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 Timer Edge Time Mode

Other Parts Discussed in Thread: CC3200

I am using the CC3200 Timer A2 in edge time mode to determine the duration of high and low pulses from an external signal.

In the edge time mode, it is a 16-bit timer with 8 bit prescaler.The timer edge interrupt is triggered for both rising and falling edges.The CC3200 is running at 80MHz and I have set the prescaler to 0xFF . Here is the code I have written in the interrupt handler.

To avoid timer overflow, i am setting the timer value to 0xFFFF everytime the interrupt occurs using the   TimerValueSet(TIMERA2_BASE,TIMER_A,0xFFFF); 

I have a couple of doubts:

1) when i use MAP_TimerValueGet, does it return the 16 bit timer value or does it include the 8-bit prescaler

2) when i use TimerValueSet, does it set only the 16-bit timer count or also the prescaler

Is there any better way/logic to implement this? Thanks

static void TimerIntHandler()
{

MAP_TimerIntClear(TIMERA2_BASE,TIMER_CAPA_EVENT);             // Clear the interrupt

g_ulSamples[0] = 0xffff;

g_ulSamples[1] = MAP_TimerValueGet(TIMERA2_BASE,TIMER_A);  //Get the current timer value

capturedValues[index] = g_ulSamples[0] - g_ulSamples[1];                   //Storing Duration of the pulse 

index++;

TimerValueSet(TIMERA2_BASE,TIMER_A,0xFFFF);                                    //Setting the timer value to 0xFFFF every time the interrupt occurs

if(index >=63)

{
MAP_TimerDisable(TIMERA2_BASE,TIMER_A);
index = 0;

}

}

  • Hi Nikhil,


    We will look into this and get back to you.


    Regards,
    Aashish
  • Hi Nikhil,


    MAP_TimerValueGet() API will give you timer value without include pre-scale. To set and get pre-scale use MAP_TimerPrescaleSet and MAP_TimerPrescaleGet() API.


    Regards,
    Aashish
  • Thanks for the answer
    1)Firstly, This is the code I have used for setting up the timer in edge time mode:

    MAP_PinConfigSet(PIN_05,PIN_TYPE_STD_PU,PIN_STRENGTH_6MA); // Enable pull up
    MAP_TimerIntRegister(TIMERA2_BASE,TIMER_A,TimerIntHandler); // Register timer interrupt hander
    MAP_TimerConfigure(TIMERA2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_TIME_UP)); // Configure the timer in edge count mode
    MAP_TimerPrescaleSet(TIMERA2_BASE,TIMER_A,0xff); // Setting Prescaler to 255
    MAP_TimerControlEvent(TIMERA2_BASE,TIMER_A,TIMER_EVENT_BOTH_EDGES); // Set the detection edge
    MAP_TimerLoadSet(TIMERA2_BASE,TIMER_A,0xffff); // Set the reload value
    MAP_TimerIntEnable(TIMERA2_BASE,TIMER_CAPA_EVENT); // Enable capture event interrupt

    But whatever value i put for the prescaler, it doesnt seem to have any effect and the timer runs at default 80Mhz,what is the reason for this.

    2) And Secondly, I am determining the edge time for the external signal.When i subtract the previous value of the timer and the current value to determine the edge duration,sometimes an overflow occurs resulting in an erronous value.How do I overcome this.I tried using the TimerValueSet(0xffff) so that the timer restarts from 0xffff everytime the interrupt occurs but I am not getting the correct durations.


    static void TimerIntHandler()
    {

    MAP_TimerIntClear(TIMERA2_BASE,TIMER_CAPA_EVENT); // Clear the interrupt

    g_ulSamples[0] = g_ulSamples[1];
    g_ulSamples[1] = TimerValueGet(TIMERA2_BASE,TIMER_A);
    capturedValues[index] = g_ulSamples[1] - g_ulSamples[0];
    index++;

    if(index >= lengthOfCapturedValues)
    {
    MAP_TimerDisable(TIMERA2_BASE,TIMER_A);
    index = 0;
    }

    }

    Please help,Thanks
  • Hi Nikhil,

    nikhil gumidelli said:
    2) And Secondly, I am determining the edge time for the external signal.When i subtract the previous value of the timer and the current value to determine the edge duration,sometimes an overflow occurs resulting in an erronous value.How do I overcome this.I tried using the TimerValueSet(0xffff) so that the timer restarts from 0xffff everytime the interrupt occurs but I am not getting the correct durations.

    Please refer https://e2e.ti.com/support/wireless_connectivity/f/968/t/398262

    Regards,

    Aashish