Generate to generate a signal that contains different parts

Hi everyone,

I’m pretty new to the whole platform and I would like to generate the following signal:

I’m using the LED1 on my NUCLEO-F767ZI to test my code.

#include “mbed.h”
// define digital output for pin 5
PwmOut led(LED1);

int main() {
int i;
for(i=0;i<1024;i++){
led = 0;
wait_us(5000000);
led = 1;
wait_us(5000000);

// specify period first, then everything else
led.period(1.0f); // 4 second period
led.write(0.9f);  // 50% duty cycle

wait_us(5000000);
led = 0;

}
}

I really appreciate your feedback :innocent:

best regards,
Ezzow

Hello @Yassine_Ezzaroual

I was unable to define the shortest period of your signal from your picture.
But for me you define this shortest period of your pwm at the beginning of your program only once.
Then you alternate between the cycle ratio changes and your wait times.

led.write(0);
ThisThread::sleep_for(5s);
led.write(1);
ThisThread::sleep_for(5s);
led.write(0.5);
ThisThread::sleep_for(5s);

best regards,
YSI

1 Like