Page 1 of 1

Segmenting a complex bit of hardware-two STM32F4's

Posted: Thu Mar 17, 2022 4:07 am
by Xnke
I am working on an engine control computer project based around Speeduino, that already exists on STM32. It does a solid 90% of what I want it to do, however the hardware available is not built to the durability standard I want, so I'll build my own. I have no worries about the hardware design, that's what I do-the coding is what will be difficult for me.

Currently, the main project runs on an STM32F4XX, I will be using an STM32F407VGT6 or an STM32F417ZGT6 as the main processor. The 407VGT6 is the preferred target due to some communications issues that haven't been worked out yet. This part is not too difficult to work with.

The problems come up with the drive-by-wire system. It will require some hardware redundancies, which are already worked out-the throttle pedal and throttle body-the OEM redundant systems are good enough. All-in-all, I will need to read 4 potentiometers, drive an H-bridge motor amplifier, generate an analog throttle position signal, and maintain a communication link (I'm thinking SPI would be appropriate) back to the main processor.

First, do I need the multiple ADCs of the STM32F303(hard to get right now!), or will the STM32F401 with its single ADC be enough to sample the four potentiometers? The advantage is that if I offload the drive-by-wire duties, I won't have the main processor loop clogging up ADC reads or position commands.

Next, the SPI communications. I want to report back to the main processor with a data packet that includes the TPS value (in addition to the analog value), a fault status (four potentiometers plus a motor control circuit) and a "follower error" that includes the measured throttle position deviation from the commanded value. This seems trivial on the hardware side. Any gotchas to look for as I lay out the hardware to do this?

I've seen a few examples out there in the wild, and the hardware is not too complicated. It's that hardware/software interface that I am concerned with. I don't want to lay out a hardware system that puts up roadblocks for the software to deal with-I'm not a good enough programmer to program around badly designed hardware!

Re: Segmenting a complex bit of hardware-two STM32F4's

Posted: Thu Mar 17, 2022 8:21 am
by fpiSTM
STM32F407VG has several ADC:
https://github.com/stm32duino/Arduino_C ... .c#L35-L77

Even the STM32F401/ Same instance but several channel:
https://github.com/stm32duino/Arduino_C ... .c#L37-L49

Re: Segmenting a complex bit of hardware-two STM32F4's

Posted: Thu Mar 17, 2022 2:12 pm
by Xnke
I know the '401 has 1 ADC with multiple channels, but will it be enough to run multiple channels for the 4 ADC reads?

Re: Segmenting a complex bit of hardware-two STM32F4's

Posted: Thu Mar 17, 2022 2:27 pm
by ag123
I think STM32F401 ADC can reach sample speeds of 2.5 Msps, but normally for high impedance sources to get a more stable reading it is better to use a larger sample time which means reducing samples per sec, then you need to divide that by the number of samples you would like to capture concurrently, say round robin.

For potentiometers, I'd guess extreme sample speeds isn't really needed.

Re: Segmenting a complex bit of hardware-two STM32F4's

Posted: Thu Mar 17, 2022 5:15 pm
by GonzoG
Xnke wrote: Thu Mar 17, 2022 2:12 pm I know the '401 has 1 ADC with multiple channels, but will it be enough to run multiple channels for the 4 ADC reads?
It all depends on how many reads per second you need.
Even with Arduino's analogRead() F401 can do about 14k reads per second.

Re: Segmenting a complex bit of hardware-two STM32F4's

Posted: Thu Mar 17, 2022 6:04 pm
by Xnke
If I can make it through 500 samples per second, that should be plenty of samples to ensure safety and responsiveness.