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.

TM4C1294NCPDT: TM4C1294NCPDT: Timer Edge count capture shows wrong value

Part Number: TM4C1294NCPDT

I am trying to measure the frequency of incoming signal which I set at 400 KHz. I setup a capture timer in edge count mode.
Parallely I setup the Systick for an interrupt every 10 ms. So every 10 ms I load the counter with a known value and check the count value after 10 ms. 
I expect the count to be 4000( 400000 edge in 1 sec and 4000 in 10 ms).  But the count seems to be  33% lesser and I get only 2667 . Similarly If I change the incoming frequency  to 600 Khz I get the count only as 4000( instead of 6000).  Could you help me with finding the mistake. 
The code snippets below
// set up the Timer3 for Edge count
void setupT3CCP0(void)
{
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_GPIOPinTypeTimer(GPIO_PORTA_BASE, GPIO_PIN_6);
    GPIOPinConfigure(GPIO_PA6_T3CCP0);
    MAP_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_6,
                      GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    ROM_TimerConfigure(TIMER3_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT));    //TIMER_CFG_A_CAP_COUNT
    ROM_TimerControlEvent(TIMER3_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);
    ROM_TimerPrescaleSet(TIMER3_BASE, TIMER_A, 0);
    ROM_TimerLoadSet(TIMER3_BASE, TIMER_A,60000);
    ROM_TimerMatchSet(TIMER3_BASE, TIMER_A, 0);
    ROM_TimerEnable(TIMER3_BASE, TIMER_A);
}
//Setup Systic for 10 ms timing
void
initSystick(uint32_t ui32SysClock)
{
    g_ui32sysCounter = 0;
    SysTickPeriodSet(ui32SysClock/100); n
    psysTimerTick=false;
    toggle=false;
}
After every psystic interrupt I will run this function to check the frequency and also reload the timer .  I am checking the FreqVal value.
void FreqMeasTTask(void)
{
    uint32_t FreqVal;
FreqCount = ROM_TimerValueGet(TIMER3_BASE, TIMER_A);
ROM_TimerLoadSet(TIMER3_BASE, TIMER_A,60000);
ROM_TimerMatchSet(TIMER3_BASE, TIMER_A, 0);
FreqVal = 60000 - FreqCount;
}
  • Hello Ramesh,

    I was comparing what you have against our Edge Count example provided, but I am not seeing anything sticking out to me now. You've posted partial code though and I don't see your system clock settings, interrupt setups, etc. - Can you provide the full code? I could test it on my LaunchPad at that point as well. 

    Another test you could do is try to set your edge count load to 4000 and then measure via a global variable how many SysTick interrupts you made before you hit the Edge Count interrupt just to help characterize what you are seeing further.

  • Thanks Ralph.  I found the mistake.  I have programmed system clock at 80 MHz by mistake instead of 120.  I corrected and working fine.

    Regards,

    Ramesh