• AVR Freaks

Hot!Why is my timer getting disabled?

Senior Member
  • Total Posts : 123
  • Reward points : 0
  • Joined: 2010/06/15 22:21:39
  • Location: 0
  • Status: offline
2019/08/15 19:28:55 (permalink)

Why is my timer getting disabled?

I'm trying to use the Timer driver to implement a regular periodic timer using the PIC32 TMR2 in 32-bit mode and I've configured the driver like this:
if (DRV_HANDLE_INVALID == tmr2_handle)
    printf("TIMER 2 Driver can't be opened!!");

DRV_TMR_CounterValueSet(tmr2_handle, 0x00000000);
DRV_TMR_AlarmPeriodSet(tmr2_handle, 0x00000FFF);
DRV_TMR_AlarmRegister(tmr2_handle, 1, true, 0, timer2_tick);
DRV_TMR_AlarmEnable(tmr2_handle, true);
if (!DRV_TMR_Start(tmr2_handle))
    printf("TIMER 2 Driver can't be Started!!");
static void timer2_tick( uintptr_t context, uint32_t alarmCount )

If I single-step through the code I can see the timer enabled and counting. But if I hit "run" the execution never gets to the "timer2_tick" callback and when I pause the execution I see in the TMR2 registers that the timer is disabled.
What else do I need to do to make this work? I just need a periodic timer that executes the callback every time the counter reaches the period and the documentation does not contain an example of clear explanation about how to achieve this.

1 Reply Related Threads

    Super Member
    • Total Posts : 375
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: online
    Re: Why is my timer getting disabled? 2019/08/16 07:58:02 (permalink)
    Did you check the "Enable Interrupts" in MHC?  Are you also using the SYS_TMR system service?
    This looks like Hv2 code.  The timers in Hv3 are a little simpler to understand.
    Jump to:
    © 2020 APG vNext Commercial Version 4.5