Couldn't you use a 16 bit int instead of the 8 bit in the example? That would give +/- 32767 I think?
Disclaimer: I'm a noob to this stuff.
Moderators: adafruit_support_bill, adafruit
rschmit wrote:Yep, I looked at that post previous to writing, and I thought this would be a show stopper:-128 <= cal_factor <= 127
If that's the limit to the range of values for cal_factor, then a full range value only buys me 0.366 seconds per day. At least that's how I was reading it.
// an hour...
if (time_m >= 60) {
cal = eeprom_read_byte((int8_t *)EE_CAL);
if (cal < 0)
{
// clock slow - shorten first second of hour
TCNT2 += -cal + 1;
}
else if (cal > 0)
{
// clock fast - lengthen first second of hour
uint8_t tmp = TCNT2;
while ((TCNT2 - tmp) < cal);
TCNT2 = tmp;
}
time_m = 0;
time_h++;
// lets write the time to the EEPROM
eeprom_write_byte((uint8_t *)EE_HOUR, time_h);
eeprom_write_byte((uint8_t *)EE_MIN, time_m);
}
CLKPR = _BV(CLKPCE); //MEME
CLKPR = 0;
time_s++; // one second has gone by
// HERE WE ADD THE SHITCANNED CODE FROM BELOW
cal = eeprom_read_byte((int8_t *)EE_CAL);
if (cal < 0)
{
// clock slow - shorten first second of hour
TCNT2 += -cal + 1;
}
else if (cal > 0)
{
// clock fast - lengthen first second of hour
uint8_t tmp = TCNT2;
while ((TCNT2 - tmp) < cal);
TCNT2 = tmp;
}
// ADDED
centiseconds = 0;
// a minute!
if (time_s >= 60) {
time_s = 0;
time_m++;
}
// an hour...
if (time_m >= 60) {
/* SHITCANNING THIS CODE BLOCK BY COMMENTING IT OUT
cal = eeprom_read_byte((int8_t *)EE_CAL);
if (cal < 0) {
// clock slow - shorten first second of hour
TCNT2 += -cal + 1;
} else if (cal > 0) {
// clock fast - lengthen first second of hour
uint8_t tmp = TCNT2;
while ((TCNT2 - tmp) < cal);
TCNT2 = tmp;
}
SHITCANNED! */
time_m = 0;
time_h++;
// lets write the time to the EEPROM
eeprom_write_byte((uint8_t *)EE_HOUR, time_h);
eeprom_write_byte((uint8_t *)EE_MIN, time_m);
}
CLKPR = _BV(CLKPCE); //MEME
CLKPR = 0;
time_s++; // one second has gone by
// BEGIN 0.25 HZ BLOCK
if( time_s % 4 == 0 )
{
// HERE WE ADD THE SHITCANNED CODE FROM BELOW
cal = eeprom_read_byte((int8_t *)EE_CAL);
if (cal < 0)
{
// clock slow - shorten first second of hour
TCNT2 += -cal + 1;
}
else if (cal > 0)
{
// clock fast - lengthen first second of hour
uint8_t tmp = TCNT2;
while ((TCNT2 - tmp) < cal);
TCNT2 = tmp;
}
// ADDED
}
// END 0.25 HZ BLOCK
centiseconds = 0;
// a minute!
if (time_s >= 60) {
time_s = 0;
time_m++;
}
Stephanie wrote:Couldn't you use a 16 bit int instead of the 8 bit in the example? That would give +/- 32767 I think?
Disclaimer: I'm a noob to this stuff.
Users browsing this forum: No registered users and 2 guests