Hi guys,
i want to make a program that alternates the duty cycle of a PWM signal generated by my NUCLEO-F401RE. The duty cycle should be 20% for two periods of the signal and 90% for two periods of the signal. I have chosen a period of 3s. Evaluating the generated signal with another board I see a signal with a costant 20% duty cycle. It never changes. I show you my short code, where are the errors?
#include “mbed.h”
PwmOut pwm1 (D3);
float D=0.9;
int main()
{
pwm1.period(3);
while (1) {
if(D==0.2) D=0.9;
else D=0.2;
pwm1.write(D);
ThisThread::sleep_for(6s);
}
}