// fBus = 18.432MhzTPM1CNT = 0; // reset timer1TPM1MOD = 0; // no modulo// Input capture, rise-edge, ch0 interrupt enable: PULSE1TPM1C0SC = 0b11000100;// Interrupt enable// Bus frequency// Divider: 1/16TPM1SC = 0b01001100;interrupt VectorNumber_Vtpm1ovf void intTPM1OVF(void){ // tpm1 frequency 1.152Mhz // overflow occurs at 1.152Mhz / 65536 ++main_timer_overflow_counter; TPM1SC; TPM1SC_TOF = 0;}interrupt VectorNumber_Vtpm1ch0 void intTPM1CH0(void){ // PULSE1 previous_capture[0] = last_capture[0]; // save previous pulse last_capture[0].OverFlowValue = main_timer_overflow_counter; last_capture[0].CaptureValue = TPM1C0V; last_capture[0].Initialized = 1; last_capture[0].Counter++; TPM1C1SC; TPM1C0SC_CH0F = 0;}
interrupt VectorNumber_Vtpm1ch0 void intTPM1CH0(void){ // PULSE1 ... last_capture[0].OverFlowValue = main_timer_overflow_counter; if(TPM1SC_TOF) last_capture[0].OverFlowValue++; // <------- added last_capture[0].CaptureValue = TPM1C0V; ...}
/* Take the bus frequency directly from the external */ ICGC2 = 8; // Generate a reset request on loss of clock. ICGC1 = 0b00110100; // FBE mode, fbus=16,384 Hz, clock monitor enabled TPM1SC = 0; // disable timer TPM1MOD = 0; TPM1CNT = 0; TPM1C0V = 512; // tpm1 counter, first toogle time TPM1C0SC = 0b00010100; // toggle at compare mode TPM1SC = 0b00001000; // fbus, 1/1 while(!TPM1C0SC_CH0F) __RESET_WATCHDOG(); // first toogle time - 1 TPM1C0V += 1536; tmp = TPM1C0SC; TPM1C0SC_CH0F = 0; while(!TPM1C0SC_CH0F) __RESET_WATCHDOG(); // second toogle time - 0 TPM1C0V += (32768-1536); tmp = TPM1C0SC; TPM1C0SC_CH0F = 0; while(!TPM1C0SC_CH0F) __RESET_WATCHDOG(); // third toogle time - 1 TPM1C0V += 1536; tmp = TPM1C0SC; TPM1C0SC_CH0F = 0; while(!TPM1C0SC_CH0F) __RESET_WATCHDOG(); // fourth toogle time - 0 TPM1SC = 0; // disable timer asm("dcb 0x8D"); // reset the mcu
BasePointer wrote:
I have 16,384 Hz bus frequency at LC60 side and need to generate two rise-edges have time 2sec between them. If I set "TPM1MOD = TPM1C0V = 16384", this gives 94 ppm error. If I set 16383, it gives about 30ppm error. I don't know why.
BasePointer wrote:interrupt VectorNumber_Vtpm1ch0 void intTPM1CH0(void){ // PULSE1 ... last_capture[0].OverFlowValue = main_timer_overflow_counter; if(TPM1SC_TOF) last_capture[0].OverFlowValue++; // <------- added last_capture[0].CaptureValue = TPM1C0V; ...}
bigmac wrote:Will you be able to maintain the required accuracy (5 ppm per day) over temperature, and allowing for aging of the crystal? My understanding is that low frequency crystals have a degraded temperature specification, compared with high frequency AT-cut crystals. When used within a watch, the human body tends to regulate the temperature of the crystal.