3 years, 8 months ago.  This question has been closed. Reason: Too broad - no single answer

Using PWM to control MOSFET gates for full h-bridge switch mode power supply? (Please check my code)

Hello,

First of all, I'd like to apologise if my code was meaningless. I've never done programming before and I have to make a mbed programme to control four MOSFET. Basically if S1+S4=ON then S2+S3=OFF. So I have to generate the pwm to drive the gates. My project is a DC-AC-DC converter as following:

/media/uploads/Gaz142/schemeit-project_1.32.30_p.m..jpg

I wrote the following code which I have a feeling it is completely wrong.

#include "mbed.h"

PwmOut MosfetOneAndFour(p26);
PwmOut MosfetTwoAndThree(p27);

void SwitchOneAndFourON();
void SwitchOneAndFourOFF();
void SwitchTwoAndThreeON();
void SwitchTwoAndThreeOFF();

void SwitchOneAndFourON() {
    MosfetOneAndFour.period_ms(2.48f);      // 2.48 milisecond period
    MosfetOneAndFour.write(0.50f);      // 50% duty cycle, relative to periodƒ
    }

void SwitchOneAndFourOFF(){
    MosfetOneAndFour.period_ms(0);      //off
    MosfetOneAndFour.write(0);             //off
    }
    
void SwitchTwoAndThreeON(){
    MosfetTwoAndThree.period_ms(2.48f);
    MosfetTwoAndThree.write(0.50f);
    }

void SwitchTwoAndThreeOFF(){
    MosfetTwoAndThree.period_ms(0);
    MosfetTwoAndThree.write(0);
    }  
    
int main() {
    
    SwitchOneAndFourON();
        wait(0.001);
    SwitchOneAndFourOFF();
        wait(0.001);
    SwitchTwoAndThreeON();
        wait(0.001);
    SwitchTwoAndThreeOFF();
        wait(0.001);
    
    while(1);
}

Please any help will be appreciated.

Thanks.