Simple PWM inversion used to drive an H-bridge used for motor inverter

Status
Not open for further replies.

smuscat

Member
Hello,

I have just acquired a teensy 4.0 ucontroller board. I am trying to implement the control code of a motor inverter using four n-channel mosfets. I need help how to get an inverted PWM signal to drive the other two mosfets using analogWrite() function using the arduino IDE for Teensy 4.0. Please, my task require not to use extra hardware just implemented with code only.

Thank You,
Saviour
 
Hello again,

After some found out, I followed the post of another member that was very useful(https://forum.pjrc.com/threads/61758-Polarity-Inversion-for-Teensy-4-0-FlexPwm?highlight=pwm+invert) He uploaded the function void flexPwmInvertPolarity(uint8_t pin, bool inversePolarity) from pwm.c. Then when I run it, the two generated PWM signals, at the end momentary they are all High logic Momentary High.jpg .What I need, is little help how to configure the microcontroller to complementary channel operation and insert dead-time so when applying to the hardware doesn't damage the mosfets.
Also I found on the datasheet of teensy 4.0 that I need to set dead-time registers DTCNT0 & DTCNT1, complementary register CTRL2[INPEP]=0 and MCTRL[IPOL] for output on PWM23 or PWM45.
I am little bit confused because I am newbie to program IMRXT1060M and I found little bit info for my task, please could someone post a code snippet or a place where I should be able to find information to follow?

Your help is much welcome.

Thank you in advance

Saviour
 
Hi smuscat,

I'm not sure I understand your project. A H-bridge can drive a motor in either direction, by turning on two out of four motors. For each pin of the DC motor, one MOSFET can connect this to high and one to low, and the same for the other motor pin. In this way one side of the motor is connected to V+, and the other to V-. For this, you only ever need to turn 2 out of 4 MOSFETs on, the other two are left off. Deadtime is important, to ensure that one pair of MOSFETs have turned off before the other pair turn on, else if there could be a moment where the MOSFETs connect V+ to V-.

You could get some measure of speed control, by using PWM to these MOSFETs. Instead of turning them steadily on, the pair are turned off and on very quickly, must faster than the motor can respond. This switching results in a lower average power to the motor and hence speed control. To do this, you still don't need to turn the other pair on at all, you can leave them off. You don't need to invert the PWM to the other pair, in fact this would be bad and probably damage something.

If you genuinely need this behavior, that is to say, you need to generate an alternating current from a PWM signal, I'm not sure a H-bridge would be the best option. That being said, if you're stuck with the requirement, and stuck with the hardware I'd think a state machine and a timer would be the way to go. Perhaps if you post more information about what you're driving and how, someone will have more insight.
 
For this, you only ever need to turn 2 out of 4 MOSFETs on, the other two are left off.

You are assuming using only decay modes - for synchronous rectification mode you need to switch/PWM all the devices together.
 
I've not heard of using synchronous rectification with a H-bridge, but if I've understood, that would require opening the appropriate MOSFETs in Phase with the supply. Surely that would require two PWM signals 180 degrees out of phase with each other, not a balanced pair?
 
Aren't those are the same thing, aka antiphase. Synch rect is used for accurate control (its slightly less efficient, but way more linear, being pretty much essential for servomotor drive for instance where the control loop assumes linear system response.)

In reality you need some deadtime too, so not-quite-antiphase.
 
Many thanks for your reply,

To drive the mosfets I am using bipolar topology applied for motor inverter (http://www.ijirst.org/articles/IJIRSTV1I7111.pdf). My aim is to produce pulses as described in the pdf link to drive the mosfets at 10KHz PWM and the result across the inductor(motor) we will see a sinusoidal current waveform. As we can see the screenshotbiplor modulation.png Vg1 and Vg3 must be in antiphase and I need to introduce little dead-time because when I applying in the mosfets( S1&S3 or S2&S4) they cannot be dead short momentary and the worst case can be damaged . I am seeking code snippet example how I could be able using Arduino ide to program the Teensy 4.0 because I am not too much familiar to set the correct registers.

Thank you in advance for your advice,
Saviour
 
Last edited:
That's synchronous rectification by another name - two switches on, two off, all the time (apart from deadtime).

Neither are great names for what is more simply just antiphase drive.
 
Thank you for your time Mark and Edward,

To confirm if it is synchronous rectification please attached my hardware circuit.
H-Bridge.png

Sorry from my late reply because I was at work.

I drafted a program to produce 1HZ sinewave with antiphase drive, the gate pulses of PWM0(inverse) and PWM9 as I said earlier at the end overlap(momentary high logic) see image
Momentary High.png.
To confirm the output that is correct, I fed one of the PWM signal to a low pass filter to see the 1Hz sinewave.
sinwave.png.
The program attempt is the following
Code:
void setup() {
  // put your setup code here, to run once:
analogWriteResolution(8);
analogWriteFrequency(9,10000);
analogWriteFrequency(0,10000);
flexPwmInvertPolarity(0,false);
}

void loop() {
   //long t=micros();
   
  float val=sin(micros()*PI/500000.0)*115.0+115.0;//1hz sinwave
  int val1=abs(255-val);//modulus
  analogWrite(0,val1);
  analogWrite(9,(int)val);

}

Now to complete my task I need guidance to configure the dead-time as said before. Kindly show me the way forward.

Again thank you,

Saviour
 

Attachments

  • Momentary High.png
    Momentary High.png
    59.8 KB · Views: 41
Status
Not open for further replies.
Back
Top