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.

The timer interrupt period inaccurate??

hi dear all,

 I have a question about the interrupt period accuracy.

I am using 28035, and use one gpio to output a pwm signal. (please not  persuad me to use the epwm module)

here is part of my code:

=====================================================================

interrupt void servo_ISR(void)//2015.5.10 last modified for control servo, output pulse

{

     switch(GpioDataRegs.GPADAT.bit.GPIO10)

     {

     case 0:/*when the output is low*/

         CpuTimer2Regs.PRD.all=(long)60*1500;/*GPIO10 on for 1500usec*/

         CpuTimer2Regs.TCR.bit.TRB = 1    ;/*reload interrput period*/

         CpuTimer2Regs.TCR.bit.TSS = 0;    /* 1 = Stop timer, 0 = Start/Restart Timer*/

         GpioDataRegs.GPADAT.bit.GPIO10=1;

         break;

     case 1:/* when the output is high*/

         CpuTimer2Regs.PRD.all=(long)60*15000; // GPIO10 off for 15msec;

         CpuTimer2Regs.TCR.bit.TRB = 1;                //reload interrput period

         CpuTimer2Regs.TCR.bit.TSS = 0;             // 1 = Stop timer, 0 = Start/Restart Timer

GpioDataRegs.GPADAT.bit.GPIO10=0;

         break;

     }/*end of case*/

}/*end of servo_ISR *

=========================================================================

the initialize of CpuTimer.etc.. are done in main(), so let us pass it.

and  ConfigCpuTimer(&CpuTimer2, 60, 20000); is set in main().

and the output wil be:

however according to my design, the pos width should be 1500sec.

and I try different value of pulse width and make plot:

the red dot are the pulse width value i got, and black are predict value. with different interrupt perion desire

and the red line is the linera fitting, which slope is 0.9829.

So the value 0.9829/60(usec) is my question, it means how much time the timer2tim decrement by one, which ideally should be 1/60(usec)

so either the the timer is faster, or the system clock greater than 60MHz?

Or my code is wrong?? 

  • Hi,

    kuotung tsai said:

    I am using 28035, and use one gpio to output a pwm signal. (please not  persuad me to use the epwm module)



    Ok, I'll try not to.  The ePWM peripheral does make all this a lot easier though.  :)


    kuotung tsai said:

    So the value 0.9829/60(usec) is my question, it means how much time the timer2tim decrement by one, which ideally should be 1/60(usec)

    so either the the timer is faster, or the system clock greater than 60MHz?

    Or my code is wrong?? 



    The chip itself will never be exactly 60MHz.  It will have some standard deviation just like all other physical signals.  In particular, I am guessing that you are using the default code which uses the less precise internal oscillator by default.  My guess is that, if you output the XCLKOUT signal (a signal that represents SYSCLK) from GPIO18, you'll see that it will show the same deviation that your are seeing on your ePWM. 

    An option to reduce the deviation is to use a different clock source than the internal oscillator.  If you are using a controlCARD, an extremely precise external crystal has been soldered onto the board.  You just have to change your code such that you use the crystal once the device has powered up.


    Thank you,
    Brett

  • Hi Brett,

     I did what you told me, check the xclk. And found the sysclkout is not exactly 60MHz, it around 61MHz

    and it looks like this:

    but I am  only curious about the sinusoidal form, is that right? because I thought it will be square form.

    thanks

    kuotung

  • Hi,
    I figure it out, since the sysclkout is 60MHz, and the rising and falling time for GPIO will be 13nsec(max)
    so, it will not like square, if sysclkout is about 5MHz, then the square form will show up.