2023-09-11 10:27 PM - edited 2023-09-12 09:05 PM
I am doing current control with PWM. The switch provides a current sense pin which is going to my ADC.
I am using STM32F4. I am also using FreeRTOS, not sure if this is important though.
My ADC is set to run at 84MHz with 4x prescaler. The conversion is 10bit and the cycles are 15. ADC into circular buffer.
The PWM frequency to be measured is 250Hz, very small. I am watching the ADC values using STM Studio trace using genuine stlinkv2 and I am unable to capture every PWM pulse when the duty cycle is below ~15%. This is clearly due to aliasing. I assume it's due to the ADC being too slow but I'm also under the impression that the ADC is supposed to be capturing 750k samples per second, 21MHz/(15+12) >= 750k. Even 5000 samples per second should suffice so what could be happening?
My problem is similar to this but I am not currently concerned with gating, just being able to capture the low duty cycle PWM pulses.
code:
Solved! Go to Solution.
2023-09-12 07:23 AM
Isn't sampling 15 channels going to significantly decimate the attained rate?
How deep is your buffer? Make sure its several KB deep, filled once, so you can inspect the content at your leisure.
2023-09-12 06:28 AM - edited 2023-09-12 06:29 AM
> I am watching the ADC values using STM Studio trace
Is this your only method of watching data? Likely STM Studio is just not passing variables every time it updates. You're churning through quite a lot of samples and the trace can't keep up.
Also make sure adc_num_conv is large enough that you aren't swamping the CPU with interrupt requests every few samples.
750 ksps is going to require to you get out 7.5 Mbps of data. That's a large amount of data, what is you plan for getting that from the STM32 to your computer? Or how else will the data be processed?
2023-09-12 07:23 AM
Isn't sampling 15 channels going to significantly decimate the attained rate?
How deep is your buffer? Make sure its several KB deep, filled once, so you can inspect the content at your leisure.
2023-09-12 03:01 PM - edited 2023-09-12 03:04 PM
STM Studio is faster than the cube ide trace. I don't have a jtag debugger so that's what I'm working with.
Currently I'm trying out 7 conversions. My plan was bad but I haven't thought of another way. In any case, the actual data stream is only one of the many ADC conversions taking place so I would be outputting less than 7.5 Mbps, I'm accepting samples at 10khz then outputting that.
2023-09-12 03:11 PM
I'm doing 7 ADC conversions and putting one value for each pin into a buffer then at the end of conversion replacing them with the newly converted values using a DMA request.
What you're suggesting is making it lets say 1000 long and having the DMA place new values into the next position after a conversion sequence (1000/number of conversions) times before starting from the beginning again?
2023-09-12 09:04 PM
So I did this, the ADC was sampling correctly but the duty cycle coming out of the switches sense pin was 10% lower than the actual duty cycle.