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.

cc3200 Timers, reset to zero in program

Other Parts Discussed in Thread: ENERGIA, CC3200

I am counting external pulses of a shaft encoder using a timer counting external events.

All of this works OK, but when i have finished counting i need to start counting again on the same pin but the timer/counter resumes the count from where it finished the previous count e.g. count finishes at 12345 and when the counter starts again it starts from 12345.

I have tried disabling the counter/timer and enabling it again but it still starts from the previous count of the timer.

The only way that i can see to reset the counter/timer to zero is to preform a hardware reset ( pressing the reset button )

Is there any way i can reset the counter to zero in code while the program is running.

Any help would be appreciated. 

  • Just try,

    void YourTimerFunction(void){

    unsigned long ulInts;
    ulInts = MAP_TimerIntStatus(ulBase, true); // ulBase is your current Timer, e.g. TIMERA0_BASE.
    //
    // Clear the timer interrupt.
    //
    MAP_TimerIntClear(ulBase, ulInts);
    ...
  • Thanks for the reply,

    Where should this code be placed to reset the timers to 0.

    I have tried to put it before the timer is enabled and while it is enabled but it hasn't had any effect.

    It should be noted that I have an interrupt on this timer. The interrupt is triggered on a timer match value.

    Regards

    josmchale

  • Past on the first line of your interrupt.

    unsigned long ulInts;
    ulInts = MAP_TimerIntStatus(ulBase, true); // ulBase is your current Timer, e.g. TIMERA0_BASE.
    //
    // Clear the timer interrupt.
    //
    MAP_TimerIntClear(ulBase, ulInts);

    Should work!
  • This is my interrupt currently

    static void CalibrationTimerIntHandler() {
    MAP_TimerIntClear(TIMERA0_BASE, TIMER_CAPA_MATCH);// Clear the interrupt

    }

    It does reset the counter on a timer A match it is similar to your suggestion i that TIMER_CAPA_MATCH is the value in your "ulInts", however the pulses to be counted will never end on the interrupt as there is a different amount of counts each run. which means the counter is never at 0 when finished. 

    I need a way i can reset the counter separate to this code. maybe i should set up the timer again using an internal trigger and run the timer until the next interrupt and then use the code you suggested along with a timer disable which would stop the timer at 0.

    If there is a simpler way of resetting the timer it would be easier.

  • Hi josmchale,

    There was a similar requirement discussed in the below thread. Please see if it helps.
    e2e.ti.com/.../398262

    Thanks and Regards,
    Siddaram
  • Hi Siddaram,

    Thanks for the advice,

    I used the  GPTMTAV Register to dynamically change the counter value ( see Table 9-27. GPTMTAV Register Field Descriptions), as mention in the thread you suggested.

    The code i use was : " HWREG(TIMERA0_BASE + TIMER_O_TAV) = 0; " this set the timer A value to zero.

    Thanks for the help, it has save me a lot of time.

    Regards,

    josmchale

  • Hi I think that you have worked on CC3200. I am new to cc3200 coding. I am using Energia.
    Can you tell how to use timers in CC3200.
    I am stuck in a problem.
    Either my timer is not working or I am not getting the compare match interrupt.

    below is my code

    #include<Energia.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_timer.h"
    #include "inc/hw_types.h"
    #include "debug.h"
    #include "interrupt.h"
    #include "timer.h"
    #include "driverlib/prcm.h"
    #include "inc/hw_gprcm.h"
    #include "wiring_private.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/pin.h"


    void setup()
    {
    pinMode(2,INPUT_PULLUP);
    pinMode(4,OUTPUT);
    noInterrupts();
    PRCMPeripheralClkEnable(PRCM_TIMERA1,PRCM_RUN_MODE_CLK);

    PRCMPeripheralReset(PRCM_TIMERA1);

    TimerConfigure(TIMERA1_BASE,TIMER_CFG_A_PERIODIC_UP);

    TimerIntRegister(TIMERA1_BASE,TIMER_A,start);

    TimerIntEnable(TIMERA1_BASE,TIMER_TIMA_MATCH);

    TimerPrescaleSet(TIMERA1_BASE,TIMER_A,32);

    TimerMatchSet(TIMERA1_BASE,TIMER_A,7500);

    TimerLoadSet(TIMERA1_BASE,TIMER_A,0);

    TimerEnable(TIMERA1_BASE,TIMER_A);
    attachInterrupt(2,zeroCrossingInterrupt, RISING);
    interrupts();
    Serial.begin(9600);
    }


    void loop()
    {
    }

    void zeroCrossingInterrupt()
    {
    digitalWrite(4,LOW);

    TimerEnable(TIMERA1_BASE,TIMER_A);

    Serial.println("0k");
    }

    void start()
    {
    digitalWrite(4,HIGH);

    TimerDisable(TIMERA1_BASE,TIMER_A);

    Serial.println("hi");

    }