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.
Hi all,
I use F28035 cputimer0, set as following 1,2,3,4.
when I call "ConfigCpuTimer(&CpuTimer0, 60, mSec1); " I tested waveform of the LED, period is 60ms,
when I change to "ConfigCpuTimer(&CpuTimer0, 1, mSec1); " I tested waveform of the LED, period is 1ms.
Timer->CPUFreqInMHz = Freq;
Timer->PeriodInUSec = Period;
1. sysclk
// SYSTEM CLOCK speed based on internal oscillator = 10 MHz
// 0xC = 60 MHz (12)
PLLset(0xC); // choose from options above
EALLOW;
// LOW SPEED CLOCKS prescale register settings
SysCtrlRegs.LOSPCP.all = 0x0002; // Sysclk / 4 (15 MHz)
SysCtrlRegs.XCLK.bit.XCLKOUTDIV=2;
2. CPUTimer0 set
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 60, mSec1); //mSec1 60000
CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0
3. 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;
}
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
{
Uint32 temp;
// Initialize timer period:
Timer->CPUFreqInMHz = Freq;
Timer->PeriodInUSec = Period;
temp = (long) (Freq * Period);
Timer->RegsAddr->PRD.all = temp;
// Set pre-scale counter to divide by 1 (SYSCLKOUT):
Timer->RegsAddr->TPR.all = 0;
Timer->RegsAddr->TPRH.all = 0;
// Initialize timer control register:
Timer->RegsAddr->TCR.bit.TSS = 1; // 0 = Stop timer, 1 = Start/Restart Timer
Timer->RegsAddr->TCR.bit.TRB = 1; // 1 = reload timer
Timer->RegsAddr->TCR.bit.SOFT = 0;
Timer->RegsAddr->TCR.bit.FREE = 0; // Timer Free Run Disabled
Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt
// Reset interrupt counter:
Timer->InterruptCount = 0;
}
4. interrupt ISR
interrupt void cpu_timer0_isr(void)
{
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; //drive a LED
}
so I'm confused how does it happen? could anyone help me on this?
it may be follow the formula: Periode=60*60000/60MHz=60ms or 1*60000/60MHz=1ms