cancel
Showing results for 
Search instead for 
Did you mean: 

To vary duty cycle of pwm according to adc value

bharti sharma
Associate II
Posted on September 08, 2017 at 14:19

Hello all, 

My question is how to read ADC  value ( AC and DC (voltage and current ) ) If I want to generate 20khz signal and vary duty cycle (0-100%) of PWM according to ADC value   how it can do and how to reload any value of  PWM (at instant of time) Please guide me with an example 

1 REPLY 1
Posted on September 08, 2017 at 14:29

>>Please guide me with an example 

And you're using what part, with what TIM, and pins for input vs output?

Take the ADC sample, 0..4095, scale it so fits within the period of the TIM, and write that value into TIMx->CCRx, secondary school level math.

Where Period = N-1, 0% = 0, 50% = N/2, 75% = 3N/4, 100% = N

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..