This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello everyone,
I am stuck trying to figure out if I can manipulate the deadband on certain pins for the PWM. I am driving an H-Bridge with the PWM signals. The FETs on the H-Bridge are turned on active high, so I have the deadband in there to make sure I never have both FETs on. In the waveform screen shot you can seethe first two patterns are from GEN_0, with a deadband on the rising and falling edge to make sure they are never both high. I need the inverse of these signals on the other side of the H-Bridge, but if I invert them the deadband follows (second two signals from GEN_1). As you can see, this would be bad because now I will have both FETs turned on on this side of the bridge. My question is, how can I set the deadband individually and keep my inversion? Is this even possible? I may have to switch my hardware lines or do something of that nature so I am looking for any suggestions. Thank you.
Code that controls the PWMs:
//Configure PWM Clock to match system clock
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
//Configure PF0, PF1, PF2, PF3 Pins as PWM
GPIOPinConfigure(GPIO_PF0_M0PWM0);
GPIOPinConfigure(GPIO_PF1_M0PWM1);
GPIOPinConfigure(GPIO_PF2_M0PWM2);
GPIOPinConfigure(GPIO_PF3_M0PWM3);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
//Configure PWM Options
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
// make sure pins are not inverted
PWMOutputInvert(PWM0_BASE, PWM_OUT_2_BIT, FALSE);
PWMOutputInvert(PWM0_BASE, PWM_OUT_3_BIT, FALSE);
// Turn off the Output pins
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, FALSE);
PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, FALSE);
PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, FALSE);
PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, FALSE);
// Disable the PWM generator
PWMGenDisable(PWM0_BASE, PWM_GEN_0);
PWMGenDisable(PWM0_BASE, PWM_GEN_1);
//Set the Period (expressed in clock ticks)
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PULSE_TICKS);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, PULSE_TICKS);
// Enable the dead-band generation on the PWM0 output signal.
PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, DB_RISING, DB_FALLING);
PWMDeadBandEnable(PWM0_BASE, PWM_GEN_1, DB_RISING, DB_FALLING);
// Invert the GEN_1 PWMs
PWMOutputInvert(PWM0_BASE, PWM_OUT_2_BIT, TRUE);
PWMOutputInvert(PWM0_BASE, PWM_OUT_3_BIT, TRUE);
// Turn on the Output pins
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, TRUE);
PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, TRUE);
PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, TRUE);
PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, TRUE);
// Enable the PWM generator
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
PWMGenEnable(PWM0_BASE, PWM_GEN_1);
// Enables 15v regulator for H-Bridge
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_PIN_4);
// Set pulse width, 50% duty-cycle for now
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, PULSE_TICKS / 2);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, PULSE_TICKS / 2);
Believe that your objective can be achieved - and suspect that I can guide to that end...
Let's start - focused upon just your nice scope traces. (we also are 4 chan, Tek scope, fans)
Top 2 traces show dead-band preventing the overlap of any "highs" - upon either channel. (just as you desire)
And bottom 2 show dead-band preventing the overlap of any "lows" - either channel. Key that - c'est non?
Now let's look @ your code - on the top 2 traces (Gen 0) you make no PWM modifications after your call to, "PWMDeadBandEnable()" And that code succeeds. Yet - bottom 2 traces (Gen 1) reveals that you, "PWMOutputInvert()" immediately after your, "deadband enable!" And that - I believe - does you in!
How, why? Your deadband enable performs fine - on those bottom 2 traces - for the "active" (high) levels which existed "at the moment" you invoked that "deadband enable." And they surely fail after you subsequently "flip" those outputs - via your call to "pwmoutputinvert."
Cure: Suggest that you call, "PWMOutputInvert()" for Gen 1 - before the call to, "PWMDeadBandEnable()." Justification (at least in my mind) is that the output invert places the "low" as active - which destroys your non-overlapped desire for PWM Gen 1 during output, "high." (all theory - I'm not near boards nor code - but seems w/in reason - "quick/easy fix" and "good" for G'ovt work...)
I believe.
My hardware engineer wants to jump and connect the lines so we can mirror PWM1 to PWM4 and mirror PWM2 to PWM3. I was trying to avoid this for him but I cant figure out another way to invert the signals without inverting the deadband.
Unclear to me just what you, "believe."
Tried to detail my "fix" earlier - my belief is that a simple re-ordering of 2 of your code lines will meet your objective. Might a 2nd "read" of my writing clarify? (or you may simply ask...)
I un-clearly meant that I am, in general, a believer. I believe that there are solutions to most problems :)
Sorry, I didn't read the rest of your edited reply so I missed your "cure". It ,without a doubt, made sense. However, it was not the solution. I actually had the same idea but regardless of order for inverting the output and triggering the deadband, once those registers are configured, this is what the signal will look like.
I am going to take a closer look on how the PWM module is set up and try and come up with a way to make this work. Your detailed response was much appreciated. I'll post what course of action I end up taking unless we can come up with a solution via form member contribution. Thanks!
Again - (today) I have no board - no means to test/verify.
That said, your code:
PWMOutputInvert(PWM0_BASE, PWM_OUT_2_BIT, TRUE);
PWMOutputInvert(PWM0_BASE, PWM_OUT_3_BIT, TRUE);
I believe would meet your needs by changing each "true" (above) to "false." False makes the active level low - not high - as your existing code orders. Following that with your PWMDeadBandEnable() should insert that deadband guardband into those low levels. And then - your PWMOutputInvert() (placed just as you listed) should meet your desire...