2021-05-06 01:45 AM
I wish to build a classical closed loop controller based on a STM32H743 interfaced via SPI to an external 16bit ADC and to a 16bit DAC. The MCU is supposed to read an ADC sample, feeding a controller routine (for example implementing a standard PID controller) which yields to an output then sent to the DAC to generate a corresponding voltage. In parallel, the MCU should have another SPI for communication with a client (actually a RaspberryPi), receiving commands and sending all the ADC and DAC sample pairs at each loop (or eventually at a shorter time rate, for example, every N feedback loop iterations).
I want to ask you which is the better way (i.e. the fastest and more reliable) to implement this scenario. The ideal workout would allow the feedback loop to run undisturbed without any interaction with the other routines to send data and receive commands, so that I can set a definite "loop timing".
For example, I wish to know if there is anything better than a timer interrupt routine implementing the whole feedback process, i.e. get an ADC sample, process it, set the DAC. In particular I cannot foresee any helpful way to take benefit from the use of DMA for ADC acquisition, in this scenario. And also how to get rid of possible slowing / interruptions of the feedback loop when the MCU is also performing a transaction on the communication SPI line to/from the client.
Any hint will be appreciated.
Thanks in advance,
Marco
2021-07-01 02:22 AM
Hello @marcosartore
if I understand well, you are using external ADC and DAC that interface with the STM32H743 via the SPI, and you want to know what is the better way to implement this application.
If so, why you don't use the internal ADC & DAC but an external one instead?
for the STM32H743, the ADC has a configurable resolution (16bit max) so if you really don't need such resolution you can use the 12b or 10b resolution for example in order to gain more performance.
Eventually, the ADC can be served by the DMA controller, thus allowing to automatically transfer ADC converted values to a destination location without any software action, and in this case you use the SPI only to interface with the client.
I think that this is a better way for your application than using external ADC & DAC.
Regards,
Houssemeddine.