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.

request CPU ticks TMS320F28377S

Other Parts Discussed in Thread: CONTROLSUITE

Hi,


currently I'm programming my F28377S which I use for realtime adc tests. I want to save my test results together with a timestamp.

I want to do this by the use of the clock-cycle counter. I want to know the amount of cycles since the program was started. Usually I would use the timer.h library and clock(). However, when I do so, this results in an output: 0.

The next thing I tried is using the CpuTimer0Regs. This did work in the sense that I got numbers up to 300. The code I used is the following:

timestampH = CpuTimer0Regs.TIM.bit.MSW;
timestampL = CpuTimer0Regs.TIM.bit.LSW;

sendString[6] =(int) (timestampL) & 0xFF; // first 8 bits of timestamp
sendString[7] =(int) ((timestampL >> 8)) & 0xFF; // second 8 bits of timestamp
sendString[8] =(int) (timestampH) & 0xFF; // third 8 bits of timestamp
sendString[9] =(int) ((timestampH >> 8)) & 0xFF; // fourth 8 bits of timestamp

However, the maximum output here is around 300, loop of 10 around my full program result in the following timing outputs:

0
328
294
41
189
337
84
232
392
139

for the complete programming part see below

  //volatile uint32_t timestamp;
    uint16_t timestampH;
    uint16_t timestampL;

    bool curVolBit = 0;
    int matrixNmbr = 2;
    int nodeNmbr = 612;
    int curVol = 987;

    for(x = 0; x < 20; x++){
    	//timestamp = CpuTimer0Regs.TIM.bit.MSW;// + (CpuTimer0Regs.TIM.bit.MSW << 16);

    	timestampH = CpuTimer0Regs.TIM.bit.MSW;
    	timestampL = CpuTimer0Regs.TIM.bit.LSW;

        sendString[0] = '€'; //icon for start of packet
        sendString[1] = 'R'; //icon for Reading instruction
        sendString[2] = (matrixNmbr & 0x03) + (curVolBit << 2) + ((nodeNmbr & 0x03) << 6); // bit 0-1 = matrixNmbr, bit 2 = curVolBit, 6-7 = nodeNmbr first 2 bits
        sendString[3] = (nodeNmbr >> 2) & 0xFF ; // nodeNmbr last 8 bits
        sendString[4] = curVol & 0xFF ; // first 8 bits of curVol
        sendString[5] = (curVol >> 8) & 0xFF;// last 8 bits of curVol
        sendString[6] =(int) (timestampL) & 0xFF; // first 8 bits of timestamp
        sendString[7] =(int) ((timestampL >> 8)) & 0xFF; // second 8 bits of timestamp
        sendString[8] =(int) (timestampH) & 0xFF; // third 8 bits of timestamp
        sendString[9] =(int) ((timestampH >> 8)) & 0xFF; // fourth 8 bits of timestamp

        curVol += 10;
    	for(z = 0 ; z < 30; z++)
    		SCI_write(&sendString[z], 1);
    }

it seems that only a part of the timer gets updated. Does anyone know a better timer or a way how to fix this? knowing the clockcycles is enough to me.

  • Bas de Wit,

    What does your initialisation code for CPU timer 0 look like?

    Regards,

    Richard
  • the init looks like the following:
    void initTimer0() {

    //Configure timer0
    CpuTimer0Regs.PRD.all = 400;
    CpuTimer0Regs.TCR.all = 0x4020;
    }
  • The function clock() from time.h only returns '0' . So is there a way to get this working on the running platform?
  • Bas de Wit,

    The CPU timers are 32-bit timers which count down from their user defined period value.  By loading 400 into the PRD register you instruct the timer to count down from that value until it reaches 0, then reset to 400 and repeat.  That's why you never see any larger values in the TIM register.

    If you want to use the entire 32-bit range for timing purposes I suggest loading PRD with 0xFFFFFFFF.

    Please start a different post about the clock() issue.  I'm not the best person to help with that and the thread title should be different.  Thanks.

    Regards,

    Richard

  • Richard,

    thank you! this does indeed work, I have tried to do this an hour ago (through some documentation) and it seems that this works out very well. Will the counter start at 0xFFFFFFFF again when it reached 0? or should I use a different way of reading the clock as a timestamp? I need timestamps for my test results. Tests could take up to over a month.
    I know that I can get to a maximum of 2^32, and I would have to write an interupt based/smart way to keep track of time. However, this means that the clock should start over again from max value when its finished.

    Kind regards,

    Bas

  • Bas de Wit,

    Glad it's working for you. Yes, the timer will automatically reset to the PRD value on reaching zero count.

    If you have a very long duration test and can tolerate less time resolution you may choose to pre-scale the timer clock with the TDDR field in the TPR register.

    You can also keep track of timer zero counts by triggering a CPU interrupt from the timer, and incrementing a software counter in an ISR. That way you can have a very long duration test yet retain the full timer resolution.

    The documentation for the counter is in section 2.8 of the User's Guide for this device:
    www.ti.com/.../spruhx5c.pdf

    There is an example of how to configure and count CPU timer interrupts in the example "cpu_timers" in controlSUITE whic you may find useful.

    Regards,

    Richard