2023-09-08 08:55 AM
I'm working on a project in speed control of a pmsm and i am using ADC1 and 7 channels of the ADC to sample 7 different inputs. The ADC gets triggered from TIM2 and i'm doing the conversions every time i get a callback. At first the adc works fine with the V/F control scheme, but when i switch to the closed loop control adc starts mixing up the sampled values though the sevens channels.
The callback code is the following:
2023-09-11 07:07 AM
What leads you to believe they're being mixed up? What are the values normally and what are they when they are "mixed up"?
What is your sample rate?
2023-09-11 01:02 PM
CubeIDE has a bunch of good examples. I've settled on a conglomeration of a couple of examples like ADC_TripleModeInterleaved and ADC_TriggerMode to come up with a chunk of code that uses a timer to trigger a bunch of ADC conversions from 1 - 3 ADCs simultaneously (depending on which processor I'm currently using). When a bunch of results are ready, I get an interrupt from the DMA system, then I can pull the data out of the ping-pong buffers, convert them to engineering units with the latest value of Vref, average and post them for consumption.
I only run my ADCs at 200Hz, but that's what I need.
The examples show how to un-"mix-up" the results. Remember, if you're using DMA without ping-pong (circular) buffers, the buffers will be updated as you are using them, that would give weird results.