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.

Problem with CPU Timer

Other Parts Discussed in Thread: TMS320F28335, CONTROLSUITE

Hello,

I try to use a CPU timer for DSP TMS320F28335 and there are some mistakes in my calculation.
The processing and the writing are always the same but the timer counter can pass from 1500000 to 1120000
as from 1500000 to 10000 and it is not really good for me. So I would like to ask you if my method to
count the time of Processing+Writing is good or does something appear to be incorrect ? Thank you...

// Initialisations
Uint32 toto = 0;
        
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, FREQ150_MHz, 10000);
        
        
for(;;){
        
   // Start Timer
   CpuTimer0Regs.TCR.bit.TSS = 0;

   Processing();
   Writing();
            
   //Stop Timer
   CpuTimer0Regs.TCR.bit.TSS = 1;
            
   // Time calculation
   val_p = ((double) (CpuTimer0Regs.PRD.all - CpuTimer0Regs.TIM.all)) /  ( (double) FREQ_Hz ) + 1750.0/1000000.0;
            
   // DEBUG
   toto = (double) (CpuTimer0Regs.PRD.all - CpuTimer0Regs.TIM.all);
            
// toto can be equal to 300000 as to 1400000, is it //normal?
// Because I want just 2ms and 1500000*6.67e-9 //(<=>CPU_RATE) = 10ms
// So 1400000 is really higher than what I want...
// This soft works fine on a computer in 0.3ms, so it would be faster on DSP...
            
            
            
 // Waiting function
 DELAY_US(1750);
/*where #define DELAY_US(A)  DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L)  /5.0L)*/
            

            
    // Reload Timer
    CpuTimer0Regs.TCR.bit.TRB = 1
            
}
        
        
        
void InitCpuTimers(void){

// CPU Timer 0
// Initialize address pointers to respective timer //registers:
CpuTimer0.RegsAddr = &CpuTimer0Regs;
// Initialize timer period to maximum:
CpuTimer0Regs.PRD.all  = 0xFFFFFFFF;
// Initialize pre-scale counter to divide by 1 //(SYSCLKOUT):
CpuTimer0Regs.TPR.all  = 0;
CpuTimer0Regs.TPRH.all = 0;
// Make sure timer is stopped:
CpuTimer0Regs.TCR.bit.TSS = 1;
// Reload all counter register with period value:
CpuTimer0Regs.TCR.bit.TRB = 1;
// Reset interrupt counters:
CpuTimer0.InterruptCount = 0;

}
  • Hi Cedric!

    You can try to do it in a simpler way. Take please interrupt handler of timer0 from ti\controlSUITE\device_support\f2833x\v133\DSP2833x_examples_ccsv4\cpu_timer\ and try the following:

    (BTW about DELAY_US refer please to this thread (it is important))

     http://e2e.ti.com/support/microcontrollers/c2000/f/171/p/276146/964855.aspx#964855

    Regards, Igor

     Uint32 t1=0, t2 =0, deltat =0:
    
    
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer0, FREQ150_MHz, 1);
    .................................................................................................
    for(;;){
            
       t1 = CpuTimer0.InterruptCount;
      
       Processing();
       Writing();
       t2 = CpuTimer0.InterruptCount;
       //calculation of deltat us
       if (t2>t1) {deltat = t2-t1}
       else deltat =4294967295-(t1-t2);     
      
       // Waiting function
     DELAY_US(1750);
    }
    
    
    
    
    
    
            
  • Hello Igor, How are you?

    Thank you very much for your answer ! It is really simpler! And I have read your link of DELAY_US, I think I would be more careful with this... Your great! Thank you.  Have a good day.

    Regards,

    Cédric

  • Hi Cedric!

    I'm fine and I'm fine twice if my help was useful. Perhaps you don't need such high accuracy (1 us). Then you can reprogram timer0 on other interval.

    Regards,

    Igor