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.

Compiler/EK-TM4C123GXL: EK-TM4C123GXL PROBLEM PWM DEADBAND

Part Number: EK-TM4C123GXL

Tool/software: TI C/C++ Compiler

hi,

I want to produce dead time that will be two percent of the period ,but I did not get a result in the oscilloscope,  where am I making mistakes?

also i can not reverse pwm ,Why is the pdo output not inverted ?

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"
#include "driverlib/rom.h"


int main(void)
{

uint32_t cycle;
uint32_t pwmfrequency;
uint32_t deadband;
uint32_t pwmperiod;
pwmperiod=50;
pwmfrequency=SysCtlPWMClockGet()/pwmperiod;
deadband=pwmperiod*2/100;
cycle=pwmperiod*50/100;

SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|
SYSCTL_XTAL_16MHZ);
SysCtlPWMClockSet(SYSCTL_SYSDIV_8);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
{
}

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypePWM(GPIO_PORTE_BASE,GPIO_PIN_5);

GPIOPinConfigure(GPIO_PD0_M1PWM0);
GPIOPinConfigure(GPIO_PE5_M0PWM5);
PWMGenConfigure(PWM1_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN);
PWMGenConfigure(PWM0_BASE,PWM_GEN_2,PWM_GEN_MODE_DOWN);

PWMGenPeriodSet(PWM1_BASE, PWM_GEN_0,pwmperiod);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2,pwmperiod);

PWMDeadBandEnable(PWM1_BASE,PWM_GEN_0,deadband,0);
PWMDeadBandEnable(PWM0_BASE,PWM_GEN_2,deadband,0);

// PWMOutputInvert(PWM1_BASE,PWM_OUT_0,false);

PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
PWMOutputState(PWM0_BASE, PWM_OUT_5_BIT, true);
PWMGenEnable(PWM1_BASE, PWM_GEN_0);
PWMGenEnable(PWM0_BASE, PWM_GEN_2);

while(1)
{


PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, cycle);
PWMPulseWidthSet(PWM0_BASE,PWM_OUT_4,cycle);

}
}

  • You should note that "deadband" is (only) applied between the TWO PWM Outputs w/in the (same) PWM Generator.      Your code reveals that you have chosen to "attempt" to apply "deadband" across  TWO PWM Outputs - yet from different:

    • PWM Bases!     You've chosen both PWM1_BASE & PWM0_BASE
    • PWM Generators!      You've chosen PWM_GEN_0 and PWM_GEN_2

    Such is destined for failure - as you've noted!

    Note too that your chosen "PD0" is tied directly to another MCU GPIO (PB6) - thus trouble surely awaits...    (as soon as you config PB6 as an output)

    May I suggest that you find one of the vendor's simple PWM Generator examples - implement that (correct) code - and (then) return if you (still) require assistance w/ "deadband."

    You are in the midst of a "learning curve" - which all here faced - and reading first - only then working thru the many code examples - will quickly build your capability & confidence...

  • I looked and could not find a solution,it looks like there is no trouble in the codes, but I can not get results
  • Pardon - I've got to ask - did you "not" read nor understand my writing?
    Look especially at the two bullet points - which fully/completely/precisely identify your ERRORS!
  • Hi,
    You can only generate dead-band pair from the a given generator. It looks like you are trying to make M1PWM0 and M0PWM5 a dead-band pair, correct? This will not work. Please refer to the dead-band ecample in <TivaWare_Installation>\examples\peripherals\pwm\dead_band.c.
  • Hi cb1,
    Didn't know that you already responded. Thank you!
  • Charles,

    Pardon - was that exact info not reported - far earlier?

    Note that "poster's crime" was even worse - Two Different PWM Generators AND Two Different PWM Modules!       And choice of the (always) "iffy" PD0!     (tied directly to PB6 - awaiting its "Call to Evil!")

    (Be (very) still - my "deadband absent" heart...)

    (should poster - once/if returned - award "Green to you" - I'm given no choice but to, "Slit my own wrists!")

  • Hi cb1,
    I hit the post button and realized that you have exchanged with the posters several times already.

    I think the TivaWare example will provide good guidance in additional to your good explanation.
  • Thank you Charles - note that (still) ... ... I am rubbing my wrists...
  • correct , ı now adjusted,
    also I can not reverse the output of pwm can you help me ?
  • What do you mean by, "I can not reverse the output of pwm?"       You are aware - or should be - that there exists a, "PWMOutputInvert" function - are you not?  

    Are you speaking of a "PWM Pair" (from the same PWM Generator) operating w/in the constraints of "deadband?"

    Note that you've awarded TWO Verifies - but your results "correct, adjusted" provide little insight into your, "degree of success."

    More detailed description - rather than less - greatly aids in your guidance & assistance...

  • HI cb1,
    Thanks for pointing out the PWMOutputInvert() function to the poster.
  • Hi Charles,

    Some may note my wrists "slightly bruised" - yet NOT slit. Good that...