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?
-
\$\begingroup\$ To trigger ADC from PWM. But it is not clear what your intentions are. \$\endgroup\$– Marko BuršičCommented Aug 27, 2019 at 8:31
-
\$\begingroup\$ Could you explain the bit about trigger PWM from ADC? What should happen with the PWM at the end of conversion? \$\endgroup\$– followed Monica to CodidactCommented Aug 27, 2019 at 8:32
-
\$\begingroup\$ I want to change pwm duty cycle after measuring output voltage , so to do it fast at the end of conversion of ADC ıt should gives a trigger so that pwm duty cycle is rearranged depending on adc value. \$\endgroup\$– emre irisCommented Aug 27, 2019 at 8:45
-
\$\begingroup\$ how are you reading the voltage? is it time triggered? \$\endgroup\$– Pop24Commented Aug 27, 2019 at 8:47
-
\$\begingroup\$ I understand what you want to do and can guess at why. But your question has far too little detail for anyone to construct a useful or meaningful answer. Please edit your question and greatly improve it, showing your work and findings so far in considerable detail with any schematic. The better the quality of your question, the better the quality of the answers you will attract. \$\endgroup\$– TonyMCommented Aug 27, 2019 at 8:55
3 Answers
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)