cancel
Showing results for 
Search instead for 
Did you mean: 

ADC trigger with PWM and reading voltage on its state

gokhannsahin
Associate II

Hi everyone,

I have a question about ADC trigger. I have to generate a PWM 1.1KHz and read the avarage voltage of ADC pin accoding to the On/Off state of that PWM. How can I make it.? I enclosed an image about it.

0690X000006CyKTQA0.jpg

This discussion is locked. Please start a new topic to ask your question.
11 REPLIES 11
S.Ma
Principal

The way you generate the 1.1kHz is by the time it takes to perform all the ADC required conversions, half of them with GPIO low, half of them with GPIO high.

Because the callback is within interrupt, jitter will come if other interrupts delays from time to time yours. (USB, etc...). The PWM frequency is not accurate and it will definitely stop if you put a breakpoint in the callback.

Usually, we try to rely on the HW so that SW is non critical for the signals generation with precise timings.

In this case, we would generate the PWM and check how many ADC samples filled the buffer. Half of them would be for high level, the other half for the low level (exluding the ones near the boundaries).

This way, if the SW stops, the PWM may continue. And if you adjust the ADC sampling time, the number of conversions will vary and you'll still be able to calculate an average.

Make sense? There would be still different scenarios to make it better, this is the way to look at the implementation.

gokhannsahin
Associate II

Thank you @S.Ma​ 

I didn't understand what you meant in second paragraph. Please give me more details?