Part Number: TMS320F2810
Other Parts Discussed in Thread: CC3200
Hello there,
We are using the hardware timer for unix timestamp increment in second. But the hardware timer always interrupt in milliseconds. Below is the code we have used. The problem we have found is that every 4 hours before we update the timestamp after getting the actual timestamp from server to the MCU, the MCU timestamp is 2 seconds faster than the actual update server timestamp. If we do not update the timestamp, after may be 4 or 5 days, the timestamp will go around 15 seconds faster than the actual current timestamp.
static interrupt void SystickInterruptHandler()
{
ui64SysTickCounter++;
/* Need to call the extern variable for increasing the UNIX timestamp*/
if ( g_UnixTimestamp != 0 )
{
if ( (ui64SysTickCounter % 1000 ) == 0 )
{
g_UnixTimestamp++;
}
}
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
static void Timer0Initialise(float freq, float period)
{
uint32_t tick;
tick = (uint32_t)(freq * period);
CpuTimer0Regs.PRD.all = tick;
CpuTimer0Regs.TPR.all = 0;
CpuTimer0Regs.TPRH.all = 0;
CpuTimer0Regs.TCR.bit.TSS = 1; // 1 = Stop timer, 0 = Start/Restart Timer
CpuTimer0Regs.TCR.bit.TRB = 1; // 1 = reload timer
CpuTimer0Regs.TCR.bit.SOFT = 1;
CpuTimer0Regs.TCR.bit.FREE = 1; // Timer Free Run
CpuTimer0Regs.TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt
ui64SysTickCounter = 0;
EALLOW;
PieVectTable.TINT0 = &SystickInterruptHandler;
EDIS;
CpuTimer0Regs.TCR.bit.TSS = 0;
IER |= 0x0001;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
}
void Hwtimer_Initialise(void)
{
Timer0Initialise(150000000, 0.001); // 150KHz and 1ms timer.
}
So what could go wrong in the code and what other things that we need to implement in the code.
g_UnixTimestamp is the timestamp that always showing faster by 2 seconds than the actual current time.
Thanks