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.

TMS320F28027F: proj_lab03b: 500k% CPU usage??

Part Number: TMS320F28027F


I'm trying to measure the CPU usage using proj_lab03b on TMS320F28027F, and the given variables that are supposed to show percentages are showing exorbitant numbers (see screenshot). The search of the project doesn't show where the maxDeltaCntObserved variable is set. CPU_USAGE_getMaxDeltaCntObserved() just returns the value from a structure. So I'm wondering, what is it I'm actually measuring, and how do I get percentages?

  • maxDeltaCntObserved is set in CPU_USAGE_run() function in cpu_usage.h, and the percentages is calculated in updateCPUusage() function in proj_lab03.c.

    You need to change the codes in proj_lab03.c as below beacuse you need to set timer period of CPU_USAGE is equal to cpu timers 1 is HAL_setupTimers() in hal.c.

     // initialize the frequency of execution monitoring module

     femHandle = FEM_init(&fem,sizeof(fem));

     FEM_setParams(femHandle,

                   USER_SYSTEM_FREQ_MHz * 1000000.0,                  // timer frequency, Hz

                   (uint32_t)USER_SYSTEM_FREQ_MHz * 10000,          // timer period, cnts

                   USER_CTRL_FREQ_Hz,                                 // set point frequency, Hz

                   1000.0);                                           // max frequency error, Hz

     // initialize the CPU usage module

     cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));

     CPU_USAGE_setParams(cpu_usageHandle,

                        (uint32_t)USER_SYSTEM_FREQ_MHz * 10000,     // timer period, cnts

                        (uint32_t)USER_ISR_FREQ_Hz);                  // average over 1 second of ISRs

    Please check HAL_setupTimers() in hal.c whether is as below.

    void HAL_setupTimers(HAL_Handle handle,const float_t systemFreq_MHz)

    {

     HAL_Obj  *obj = (HAL_Obj *)handle;

     uint32_t  timerPeriod_0p5ms = (uint32_t)(systemFreq_MHz * (float_t)500.0) - 1;

     uint32_t  timerPeriod_10ms = (uint32_t)(systemFreq_MHz * (float_t)10000.0) - 1;

     // use timer 0 for frequency diagnostics

     TIMER_setDecimationFactor(obj->timerHandle[0],0);

     TIMER_setEmulationMode(obj->timerHandle[0],TIMER_EmulationMode_RunFree);

     TIMER_setPeriod(obj->timerHandle[0],timerPeriod_0p5ms);

     TIMER_setPreScaler(obj->timerHandle[0],0);

     // use timer 1 for CPU usage diagnostics

     TIMER_setDecimationFactor(obj->timerHandle[1],0);

     TIMER_setEmulationMode(obj->timerHandle[1],TIMER_EmulationMode_RunFree);

     TIMER_setPeriod(obj->timerHandle[1],timerPeriod_10ms);

     TIMER_setPreScaler(obj->timerHandle[1],0);

     // use timer 2 for CPU time diagnostics

     TIMER_setDecimationFactor(obj->timerHandle[2],0);

     TIMER_setEmulationMode(obj->timerHandle[2],TIMER_EmulationMode_RunFree);

     TIMER_setPeriod(obj->timerHandle[2],0xFFFFFFFF);

     TIMER_setPreScaler(obj->timerHandle[2],0);

     return;

    }  // end of HAL_setupTimers() function