cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with STM32F769 PWM output when updated according to condition

SKhan.16
Associate II

I am using STM32F769 Disc board with Mbed online compiler. My task is to change the PWM frequency and duty ratio according to input. i created a simple algorithm according to my need, the program is working well but whenever the controller updates the PWM frequency, there is strange behavior(overlapped maybe, difficult to explain verbally for me), the frequency is changed instantly and the output is incorrect at that moment, for other controllers like aurdino, this never happens, the controller update value after the time period of PWM is over. But not in this case What can be wrong?

i thought to add a small delay before value is updated but that will not work, as every time a different delay would be needed. i have attached the code and screenshots.

  1. include "mbed.h"

AnalogIn analog_value(A0);

PwmOut pulse(D11);

int main() {

double meas_v=0; double out_freq,out_duty,s_time; while(1) {

meas_v = analog_value.read()* 3300; if(meas_v<1) { out_freq=50000; out_duty=40; }

else if(meas_v>=1000) { out_freq=100000; out_duty=80; } else { out_freq=50000+(meas_v*50); out_duty=40+(meas_v*0.04); }

pulse.period( 1.0 / out_freq); pulse=out_duty/100; s_time=0.0001; wait(s_time);

}

}

The output should be updated after the current period is completed

0 REPLIES 0