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.

LP-MSPM0G3519: Confusion regarding DL_Timer_startCounter() function

Part Number: LP-MSPM0G3519

Hello, 

general project information:

  • Interrupt triggers every 100µs to execute urgent code and check if tasks are pending
  • pending tasks are processed inside main loop before entering WFI()

In one of our projects we need to measure the CPU load and thought we could do this with a timer. 

On every enter of any interrupt the timer is started (DL_TIMER_startCounter()) and only stopped, when the MCU enters WFI(), thus the timer counts during interrupts as well as pending tasks. 

Every 10th execution of the 100µs interrupt the timer counter value is read and timer is reset, so we have the CPU usage within the last 1ms.

At first shot we implemented this using a normal timer (TIMG or TIMA), but we observed that DL_TIMER_startCounter() seems to reset the timer counter register to "0". Is this intended, since its not obvious from looking at the driverlib? Even setting the CVAE-Reg to "No change" doesnt help. This is visable in picture 1. 

Picture 2 also shows a weird behavior. For some reason the buffer_before_stop and buffer_after_stop lose "synchronization" at sample 210, which does not make sense since both buffers are written to the same index with the only difference beeing one is written before and one is after stopping the timer. 

Maybe someone could help with this.

 

In the following there is a simplified example, where we observed the missbehavior. 

#include "ti_msp_dl_config.h"

bool exe_task = false;

uint32_t buffer[256u] = {0u}; 
uint8_t i = 0u;

uint32_t buffer_before_start[256u] = {0u}; 
uint32_t buffer_after_start[256u] = {0u}; 
uint8_t i_start = 0u;

uint32_t buffer_before_stop[256u] = {0u}; 
uint32_t buffer_after_stop[256u] = {0u}; 
uint8_t i_stop = 0u;

/* Interrupt triggered by timer every 100µs */
void TIMER_SWTICK_INST_IRQHandler( void ) {
    static uint8_t cnt = 0u;
    
    buffer_before_start [i_start] = DL_Timer_getTimerCount(TIMER_CPU_LOAD_INST);
    DL_Timer_startCounter(TIMER_CPU_LOAD_INST);
    buffer_after_start [i_start] = DL_Timer_getTimerCount(TIMER_CPU_LOAD_INST);
    i_start++;

    DL_GPIO_setPins(DEBUG_PORT,DEBUG_PIN_0_PIN);

    if(0u == cnt) {
        exe_task = true; 
        buffer [i] = DL_Timer_getTimerCount(TIMER_CPU_LOAD_INST);
        i++;
        cnt = 10u;
    }

    cnt--;

    DL_Common_delayCycles(320u); // Do some work
}


int main(void)
{
    SYSCFG_DL_init();

    /* start base timer */
    DL_Timer_startCounter( TIMER_SWTICK_INST );
    DL_Timer_setCounterValueAfterEnable( TIMER_CPU_LOAD_INST, DL_TIMER_COUNT_AFTER_EN_NO_CHANGE );

    /* enable interrupts */
    NVIC_EnableIRQ( TIMER_SWTICK_INST_INT_IRQN );

    while (1) {
        if (true == exe_task ) {
            /* Do normal priority processing here */
        }
        
        buffer_before_stop [i_stop] = DL_Timer_getTimerCount(TIMER_CPU_LOAD_INST);
        DL_Timer_stopCounter(TIMER_CPU_LOAD_INST);
        buffer_after_stop [i_stop] = DL_Timer_getTimerCount(TIMER_CPU_LOAD_INST);
        i_stop++;

        DL_GPIO_clearPins(DEBUG_PORT,DEBUG_PIN_0_PIN);
        __WFI();
    }
}

 

start_counter.png

Picture 1 

 

stop_counter.png

Picture 2

 

Thanks in advance!

Best regards

  • Hello Timon,

    I have tested on my side, and I found that "Start counter" and "Stop counter" won't affect the current count value. Timer will continue counting from the current value. It seems strange about your results. I will try to more tests and analysis on my side after I come back from International Labor Holiday from May 1st to May 6th.

    BR,

    Janz Bai