I am making a full bridge control on D-SMPS and I want to trigger PWM from ADC to keep output voltage constantly stable. I am using STM32f103xx as microcontroller. The problem is that looks like in ST's MCUs does not provide a trigger for PWM from ADC. So how can find the right path?
I want to change pwm duty cycle after measuring output voltage
ST's timers have buffered register options, they call it preload. They will update at an overflow.
You can safely write directly to the compare registers from where you have your ADC computation result as long as in TIMx_CCMRx the bit OCxPE is set.
Enable the end of conversion interrupt for the ADC in the ADC_SR Register (page 237 of reference manual RM0008). Once you have a new ADC measurement this will trigger this interrupt and you can access the ADC value (in the ADC_DR Register) immediately after the trigger and use this to update your PWM duty cycle as required.
- Start ADC conversion
- enable ADC Interrupt
- update PWM in ADC ISR (when conversion ready)