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.

LAUNCHXL-F28379D: Using polling for hardware timer on CPU2

Part Number: LAUNCHXL-F28379D

Hi,

I am using a 3 high frequency interrupts on CPU2 namely

ADC1 - 180kHz     - Execution time : 650ns

EPWM1 - 180kHz - Execution time : 350ns

EPWM2 - 45kHz   - Execution time : 1.86us  (But this is happening in a CLA task, EPWM 2 ISR only occurs to trigger the CLA and clear ACK)

CLA ISR - 45kHz   - Only clears the ACK when CLA Task is completed.

As I do not want to add another interrupt, I tried to use a timer without ISR i.e. I was trying to the API CPUTimer_getTimerCount(CPUTIMER0_BASE); to get the value of TIM register and checking if its equal to zero to do the counting that I need. I used the below initialization function. If I mention 1000us=1ms in this initialization the timer ticks that I get are more than 1sec; the ticks are very slow and not periodic at all.

I am polling the TIM register in an infinite loop in main() and I have ensured with an LED toggling that the function is getting enough CPU time in main. The time for which the LED was completely off was around 75ns periodically.

static void ConfigCPUTimer(U32 cpuTimer, U32 period)
{
    U32 temp, freq = DEVICE_SYSCLK_FREQ;

    /* Initialize timer period:*/
    temp = ((freq / 1000000) * period);
    CPUTimer_setPeriod(cpuTimer, temp);

    /* Set pre-scale counter to divide by 1 (SYSCLKOUT):*/
    CPUTimer_setPreScaler(cpuTimer, 0);

    /* Initializes timer control register. The timer is stopped, reloaded,
     * free run disabled.
     * Additionally, the soft bits is set to stop at zero.
     */
    CPUTimer_stopTimer(cpuTimer);
    CPUTimer_reloadTimerCounter(cpuTimer);
    CPUTimer_setEmulationMode(cpuTimer,
                              CPUTIMER_EMULATIONMODE_STOPAFTERNEXTDECREMENT);
    //CPUTimer_enableInterrupt(cpuTimer);
}

void SetupTimer0(void)
{
    ///Interrupt_register(INT_TIMER0, &tmrTimer0ISR);

    ConfigCPUTimer(CPUTIMER0_BASE, 1000);

    //CPUTimer_enableInterrupt(CPUTIMER0_BASE);
    //Interrupt_enable(INT_TIMER0);

    CPUTimer_clearOverflowFlag(CPUTIMER0_BASE);
    /* Start the ON timer 0 */
    CPUTimer_startTimer(CPUTIMER0_BASE);
}

Question 1: Is it not possible to get desired time ticks with hardware timer if timer interrupts are not being used? 

Question 2: Is there another correct way for polling the timer other than looking at TIM reaching 0?

Regards,

Rashmitha

  • Hi,

    Checking for timercount == 0 may not be very effective because, the timer counter goes back to configured period value once it reaches 0. While application reads the counter value, it might have already reset and started the decrement.

    A better way would be to poll for the TIF flag. This is set whenever counter reaches 0.

    Regards,

    Veena