Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 1 month ago.
PWM H-Bridge Inverter
Hello all, I´m solving a problem how to use PWMouts for switching four MOSFETs on H-bridge to work like inverter. The load of H-bridge is tranformer (20kHz) and I want change its output voltage by changing PWM width. There is a problem of switching the diagonal pairs so quickly and not to short out the supply. I have no idea how to use any library for Motors or PWM o this site. I use 2 IR2112 to control the H-bridge so I need 4 signals, but 2 are of the same level at the moment. Thanks
2 Answers
11 years, 1 month ago.
#include "mbed.h" PwmOut myled(p23); PwmOut myled2(p25); //serial pc(usbtx, usbrx); int main() { //lpc_pwm1->mr0 = 24000000; myled.period(1); // 24000 pr. ms in mr0 LPC_PWM1->MR0 = 24*50; // 50 usek routine / 20khz LPC_PWM1->MR1 = 1; // set the pwm2 output high at this count LPC_PWM1->MR2 = 24*19; // set the pwm2 output low at this count LPC_PWM1->MR3 = 24*21; // set the pwm4 output high at this count LPC_PWM1->MR4 = 24*39; // set the pwm4 output low at this count LPC_PWM1->PCR |= 0x14; LPC_PWM1->LER |= 0x1e; /* pc.printf("pwm registers: \r\n"); pc.printf("pwm1->mr0 = %x\r\n", LPC_PWM1->MR0); pc.printf("pwm1->pcr = %x\r\n", LPC_PWM1->PCR); pc.printf("pwm1->ler = %x\r\n", LPC_PWM1->LER); */ while(1) { wait_ms(20); } }
This may help you.
Lerche
11 years, 1 month ago.
The hardware of the LPC1768 can handle it, but the PWMOut library of mbed doesnt support it (and I dont know of another PWM lib here that does support it). It is on my todo list to make someday when I feel like it :P
Meanwhile however I would just search an H-bridge IC (you have them afaik both with integrated switching mosfets and ones where you have to use external mosfets). They are specifically made to not short the power supply and to switch fast.