<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AW32: Period Measurement with Timer Capture Mode in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166374#M10604</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello BP,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I cannot explain why you are getting an error of about 200 TPM cycles.&amp;nbsp;&lt;/FONT&gt; &lt;FONT size="2"&gt;I can see one potentially&amp;nbsp;intermittent problem with your code, but this would produce an error of 66636 TPM cycles, should it occur.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The problem would occur only&amp;nbsp;if the capture value should ever be zero (this assumes that&amp;nbsp; the overflow interrupt occurs when the counter is zero).&amp;nbsp; When both interrupts are simultaneously generated, the capture interrupt will take precedence.&amp;nbsp; Therefore, the overflow counter may not have been updated when the capture value is read.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The simplest way to compensate for this possibility - if the capture value is zero, increment the stored overflow counter value (but do not increment the actual overflow counter since this would be updated immediately the channel ISR completes).&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Alternatively, if it happens that the overflow interrupt occurs when the counter value is 65535 (I don't know), this problem might not occur.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I&amp;nbsp;seem to recall&amp;nbsp;an application note that covered input capture issues for HC908 TIM module.&amp;nbsp; I suspect it is quite probable that the TPM module will behave slightly differently in the timer overflow department.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I'm not sure if it will achieve anything for your error problem, but you might try reducing the TPM modulo value somewhat, perhaps a decimal value of 57599, and see whether the measurement discrepancy alters.&amp;nbsp; With this value, you should get exactly 40 overflows for your 0.5 Hz signal.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Nov 2007 20:15:11 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2007-11-26T20:15:11Z</dc:date>
    <item>
      <title>AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166371#M10601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have a TXCO 36.864Mhz and my MCU uses it as external xtal. The bus frequency is 18.432Mhz.&lt;/DIV&gt;&lt;DIV&gt;I also have a high resolution frequency counter, and it says 0.5ppm error for the TXCO.&lt;/DIV&gt;&lt;DIV&gt;I want to measure another signal has frequency 0.5Hz with this time base.&lt;/DIV&gt;&lt;DIV&gt;I also measured this low frequency signal with my high resolution counter, and it says 1.5ppm error for it.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;MCU Xtal error: 0.5ppm (I measured this from MCLK pin of MCU, this is nice feature)&lt;/DIV&gt;&lt;DIV&gt;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&amp;nbsp;no jitter, so I eliminated hardware errors)&lt;/DIV&gt;&lt;DIV&gt;I expect to measure about 1ppm error with my capture routine below.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;// 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){&amp;nbsp; // tpm1 frequency 1.152Mhz&amp;nbsp; // overflow occurs at 1.152Mhz / 65536&amp;nbsp; ++main_timer_overflow_counter;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1SC;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1SC_TOF = 0;}interrupt VectorNumber_Vtpm1ch0 void intTPM1CH0(void){&amp;nbsp; // PULSE1&amp;nbsp; previous_capture[0] = last_capture[0]; // save previous pulse&amp;nbsp;&amp;nbsp;&amp;nbsp; last_capture[0].OverFlowValue = main_timer_overflow_counter;&amp;nbsp; last_capture[0].CaptureValue = TPM1C0V;&amp;nbsp; last_capture[0].Initialized = 1;&amp;nbsp; last_capture[0].Counter++;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1C1SC;&amp;nbsp; TPM1C0SC_CH0F = 0;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;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&amp;nbsp;(main_timer_overflow_counter*65536) + CaptureValue;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;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. &lt;SPAN aria-label="Sad" class="emoticon_sad emoticon-inline" style="height:16px;width:16px;"&gt;&lt;/SPAN&gt; and I don't have any idea why it is so. Do you have?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:13:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166371#M10601</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2020-10-29T09:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166372#M10602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;I looked at your code, but as I&amp;nbsp; have got no frequency counter, it is a bit difficult to measure.&lt;/DIV&gt;&lt;DIV&gt;One thing that I don't understand, why are you using the channel interrupt AND the overflow interrupt?&lt;/DIV&gt;&lt;DIV&gt;Another thing is that as the TPMxCnV register was not initallized, it will have 0x0000 as the interrupt value. The same value is for the overflow interrupt. So those two interrupts must be coming very close to each other.&lt;/DIV&gt;&lt;DIV&gt;I would only use the overflow interrupt.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;But as I have no frequency counter, I can't measure the output frequency.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Ake&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Nov 2007 23:16:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166372#M10602</guid>
      <dc:creator>Ake</dc:creator>
      <dc:date>2007-11-23T23:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166373#M10603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi Ake,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm using TPMxCnV to capture the time of the coming rise edge of an external signal. With this way, I can measure the period of the signal.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;From AW32 Datasheet / Chapter 10 Timer/PWM (S08TPMV2):&lt;/DIV&gt;&lt;DIV&gt;----------------------------------------------------------------------------------------------&lt;/DIV&gt;&lt;DIV&gt;10.5.2.1 Input Capture Mode&lt;BR /&gt;With the input capture function, the TPM can capture the time at which an external event occurs.&lt;/DIV&gt;&lt;DIV&gt;----------------------------------------------------------------------------------------------&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I need the channel interrupt to know capture value, and using timer interrupt to control overflows. I don't know about initializing TPMxCnV.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2007 14:53:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166373#M10603</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2007-11-26T14:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166374#M10604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello BP,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I cannot explain why you are getting an error of about 200 TPM cycles.&amp;nbsp;&lt;/FONT&gt; &lt;FONT size="2"&gt;I can see one potentially&amp;nbsp;intermittent problem with your code, but this would produce an error of 66636 TPM cycles, should it occur.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The problem would occur only&amp;nbsp;if the capture value should ever be zero (this assumes that&amp;nbsp; the overflow interrupt occurs when the counter is zero).&amp;nbsp; When both interrupts are simultaneously generated, the capture interrupt will take precedence.&amp;nbsp; Therefore, the overflow counter may not have been updated when the capture value is read.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The simplest way to compensate for this possibility - if the capture value is zero, increment the stored overflow counter value (but do not increment the actual overflow counter since this would be updated immediately the channel ISR completes).&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Alternatively, if it happens that the overflow interrupt occurs when the counter value is 65535 (I don't know), this problem might not occur.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I&amp;nbsp;seem to recall&amp;nbsp;an application note that covered input capture issues for HC908 TIM module.&amp;nbsp; I suspect it is quite probable that the TPM module will behave slightly differently in the timer overflow department.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I'm not sure if it will achieve anything for your error problem, but you might try reducing the TPM modulo value somewhat, perhaps a decimal value of 57599, and see whether the measurement discrepancy alters.&amp;nbsp; With this value, you should get exactly 40 overflows for your 0.5 Hz signal.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2007 20:15:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166374#M10604</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2007-11-26T20:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166375#M10605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I see your point, channel interrupts has higher priority than the overflow. I&amp;nbsp;modified&amp;nbsp;ISR like below:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;interrupt VectorNumber_Vtpm1ch0 void intTPM1CH0(void){  // PULSE1  ...    last_capture[0].OverFlowValue = main_timer_overflow_counter;  if(TPM1SC_TOF) last_capture[0].OverFlowValue++; // &amp;lt;------- added    last_capture[0].CaptureValue = TPM1C0V;  ...}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;I have two devices currently working on. One of them is a metering application and uses LC60. This application needs accurate RTC (0.5sec/day). So I need to calibrate its low power crystal. To able to do this, I designed a calibrator with AW32. The scenario is simple, I will generate a signal that has period 2.000000sec at LC60 side(output-compare) and measure it at AW32 side(input-capture). I found my problem(94ppm) at LC60 side, the measurement unit (AW32) works well.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have 16,384 Hz bus frequency at LC60 side and need to generate two rise-edges&amp;nbsp;have time 2sec between them. If I set "TPM1MOD = TPM1C0V = 16384", this gives 94 ppm error.&amp;nbsp;If I set 16383, it gives about 30ppm error. I don't know why.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I re-wrote my pulse generation routine at LC60 side by changing only TPM1C0V, this generated acurate 2 sec pulses and AW32 measured them perfectly.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;    /* 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&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks for your helps.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:13:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166375#M10605</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2020-10-29T09:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166376#M10606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello BP,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;BasePointer wrote:&lt;/FONT&gt;&lt;/P&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I have 16,384 Hz bus frequency at LC60 side and need to generate two rise-edges&amp;nbsp;have time 2sec between them. If I set "TPM1MOD = TPM1C0V = 16384", this gives 94 ppm error.&amp;nbsp;If I set 16383, it gives about 30ppm error. I don't know why.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;For an overflow period of 16384 TPM cycles, the correct setting for TPM1MOD should be 16383 (one less than the overflow period required, since an additional cycle period will elapse before the counter is zeroed).&amp;nbsp; The TPM1C0V register may contain any value, 16383 or less.&amp;nbsp; A difference of one cycle period does amount to about 61 ppm, as you have measured.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Will you be able to maintain the required accuracy (5 ppm per day)&amp;nbsp;over temperature, and allowing for aging of the crystal?&amp;nbsp; My understanding is that&amp;nbsp;low frequency crystals&amp;nbsp;have a degraded temperature specification, compared with high frequency AT-cut crystals.&amp;nbsp; When used within a watch, the human body tends to regulate the temperature of the crystal.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;BasePointer wrote:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;FONT size="2"&gt;interrupt VectorNumber_Vtpm1ch0 void intTPM1CH0(void){  // PULSE1  ...    last_capture[0].OverFlowValue = main_timer_overflow_counter;  if(TPM1SC_TOF) last_capture[0].OverFlowValue++; // &amp;lt;------- added    last_capture[0].CaptureValue = TPM1C0V;  ...}&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;I have a problem with simply testing the overflow flag.&amp;nbsp; Since quite a few bus cycles will elapse between the occurrence of the input capture event, and the eventual&amp;nbsp;testing of the flag,&amp;nbsp;if the flag should become set sometime after the input capture event, an erroneous correction would be applied.&amp;nbsp; I think you will need to test the input capture value, as previously described.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:13:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166376#M10606</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166377#M10607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;BP,&lt;/DIV&gt;&lt;DIV&gt;If you can find a copy, the old 68HC11 Users Manual has a good example of using the overflow for measuring long time intervals. Granted, it's in assembly, but it explains the timing issues pretty well. I've used the method it outlines on more than one occassion in both C and assembly. Just a thought...&lt;/DIV&gt;&lt;DIV&gt;BA&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Nov 2007 02:38:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166377#M10607</guid>
      <dc:creator>ballen</dc:creator>
      <dc:date>2007-11-27T02:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: AW32: Period Measurement with Timer Capture Mode</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166378#M10608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;bigmac wrote:&lt;BR /&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Will you be able to maintain the required accuracy (5 ppm per day)&amp;nbsp;over temperature, and allowing for aging of the crystal?&amp;nbsp; My understanding is that&amp;nbsp;low frequency crystals&amp;nbsp;have a degraded temperature specification, compared with high frequency AT-cut crystals.&amp;nbsp; When used within a watch, the human body tends to regulate the temperature of the crystal.&lt;/FONT&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi Mac,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I make temperature&amp;nbsp; compensation for RTC like mentioned TI's application note: &lt;A href="http://focus.ti.com/lit/ml/slap107/slap107.pdf" rel="nofollow" target="_blank"&gt;http://focus.ti.com/lit/ml/slap107/slap107.pdf&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It is easy for also LC60.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;BP.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Nov 2007 23:05:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/AW32-Period-Measurement-with-Timer-Capture-Mode/m-p/166378#M10608</guid>
      <dc:creator>BasePointer</dc:creator>
      <dc:date>2007-11-27T23:05:01Z</dc:date>
    </item>
  </channel>
</rss>

