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.

Splitting a Timer for Two PWMs



Hello,

I am trying to split GPTM timers to get two independent PWMs as shown below:

void initPWM_PB(void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

//TIMER_B Conf

    GPIOPinConfigure(GPIO_PB1_T2CCP1);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_1);
    TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);
    TimerLoadSet(TIMER2_BASE, TIMER_B, 3200);
    TimerMatchSet(TIMER2_BASE, TIMER_B, 1600);
    TimerEnable(TIMER2_BASE, TIMER_B);

//TIMER_A Conf


    GPIOPinConfigure(GPIO_PB0_T2CCP0);
    GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0);
    TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
    TimerLoadSet(TIMER2_BASE, TIMER_A, 1600);
    TimerMatchSet(TIMER2_BASE, TIMER_A, 800);
    TimerEnable(TIMER2_BASE, TIMER_A);

}

void initPWM_Wide(void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

//TIMER_A Conf

    GPIOPinConfigure(GPIO_PC4_WT0CCP0);
    GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_4);
    TimerConfigure(WTIMER0_BASE,  TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
    TimerLoadSet(WTIMER0_BASE, TIMER_A, 3200);
    TimerMatchSet(WTIMER0_BASE, TIMER_A, 1600);
    TimerEnable(WTIMER0_BASE, TIMER_A);

//TIMER_B conf
    GPIOPinConfigure(GPIO_PC5_WT0CCP1);
    GPIOPinTypeTimer(GPIO_PORTC_BASE, GPIO_PIN_5);
    TimerConfigure(WTIMER0_BASE,  TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);
    TimerLoadSet(WTIMER0_BASE, TIMER_B, 1600);
    TimerMatchSet(WTIMER0_BASE, TIMER_B, 800);
    TimerEnable(WTIMER0_BASE, TIMER_B);

}

I am able to see one of them working at a time (if I comment the relevant code).  However, I am unable to get both the timers (TIMER_A and TIMER_B) to work simultaneously.  This behaviour of either the TIMER_A or the TIMER_B working at a time (and never simultaneously) is seen across the normal-width as well as the wide timer.

For your reference, this is on the Tiva TM4C123BE6PM.

Any help is appreciated.  Thanks in advance.

Regards,

Anand

  • You exhibit a penchant for bit unique/unusual applications.  However - ARM is famed for many Timers - would not it make sense to choose 2 Timers - rather than just one?

    Our group has never felt so constrained - thus we've not attempted your design.  Have you reviewed the source code (timer.c) w/in driverlib?  (perhaps there is some confinement (i.e. single use of PWM mode) when the timer is placed in that mode)

    Can report that the PWM mode of Timer operation is quite good - far faster/simpler to implement than full-fledged PWM Generator - and has proved robust in our experience.

    Jammed today - but if issue remains tomorrow - can quickly attempt via our LX4F (we are not early adopters of rebrand) - enough arrows/wounds w/out that addition...

    Update:  As I quickly scan your code - does not your TimerConfigure() usage "defeat" your desire for dual PWM output?  Suggest that you attempt to "OR" A & B... not use them singularly as listed...  And... I'd avoid the complications (which may lurk) via the wide Timer - KISS dictates shortest/sweetest - only later attempt to extend...

  • You've gone silent here - but suggestion I offered does work - present here in further detail and w/confirming scope cap.

    Now you call this function - either in the favor of "A_PWM" or "B_PWM" - and this does you in.

    TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);

    Instead - as past suggested:

    TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM  | TIMER_CFG_B_PWM);

    potentially enables both Timers w/in Timer2 to function.  (always simultaneously...)  Later you will call the formal, "TimerEnable()" function...

    I agree that SW-DRL-UGxxxx is bit unclear in this regard - suggesting that only "one" configure may be employed.  One suspects that meant - only "one" particular Timer could be managed via "TimerConfigure" - you/others likely interpreted this as just one of the "split pair" - thus only the last Timer selected would function...  Encompassing both Timers - as shown above - accomplishes your mission.  That said - should Timers from different Timer Modules be used - unique TimerConfigure()s (one for each Timer) must be employed...

    BTW - confirmed this method to work well both w/ normal and "wide" Timers...

    Here's scope cap - believe your code was employed w/ modified TimerConfigure() - above.  (no effort to Sync)

    This work was done under StellarisWare_9453 - using LX4Fxxx - custom pcb - Sys Clk @ 50MHz...

  • Hello cb1,

    Roger that on all counts:

      1. I exhibit a penchant for bit unique/unusual applications.  And as for you, you exhibit a penchant for consistently bringing back wanderers to their destination.  Thank you for your persistence and help....as always.

      2. It kind of struck me just before the "update" in your first reply that the timer configuration and enabling must be ORed (like you have shown) so as to get them working simultaneously.

      3. This works for both normal-width and wide timers.

    I don't think it is a fault of the SW-DRL-UGxxxx.  I have just got used to ready-to-digest food.

    There's one last itch though.  I had hoped to get synchronization between the two timers by doing this splitting business.  The ORing of the enable had given me hope that enabling both of them "at the very same moment" would give me a synchronization between the two timers.

    Alas, it wasn't to be.  I observe:

      1. When configured for the same frequency, the two split timers show a constant phase shift.

      2. When configured for an integral multiple (say TimerA: 25KHz and TimerB: 50KHz), they show a variable phase shift with respect to each other.

    I am perplexed.  Why should this happen?  Can you please confirm if your waveform shows a constant phase shift between the 15.62KHz and 31.23KHz timers?

    Merci encore,

    Anand

  • @ Anand,

    Merci beaucoup mon ami - j'avais l'appreciation tres grande.  (or something)

    Plz see related/sister post - in which I detail "care/handling" of Timer Sync. 

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/288250.aspx

    Pardonnez-moi - but if ever a post deserved hallowed "Verify" - that one so qualifies.  yet sits - forlonly - in "uncertain heap..."