<?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: MCF51QE128 timer module in ColdFire/68K Microcontrollers and Processors</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150395#M3794</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;You are using TPM module. Then why you are disabling/enabling TPM module clock (SCGC1 clock gating)? You should not touch any module register when corresponding SCGC1 bit is 0!&lt;/DIV&gt;&lt;DIV&gt;If I remove this line from ISR, then a write to TPM1MOD starts working.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;SCGC1_TPM1 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Also, why are you&amp;nbsp;resetting TPM1CNT? TPM overflow does it for you automatically. Purpose of disabling (TPM1SC = 0b01000111) and reenabling TPM clock is also not clear.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 07 Feb 2009 15:51:56 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2009-02-07T15:51:56Z</dc:date>
    <item>
      <title>MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150394#M3793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi all,&lt;/DIV&gt;&lt;DIV&gt;in the MAIN part of my program, I have this init code for TPM1:&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;SCGC1_TPM1 = 1;TPM1MOD = 0x3F;TPM1SC = 0b01001111;&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;(mod value = 0x3F, bus clock divided by 128, overflow interrupt enabled)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Interrupt service rutine is here:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void interrupt VectorNumber_Vtpm1ovf commutationTime(void) {&amp;nbsp; TPM1SC_TOF = 0;&amp;nbsp; SCGC1_TPM1 = 0; // stop clock&amp;nbsp; TPM1SC = 0b01000111; // stop clock&amp;nbsp; TPM1CNT = 0; // reset timer&amp;nbsp; TPM1MOD = 0x2; // change mod value&amp;nbsp; TPM1SC = 0b01001111; // start clock&amp;nbsp;&amp;nbsp; SCGC1_TPM1 = 1; // start clock&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTGD_PTGD7 ^= 1; // here I toggle one pin to see what timer does&lt;/PRE&gt;&lt;PRE&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Output signal should be first toggled after timer reaches 0x3F, in the interrupt service routine the mod value is changed to 0x02, so then the signal should have&amp;nbsp;higher frequency.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My problem is, that the mod value never changes to 0x02, I don't know why. Any advice?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;And is there any manual how to operate TPM modules? I think there is not said all in the datasheet of MCF51QE128, because this is not my only problem with TPM modules, they just don't work as they should.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Martin&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:52:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150394#M3793</guid>
      <dc:creator>gaminn</dc:creator>
      <dc:date>2020-10-29T08:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150395#M3794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;You are using TPM module. Then why you are disabling/enabling TPM module clock (SCGC1 clock gating)? You should not touch any module register when corresponding SCGC1 bit is 0!&lt;/DIV&gt;&lt;DIV&gt;If I remove this line from ISR, then a write to TPM1MOD starts working.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;SCGC1_TPM1 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Also, why are you&amp;nbsp;resetting TPM1CNT? TPM overflow does it for you automatically. Purpose of disabling (TPM1SC = 0b01000111) and reenabling TPM clock is also not clear.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Feb 2009 15:51:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150395#M3794</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-02-07T15:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150396#M3795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Sorry, I didn't read the datasheet carefully...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have another problem with TPM. What happens, when I write to TPMxCNT register? Datasheet says that it simply&amp;nbsp;resets TPMxCNT... But I have this code:&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;void interrupt VectorNumber_Vtpm1ch0 zeroCrossing(void) { // TPM1CH0 interrupt service  // another code here  TPM1CNT = 0;
  TPM1SC = (unsigned char) (TPM1SC &amp;amp; 0b00000111); // stop counter, but keep clock divider&lt;/PRE&gt;&lt;PRE&gt;  if(TPM2CNT == 0) {    // here I test TPM2CNT for 0, and it is 0  }    TPM2CNT = 0; // this is THE line&lt;/PRE&gt;&lt;PRE&gt;  TPM2MOD = (unsigned short) (someVar); // set new modulo value for TPM2  TPM2SC = (unsigned char) (0b01001000 | TPM1SC); // set TPM2 clock divider the same as TPM1 clock divider, start timer&lt;/PRE&gt;&lt;PRE&gt;  // another code here&lt;/PRE&gt;&lt;PRE&gt;  TPM1SC = (unsigned char) (TPM1SC | 0b01001000); start timer&lt;/PRE&gt;&lt;PRE&gt;  // another code here&lt;/PRE&gt;&lt;PRE&gt;  TPM2SC;
  TPM2SC_TOF;

  TPM1C0SC;
  TPM1C0SC_CH0F = 0;}&lt;/PRE&gt;&lt;PRE&gt;void interrupt VectorNumber_Vtpm2ovf commutationTime(void) { // TPM2 overflow interrupt service
  TPM2SC = 0b00000111; // stop counter
&lt;/PRE&gt;&lt;PRE&gt;  // another code here&lt;/PRE&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; TPM2SC;&lt;BR /&gt;&amp;nbsp; TPM2SC_TOF = 0;&lt;/FONT&gt;&lt;BR /&gt;}&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;TPM1CH0 is configured as input capture, TPM2 is modulo counter which generates overflow interrupt.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When I delete the line "TPM2CNT = 0;" in TPM1CH0 interrupt service, program does something different than when the line is there (it doesn't matter&amp;nbsp;what the difference is). I test if TPM2CNT is zero right before the line "TPM2CNT = 0;" and it is, so the "TPM2CNT = 0;"&amp;nbsp; line should not have any effect, as it resets already reseted counter. TPM2 counter is also stopped as you can see from the code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;So&amp;nbsp;in fact, what "TPM2CNT = 0;" does?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by gaminn on &lt;SPAN class="date_text"&gt;2009-02-08&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;12:41 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by gaminn on &lt;SPAN class="date_text"&gt;2009-02-08&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:27 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:52:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150396#M3795</guid>
      <dc:creator>gaminn</dc:creator>
      <dc:date>2020-10-29T08:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150397#M3796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;As the doc say, a write to TPMxCNT register clears TPMxCNT. Also TPMxCNT overflow to zero causes overflow interrupt. But it takes some time&amp;nbsp;for CPU to&amp;nbsp;reach code&amp;nbsp;in your&amp;nbsp;commutationTime ISR, and all this time TPMxCNT keeps counting! So when you stop TPM2 counter in commutationTime ISR, TPM2CNT&amp;nbsp;most probably is already&amp;nbsp;not zero.&amp;nbsp;Hope this answers your question.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Feb 2009 23:44:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150397#M3796</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-02-08T23:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150398#M3797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;As I have written, I&amp;nbsp;know that TPM2CNT is zero in&amp;nbsp;zeroCrossing ISR. You can see there code:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; if(TPM2CNT == 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // here I test TPM2CNT for 0, and it is 0&lt;BR /&gt;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;and program everytime goes inside this if. Additionally, I clear TPM2CNT in commutationTime ISR (I forgot to write it):&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;void interrupt VectorNumber_Vtpm2ovf commutationTime(void) {  TPM2SC = 0b00000111;  TPM2CNT = 0;    // another code here  TPM2SC;  TPM2SC_TOF = 0;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;If I specify that different behaviour between zeroCrossing ISR with and without "TPM2CNT = 0;" - program without that line does what&amp;nbsp;I want, program with the line causes that TPM2CNT overflow interrupt is somehow masked and the commutationTime&amp;nbsp;ISR routine is not performed.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PS: I know I have one version of functional program, but I would like to know what causes that difference in behaviour.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:52:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150398#M3797</guid>
      <dc:creator>gaminn</dc:creator>
      <dc:date>2020-10-29T08:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150399#M3798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;How do you test if TMP2CNT is zero. Did you put breakpoint at // ?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp; if(TPM2CNT == 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // here I test TPM2CNT for 0, and it is 0&lt;BR /&gt;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Without any code between {}, branch to past {} could be eliminated.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I believe write to TPM2CNT clears TPM2CNT.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Feb 2009 04:43:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150399#M3798</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-02-09T04:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150400#M3799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&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;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */   #define SAMPLES 3&lt;/PRE&gt;&lt;PRE&gt;word samplesHistory[SAMPLES];unsigned char samplePosition = 0;char waitingForZeroCrossing = 1; // 1 = zero crossing expected ; 0 = commutation planned&lt;/PRE&gt;&lt;PRE&gt;/********************************************/Commutation routine/********************************************/&lt;/PRE&gt;&lt;PRE&gt;void commutate(void) {  PTGD_PTGD7 ^= 1; // toggle this pin  }&lt;/PRE&gt;&lt;PRE&gt;/********************************************/TPM1CH0 ISR/********************************************/void interrupt VectorNumber_Vtpm1ch0 zeroCrossing(void) {  samplesHistory[samplePosition] = TPM1C0V; // store timer value when input capture occurs  if(++samplePosition &amp;gt; SAMPLES) { // calculate next position in the samplesHistory array    samplePosition = 0;  }  TPM1SC = (unsigned char) (TPM1SC &amp;amp; 0b00000111); // stop timer but keep divider  TPM1CNT = 0; // reset counter     int sum = 0;  unsigned char i;  if(!waitingForZeroCrossing) { // there was a commutation planned but zero crossing occured earlier    commutate();  }    for(i = 0 ; i &amp;lt; SAMPLES ; i++) { // calculate sum of last samples    sum += samplesHistory[i];   }  TPM2MOD = (unsigned short) (sum / (2*SAMPLES)); // TPM2MOD = half of last samples average, this makes 90 degrees shift of output signal  TPM2SC = (unsigned char) (0b01001000 | TPM1SC); // start TPM2 with the same clock divider as TPM1  TPM2CNT = 0;    waitingForZeroCrossing = 0;    TPM1SC = (unsigned char) (TPM1SC | 0b01001000); // start TPM1    TPM1SC;  TPM1SC_TOF = 0;  TPM1C0SC;  TPM1C0SC_CH0F = 0;  }/********************************************/TPM1 overflow ISR/********************************************/void interrupt VectorNumber_Vtpm1ovf zeroCrossingOverflow(void) {  TPM1SC;  TPM1SC_TOF = 0;&lt;/PRE&gt;&lt;PRE&gt;// I don't use this ISR but if I disable TPM1 overflow interrupts, the program doesn't work...why?}&lt;/PRE&gt;&lt;PRE&gt;/********************************************/TPM2 overflow ISR/********************************************/void interrupt VectorNumber_Vtpm2ovf commutationTime(void) {  TPM2SC = 0b00000111; // stop counter  TPM2CNT = 0; // reset counter    commutate(); // make commutation    waitingForZeroCrossing = 1;    TPM2SC;  TPM2SC_TOF = 0;}/********************************************/MAIN/********************************************/void main(void) {  PTGDD_PTGDD7 = 1; // output signal will be here    ICSC2_BDIV = 0; // divider = 1 // TPM1CH0 will be input capture //    TPM1MOD = 0xFFFF;  TPM1C0SC = 0b01001100;  TPM1SC = 0b01001111;      EnableInterrupts; /* enable interrupts */  for(;;) {    __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;This is whole code of my program. On TPM1CH0 pin (input capture) there is an rectangular input signal (e.g. 1kHz, its edges are called zero crossing in the context of my use). On PTG7 pin there is output signal, which should be also rectangular, of same frequency but shifted by 90 degrees (left or right it doesn't matter). The program will drive BLDC motor....if it works sometimes.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Also (it is another remark), my program stops working when I disable TPM1 overflow interrupt. But&amp;nbsp;the overflow interrupt&amp;nbsp;is unused in fact, it doesn't make any work there.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am really confused about it....&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by gaminn on &lt;SPAN class="date_text"&gt;2009-02-08&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;10:02 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by gaminn on &lt;SPAN class="date_text"&gt;2009-02-08&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;10:04 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by gaminn on &lt;SPAN class="date_text"&gt;2009-02-08&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;10:07 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:52:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150400#M3799</guid>
      <dc:creator>gaminn</dc:creator>
      <dc:date>2020-10-29T08:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150401#M3800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I see&amp;nbsp;a bug in your code&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;#define SAMPLES 3&lt;/DIV&gt;&lt;DIV&gt;word samplesHistory[SAMPLES];&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;...&lt;/DIV&gt;&lt;DIV&gt;void interrupt VectorNumber_Vtpm1ch0 zeroCrossing(void) {&lt;BR /&gt;&amp;nbsp; samplesHistory[samplePosition] = TPM1C0V; // store timer value when input capture occurs&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; if(++samplePosition &amp;gt; SAMPLES) { // calculate next position in the samplesHistory array&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; samplePosition = 0;&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Max samplesHistory index is 2. Now consider you run your ISR with samplePosition=2. It will increment to 3 but won't reset to 0...&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Feb 2009 15:01:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150401#M3800</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2009-02-09T15:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150402#M3801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thanks, you are right, I'm stupid... So there must be another bugs, if you can see them, please tell me. Now, when&amp;nbsp;I fixed this bug (if(++samplePosition &amp;gt;= SAMPLES)......),&amp;nbsp;program runs correctly with TPM1 overlow interrupt disabled, but with&amp;nbsp; "TPM2CNT = 0;" line, it behaves in the same way.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Feb 2009 23:03:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150402#M3801</guid>
      <dc:creator>gaminn</dc:creator>
      <dc:date>2009-02-09T23:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150403#M3802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I have simplified the code, it should do what I want:&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;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */   void commutate(void) {  PTGD_PTGD7 ^= 1;  }void interrupt VectorNumber_Vtpm1ch0 zeroCrossing(void) {  TPM1SC = (unsigned char) (TPM1SC &amp;amp; 0b00000111);  TPM1CNT = 0;    TPM2MOD = (unsigned short) (TPM1C0V/2);  TPM2SC = (unsigned char) (0b01001000 | TPM1SC);  TPM2CNT = 0; // without this line it works  TPM1SC = (unsigned char) (TPM1SC | 0b00001000);    TPM1SC;  TPM1SC_TOF;  TPM1C0SC;  TPM1C0SC_CH0F = 0;  }void interrupt VectorNumber_Vtpm2ovf commutationTime(void) {  TPM2SC = 0b00000111;  TPM2CNT = 0;  commutate();  TPM2SC;  TPM2SC_TOF = 0;}void main(void) {  PTGDD_PTGDD7 = 1;    ICSC2_BDIV = 0; // bus clock /= 1 // TPM1CH0 will be input capture //    TPM1MOD = 0xFFFF;  TPM1C0SC = 0b01001100;  TPM1SC = 0b00001111;      EnableInterrupts; /* enable interrupts */  for(;;) {    __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;What is wrong here, does anybody know? I'm really confused.&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by gaminn on &lt;SPAN class="date_text"&gt;2009-02-10&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;04:34 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:52:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150403#M3802</guid>
      <dc:creator>gaminn</dc:creator>
      <dc:date>2020-10-29T08:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: MCF51QE128 timer module</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150404#M3803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Datasheet says that input capture can occure for rising, falling or any edge. My program is configured, that it should generate input capture interrupt&amp;nbsp;on any edge.&amp;nbsp;But my program works in the way that when TPM1CH0 pin is high,&amp;nbsp;CPU doesn't stop to generate interrupts.&amp;nbsp;The situation is the same, when interrupts should be generated on rising edge. On the other hand everything is ok when configured to generate interrupt for falling edge (CPU generates interrupt really at the moment of falling edge on TPM1CH0 pin).&amp;nbsp;What is wrong?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 23:40:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/MCF51QE128-timer-module/m-p/150404#M3803</guid>
      <dc:creator>gaminn</dc:creator>
      <dc:date>2009-02-11T23:40:13Z</dc:date>
    </item>
  </channel>
</rss>

