diff -ru source.new.1/com.c source.new/com.c --- source.new.1/com.c 2011-10-08 18:25:25.000000000 +0200 +++ source.new/com.c 2011-10-10 22:04:13.000000000 +0200 @@ -377,6 +377,7 @@ * \note Mxx\n - set mode to 0=manu 1=auto * \note Ixx\n - activate bus ID 01..1f 0xff=single mode * \note Oxxxx\n - set messured temperature , >0000 = disable messurement + * \note C\n - calibrate rco * ******************************************************************************/ static uint8_t com_hex[3]; @@ -425,6 +426,11 @@ case 'V': print_version(); break; +#if HAS_CALIBRATE_RCO + // C\n - calibrate rco + case 'C': + calibrate_rco(); +#endif // D - print status line case 'D': COM_print_debug(-1); @@ -517,7 +523,6 @@ if (com_hex_len!=4) { break; } override_adc_temp=(com_hex[0] >> 4)*1000 + (com_hex[0] & 0x0f) * 100 + (com_hex[1] >> 4)*10 + (com_hex[1] & 0x0f); break; - } COM_flush(); COM_putchar('\n'); diff -ru source.new.1/config.h source.new/config.h --- source.new.1/config.h 2011-10-10 22:12:56.635161001 +0200 +++ source.new/config.h 2011-10-10 21:31:57.000000000 +0200 @@ -81,6 +81,9 @@ #define DEFAULT_TEMPERATURE 2000 +// RC Calibration on UART sending speed +#define HAS_CALIBRATE_RCO 1 + // Some default Values #define BOOT_DD 1 //!< Boot-Up date: day Nur in source.new.1: hr20.hex. diff -ru source.new.1/main.c source.new/main.c --- source.new.1/main.c 2011-09-26 20:31:01.000000000 +0200 +++ source.new/main.c 2011-10-10 21:23:44.000000000 +0200 @@ -294,6 +294,9 @@ //! Initialize the RTC RTC_Init(); + #if HAS_CALIBRATE_RCO + calibrate_rco(); + #endif eeprom_config_init((~PINB & (KBI_PROG | KBI_C | KBI_AUTO))==(KBI_PROG | KBI_C | KBI_AUTO)); diff -ru source.new.1/rtc.c source.new/rtc.c --- source.new.1/rtc.c 2011-09-26 20:31:01.000000000 +0200 +++ source.new/rtc.c 2011-10-10 22:30:03.000000000 +0200 @@ -39,6 +39,7 @@ #include #include #include +#include // HR20 Project includes @@ -47,6 +48,7 @@ #include "task.h" #include "eeprom.h" #include "menu.h" +#include "motor.h" // Vars @@ -358,6 +360,11 @@ bool RTC_AddOneSecond(void) { RTC_Ticks++; // overflow every 136 Years +#if HAS_CALIBRATE_RCO + // Calibrate every 12 hours + if (RTC_Ticks % 43200 == 0) calibrate_rco(); +#endif + if (++RTC_ss >= 60) { RTC_ss = 0; // notify com.c about the changed minute @@ -578,48 +585,37 @@ ******************************************************************************/ void calibrate_rco(void) { - unsigned char calibrate = FALSE; - int temp; - - cli(); // disable global interrupt - CLKPR = (1< 1Mhz - TIMSK2 = 0; // disable OCIE2A and TOIE2 - ASSR = (1<246) {}; // Wait for low timer counter + + uint8_t tmp_tcnt2=TCNT2+2; + while (TCNT2 5) + { + OSCCAL++; } - - if (temp > 6250) { - OSCCAL--; // internRC oscillator to fast, decrease the OSCCAL - } else if (temp < 6120) { - OSCCAL++; // internRC oscillator to slow, increase the OSCCAL - } else { - calibrate = TRUE; // the interRC is correct + else + { + OSCCAL--; } - TCCR1B = (1<