#define STOPWATCH_100HZ_TICK 328 //!!! (32768 / 100)
// Timer interrupts occur every 32768/100 = 328 ACLK
// --> stopwatch runs too slow (1 sec nominal != 100 interupts * 328 ACLK = 32800 ACLK =
// 1.00098 sec)
// --> ideally correct timer value every 10 ticks by (32768 - 32800)/10 = 3.2
// --> correct timer value every 10Hz by 3,
// --> correct timer value every 1Hz correct by 5
value += STOPWATCH_100HZ_TICK;
if (sStopwatch.swtIs1Hz)
{
value -= 5;
sStopwatch.swtIs1Hz = 0;
sStopwatch.swtIs10Hz = 0;
}
else if (sStopwatch.swtIs10Hz)
{
value -= 3;
sStopwatch.swtIs10Hz = 0;
}
// --> correct timer value every 10Hz by 3,
// --> correct timer value every 1Hz correct by 5
if (sStopwatch.swtIs1Hz)
{
value -= 5;
sStopwatch.swtIs1Hz = 0;
sStopwatch.swtIs10Hz = 0;
}
if (sStopwatch.swtIs1Hz)
{
value -= 2; //!!! 5;
sStopwatch.swtIs1Hz = 0;
sStopwatch.swtIs10Hz = 0;
}
display_stopwatch(LINE2, DISPLAY_LINE_UPDATE_FULL);
void stopwatch_tick(void)
{
static u8 delay = 0;
static u16 MyKorr = 0;
static u8 My_First_Add_Sec = 0;
// Default view (< 20 minutes): display and count MM:SS:hh
if (sStopwatch.viewStyle == DISPLAY_DEFAULT_VIEW)
{
// Add 1/100 sec
sStopwatch.time[7]++;
// Draw flag minimizes display update activity
//
// swt.drawFlag = 1: second L
// swt.drawFlag = 2: second H/L
// swt.drawFlag = 3: minutes L, second H/L
// swt.drawFlag = 4: minutes H/L, second H/L
// swt.drawFlag = 5: hours L, minutes H/L, second H/L
// swt.drawFlag = 6: hours H/L, minutes H/L, second H/L
// swt.drawFlag = 7: 1/10 sec, 1/100 sec
// swt.drawFlag = 8: 1/100 sec (every 17/100 sec to reduce display draw activity)
if (delay++ > 17)
{
sStopwatch.drawFlag = 8; //8
delay = 0;
}
if (MyKorr++ == 320) //Каждые 3.20 секунды вычитаем 0.01 сек. для коррекции секундомера
{
sStopwatch.time[7]--;
MyKorr = 0;
};
// Add 1/10 sec
if (sStopwatch.time[7] == 0x3A)
{
sStopwatch.time[7] = '0';
sStopwatch.time[6]++;
My_First_Add_Sec = 0;
// 1/10Hz trigger
sStopwatch.swtIs10Hz = 1;
// Update draw flag
sStopwatch.drawFlag = 7;
}
}
else // Alternative view (20 minutes .. 20 hours): display and count
// HH:MM:SS
{
// Just add 1 second
if (My_First_Add_Sec != 0)
{
sStopwatch.time[6] = 0x3A;
}
My_First_Add_Sec = 1;
}
// Second overflow?
if (sStopwatch.time[6] == 0x3A)
{
// Reset draw flag
sStopwatch.drawFlag = 1;
// 1Hz trigger
sStopwatch.swtIs1Hz = 1;
// Add data
sStopwatch.time[6] = '0';
sStopwatch.time[5]++; // second L (0 - 9)
if (sStopwatch.time[5] == 0x3A)
{
sStopwatch.drawFlag++; // 2
sStopwatch.time[5] = '0';
sStopwatch.time[4]++; // second H (0 - 5)
if (sStopwatch.time[4] == '6')
{
sStopwatch.drawFlag++; // 3
sStopwatch.time[4] = '0';
sStopwatch.time[3]++; // minutes L (0 - 9)
if (sStopwatch.time[3] == 0x3A)
{
sStopwatch.drawFlag++; // 4
sStopwatch.time[3] = '0';
sStopwatch.time[2]++; // minutes H (0 - 5)
if (sStopwatch.time[2] == '2')
{
// SWT display changes from MM:SS:hh to HH:MM:SS when reaching 20 minutes
sStopwatch.viewStyle = DISPLAY_ALTERNATIVE_VIEW;
display_stopwatch(LINE2, DISPLAY_LINE_UPDATE_FULL);
}
else if (sStopwatch.time[2] == '6')
{
sStopwatch.drawFlag++; // 5
sStopwatch.time[2] = '0';
sStopwatch.time[1]++; // hours L (0-9)
if (sStopwatch.time[1] == 0x3A)
{
sStopwatch.drawFlag++; // 6
sStopwatch.time[1] = '0';
sStopwatch.time[0]++; // hours H (0-1)
if (sStopwatch.time[0] == '2')
{
// When reaching 20 hours, start over
reset_stopwatch();
sStopwatch.state = STOPWATCH_RUN;
display_stopwatch(LINE2, DISPLAY_LINE_UPDATE_FULL);
}
}
}
}
}
}
}
// Always set display update flag
display.flag.update_stopwatch = 1;
}
Madf писал(а):На счет ">20 мин", отказываться от этой возможности не хотелось
#define STOPWATCH_100HZ_TICK 328 //!!! (32768 / 100)
//!!! display_stopwatch(LINE2, DISPLAY_LINE_UPDATE_FULL);
// SWT display changes from MM:SS:hh to HH:MM:SS when reaching 20 minutes
if (sStopwatch.viewStyle == DISPLAY_DEFAULT_VIEW)
{
sStopwatch.time[1]--; //!!!
}
sStopwatch.viewStyle = DISPLAY_ALTERNATIVE_VIEW;
//!!! display_stopwatch(LINE2, DISPLAY_LINE_UPDATE_FULL);
Сейчас этот форум просматривают: Yandex [Bot] и гости: 1