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??