push pull pwm generators
-
ahmetimanli
- Posts: 26
- http://meble-kuchenne.info.pl
- Joined: Mon Sep 02, 2024 11:41 pm
push pull pwm generators
Hello. I want to use push-pull PWM functionality in power electronics. I want to change the frequency, PWM width, and dead time of the push and pull signals. In a normal PWM application, I do this with a single output. However, in a full bridge application, there are two outputs, and these two PWM outputs are phase-shifted. I would appreciate it if you could provide either a component for such an output or a method for creating a phase difference between the two PWM outputs.
- Attachments
-
- push pull pwm.png (138.4 KiB) Viewed 89 times
-
chipfryer27
- Valued Contributor
- Posts: 2145
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 478 times
- Been thanked: 712 times
Re: push pull pwm generators
Hi
Would a simple inverter connected to the same pin as S1 and the input of transistor S2 not do it? Now you get an inversion of S1 with minimum delay, freeing up your uC for other tasks.
Just a thought.
Regards
Would a simple inverter connected to the same pin as S1 and the input of transistor S2 not do it? Now you get an inversion of S1 with minimum delay, freeing up your uC for other tasks.
Just a thought.
Regards
-
Steve-Matrix
- Matrix Staff
- Posts: 2061
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 310 times
- Been thanked: 479 times
Re: push pull pwm generators
What chip (and/or chip family) are you wanting to use? Some devices have very capable (and complicated!) PWM modules and creating a 'catch-all' component would be a massive undertaking.
Another approach would be to add some custom C code to configure the registers for the PWM output. This would not simulate, but would give a lot of control over the output (assuming the inverter suggestion above is impractical for you).
Another approach would be to add some custom C code to configure the registers for the PWM output. This would not simulate, but would give a lot of control over the output (assuming the inverter suggestion above is impractical for you).
-
ahmetimanli
- Posts: 26
- Joined: Mon Sep 02, 2024 11:41 pm
Re: push pull pwm generators
I'll use the pic18f47k42. You're right, it doesn't need to work in the simulation. Push-pull PWM requires both dead time and a delay time for the second PWM. It can also be done with C code. If you have an example of C code, I can continue from there.
-
BenR
- Matrix Staff
- Posts: 2332
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 647 times
- Been thanked: 856 times
Re: push pull pwm generators
Hello,
Some chips have dedicated H-Bridge compatible PWM and where they have this we have a H-Bridge component that can work with them to do all the functionality your asking for. i/e/ synchronised PWM outputs and dead time etc.
However the PIC18F47K42 does not have this feature and using PWM alone it wouldn't really be possible. Good news is the chip does have the complementary waveform generator peripheral. In fact it has three of them!
You show the circuit for a half bridge but also mention a full bridge which would be 4 output channels.
Here's some example C code for a full bridge driver using the CWG peripheral, please note I have not tested it.
Just pop it into a C code icon inside a run once initialise macro.
Then here is the code to control the duty, using a global variable named duty.
And here is the code to control the motor direction using a global variable named direction.
I'll see if I can update the H-Bridge component to work with the CWG peripheral.
Some chips have dedicated H-Bridge compatible PWM and where they have this we have a H-Bridge component that can work with them to do all the functionality your asking for. i/e/ synchronised PWM outputs and dead time etc.
However the PIC18F47K42 does not have this feature and using PWM alone it wouldn't really be possible. Good news is the chip does have the complementary waveform generator peripheral. In fact it has three of them!
You show the circuit for a half bridge but also mention a full bridge which would be 4 output channels.
Here's some example C code for a full bridge driver using the CWG peripheral, please note I have not tested it.
Just pop it into a C code icon inside a run once initialise macro.
Code: Select all
// Set PORTB RB0-RB3 as digital outputs
TRISB &= ~0x0F;
ANSELB &= ~0x0F;
// --- Output PPS Configuration (PIC18F47K42 Specific Output Codes) ---
RB0PPS = 0x05; // RB0 -> CWG1A
RB1PPS = 0x06; // RB1 -> CWG1B
RB2PPS = 0x07; // RB2 -> CWG1C
RB3PPS = 0x08; // RB3 -> CWG1D
// --- Input PPS Configuration for Fault Pin (RB4 / CWG1FLT) ---
TRISBbits.TRISB4 = 1; // Input
ANSELBbits.ANSELB4 = 0; // Digital input
WPUBbits.WPUB4 = 1; // Enable Pull-Up
CWG1PPS = 0x0C; // 0x0C = RB4 (Port Index 1 * 8 + Pin 4)
// --- Timer2 Setup for ~20 kHz PWM ---
T2PR = 199; // Period Register
T2CLKCON = 0b0001; // Clock source = Fosc/4 (16 MHz)
T2CONbits.CKPS = 0b010; // Prescaler = 1:4
T2CONbits.ON = 1; // Enable Timer2
// --- PWM1 Setup (PIC18F47K42 16-Bit PWM Peripheral) ---
CCPTMRS1bits.P1TSEL = 0b01; // 0b01 = Timer2 drives PWM1
PWM1DC = 400; // Set 50% Duty Cycle (16-bit double-buffered register)
PWM1CON = 0x80; // Enable PWM1 module (EN = 1)
CWG1CON0 = 0x00; // Disable CWG1 while configuring
// --- Select Input Source ---
CWG1ISM = 0x0C; // Select PWM1_out as input source on PIC18F47K42
// --- Dead-Band Delay Setup ---
CWG1CLK = 0x00; // Fosc (64 MHz -> 15.625 ns per count)
CWG1DBR = 64; // 1 us Rising Dead-Band delay
CWG1DBF = 64; // 1 us Falling Dead-Band delay
// --- Mode & Output Configuration ---
CWG1CON0bits.MODE = 0b010; // Full-Bridge Forward Mode
CWG1STR = 0x0F; // Enable all four output channels (CWGA through CWGD)
// --- Auto-Shutdown Configuration ---
CWG1CON1bits.INTP = 1; // Active-Low fault polarity
CWG1AS0bits.LSAC = 0b00; // Drive High-Side Low on fault
CWG1AS0bits.LSBD = 0b00; // Drive Low-Side Low on fault
CWG1AS0bits.REN = 1; // Auto-restart enabled
CWG1AS1bits.AS0E = 1; // Enable CWG1FLT pin fault trigger
CWG1CON0bits.EN = 1; // Enable CWG1
Code: Select all
PWM1DC = FCV_DUTY;Code: Select all
if (FCV_DIRECTION)
CWG1CON0bits.MODE = 0b010; // Mode 0b011 = Full-Bridge Forwards
else CWG1CON0bits.MODE = 0b011; // Mode 0b011 = Full-Bridge Reverse
-
BenR
- Matrix Staff
- Posts: 2332
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 647 times
- Been thanked: 856 times
Re: push pull pwm generators
Right I have added this now into the H-Bridge component and the definition files for the 18FxxK42 devices. Turns out we were already using the CWG to drive the H-Bridge for some of the PIC16 devices.
You will need to do a library update to get the latest files.
The best component to use is probably the Outputs -> Mechatronics -> DC motor 2D and configure the Control method to H-Bridge.
Or you can use the H-Bridge CAL component directly by using the search feature and searching for HBRIDGE.
Again it's untested other then checking it compiles so may not work but let us know how you're getting on.
You will need to do a library update to get the latest files.
The best component to use is probably the Outputs -> Mechatronics -> DC motor 2D and configure the Control method to H-Bridge.
Or you can use the H-Bridge CAL component directly by using the search feature and searching for HBRIDGE.
Again it's untested other then checking it compiles so may not work but let us know how you're getting on.
-
ahmetimanli
- Posts: 26
- Joined: Mon Sep 02, 2024 11:41 pm
Re: push pull pwm generators
Hello. My goal is to build a phase-shifted power supply (PWM) similar to an SMP-S. This power supply has four PWM outputs, and they all operate in phase-shifted mode. I thought that if I could understand the first two, I could build the others using the same logic. I will try the code you sent. Thank you.
Also, when I try to update the library, it gives a "connection error" .
Also, when I try to update the library, it gives a "connection error" .