Mehmet Fide

AW32: Period Measurement with Timer Capture Mode

Discussion created by Mehmet Fide on Nov 23, 2007
Latest reply on Nov 27, 2007 by Mehmet Fide
Hi,
 
I have a TXCO 36.864Mhz and my MCU uses it as external xtal. The bus frequency is 18.432Mhz.
I also have a high resolution frequency counter, and it says 0.5ppm error for the TXCO.
I want to measure another signal has frequency 0.5Hz with this time base.
I also measured this low frequency signal with my high resolution counter, and it says 1.5ppm error for it.
 
MCU Xtal error: 0.5ppm (I measured this from MCLK pin of MCU, this is nice feature)
Low frequency signal error: 1.5ppm (I measured this directly from MCU pin that is TPM1CH0, the signal on there is clean, has fast rise time and no jitter, so I eliminated hardware errors)
I expect to measure about 1ppm error with my capture routine below.
 
 
Code:
// 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;}

 
My routine simply works by taking time-stamps of incoming two rise edges and calculate the difference for the period. I'm calculating time-stamp for rise-edges with (main_timer_overflow_counter*65536) + CaptureValue;
 
As the result, I'm measuring 2,304,218 or 2,304,219 for the period. The measured value is stable, this is good for me, but I expect it as 2,304,000. This means I measured 94ppm error instead of 1ppm. and I don't have any idea why it is so. Do you have?
 
Thanks.

Outcomes