<?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>S12 / MagniV MicrocontrollersのトピックCRGFLG register not clearing help!</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/CRGFLG-register-not-clearing-help/m-p/658329#M13902</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;I'm using a FreeScale 9S12C micro controller and am coding in Code Warrior. I'm trying to create a SEQ detector for Sequence 10011. When I do a simulation the program gets stuck in the function "DelayGate", everything else appears ok. It seems that the last bit in the CRGFLG register is never getting set like it's supposed to. I believe it's supposed to get set at the end of every real time clock cycle. I set RTICTL = 0b01000000, so the real time clock should have a period of 1.024 ms. So my expected behavior is that the program should stay in the DelayGate for approximately 1.024 ms and than exit, but the program stays in delay gate for ever and never exits. It appears that the last bit in CRGFLG never gets set for some reason, and I'm not sure why. Thanks for any help anyone can provide me! Here's my code. I'm using a 8 MHz crystal.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Constants&lt;BR /&gt;#define CRYSTAL_CLOCK_FREQ 8000000L //set the clock to 8 MHz?&lt;BR /&gt;#define LED_COUNT_MAX 488 //(500 ms)/(1.024 ms) about 488&lt;BR /&gt;// Includes&lt;BR /&gt;#include &amp;lt;hidef.h&amp;gt; /* common defines &amp;amp; macros */&lt;BR /&gt;#include "derivative.h" /* derivative-specific */&lt;BR /&gt;// Prototypes&lt;BR /&gt;void SysInit(void);&lt;BR /&gt;void UpdateLED(void);&lt;BR /&gt;int input;&lt;BR /&gt;int state;&lt;BR /&gt;int nn = 5;&lt;BR /&gt;int value;&lt;BR /&gt;void Delay(int nn);&lt;BR /&gt;int UpdateStatetask(int input, int state);&lt;BR /&gt;void DelayGate(void);&lt;BR /&gt;int BeepFlag = 0;&lt;BR /&gt;int done = 0;&lt;BR /&gt;#endif&lt;BR /&gt;/*****************************************************&lt;BR /&gt;* main - Program main&lt;BR /&gt;****************************************************/&lt;BR /&gt;void main(void){&lt;BR /&gt; COPCTL = 0x00; // Disable the COP timer&lt;BR /&gt; RTICTL = 0b01000000; //8 MHz crystal, period of real time clock is 1.024 ms&lt;BR /&gt; PTT = 0x00; // initally all logical zero&lt;BR /&gt; DDRT = 0b11111100; // PT0 "0" input&lt;BR /&gt; //PT1 "1" input&lt;BR /&gt; //PT2 SEQ state 1 indication&lt;BR /&gt; // PT3 SEQ state 2 indication&lt;BR /&gt; // PT4 SEQ state 3 indicaiton&lt;BR /&gt; // PT5 SEQ state 4 indication&lt;BR /&gt; // PT6 SEQ detection&lt;BR /&gt; // PT7 LED Clock&lt;BR /&gt; PERT = 0b11111111; // enable pulling on all port T&lt;BR /&gt; PPST = 0b11111111; // pull-down to ground all port T&lt;BR /&gt; CLKSEL = 0x00;&lt;BR /&gt; PLLCTL = 0x00;&lt;BR /&gt; CRGINT = 0b10000000;&lt;BR /&gt; while (1){&lt;BR /&gt; UpdateLED();&lt;BR /&gt; DelayGate();&lt;BR /&gt; } &lt;BR /&gt;}&lt;BR /&gt;/**************************************************&lt;BR /&gt;* UpdateLED()&lt;BR /&gt;* When the LED count runs out, toggle and beep&lt;BR /&gt;*************************************************/&lt;BR /&gt;void UpdateLED(void){&lt;BR /&gt; static int state = 0;&lt;BR /&gt; int input;&lt;BR /&gt; int LedCount = LED_COUNT_MAX; //488*1.024 ms = 0.4997 s&lt;BR /&gt; if (--LedCount == 0){ //decrement LED count&lt;BR /&gt; LedCount = LED_COUNT_MAX;&lt;BR /&gt; PTT = 0b10000000; //turn on LED clock&lt;BR /&gt; }&lt;BR /&gt; if (PTT &amp;amp; 0x01 == 1){ //bitwise and, checking for clock LED&lt;BR /&gt; if(PTT &amp;amp; 0b00000001){ //"0" input&lt;BR /&gt; input = 0;&lt;BR /&gt; }&lt;BR /&gt; if(PTT &amp;amp; 0b00000010){ //"1" input&lt;BR /&gt; input = 1;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; UpdateStatetask(input,state);&lt;BR /&gt;}&lt;BR /&gt;/**************************************************&lt;BR /&gt;* UpdateStatetask()&lt;BR /&gt;*************************************************/&lt;BR /&gt;int UpdateStatetask(input, state){ &lt;BR /&gt; switch(state){&lt;BR /&gt; case 0:&lt;BR /&gt; PTT = 0b00000000; //state 0 no LEDs should light up&lt;BR /&gt; if (input == 0){ //SEQ = 10011&lt;BR /&gt; state = 0; //if "0" is entered at state zero stay at state zero&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){&lt;BR /&gt; state = 1; //if "1" is entered at state zero go to state 1&lt;BR /&gt; } &lt;BR /&gt; break;&lt;BR /&gt; case 1:&lt;BR /&gt; PTT = 0b00000100; //turn on LED indicating state 1&lt;BR /&gt; if (input == 0){ //if "0" is entered at state one go to state two&lt;BR /&gt; state = 2;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){ //if "1" is entered at state one stay at state one &lt;BR /&gt; state = 1;&lt;BR /&gt; }&lt;BR /&gt; break;&lt;BR /&gt; case 2:&lt;BR /&gt; PTT ^= 0b00001100; //state 2 indication turn on 2 LED&lt;BR /&gt; if (input == 0){ //if "0" is entered at state two go to state three&lt;BR /&gt; state = 3;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){ //if "1" is entered at state two go to state one&lt;BR /&gt; state = 1;&lt;BR /&gt; }&lt;BR /&gt; break;&lt;BR /&gt; case 3:&lt;BR /&gt; PTT = 0b00011100; //state 3 indication turn on 3 LED&lt;BR /&gt; if (input == 0){ //if "0" is entered at state three go to state zero&lt;BR /&gt; state = 0;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){ //if "1" is entered at state three go to state four&lt;BR /&gt; state = 4;&lt;BR /&gt; }&lt;BR /&gt; break; &lt;BR /&gt; case 4:&lt;BR /&gt; PTT = 0b00111100; //state 4 indication turn on 4 LED&lt;BR /&gt; if (input == 0){ //if "0" is entered at state four go to state 2&lt;BR /&gt; state = 2;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){//if "1" is entered at state four go to state 1&lt;BR /&gt; PTT = 0b01111100; //SEQ detection turn on 5 LED&lt;BR /&gt; state = 1;&lt;BR /&gt; }&lt;BR /&gt; break;&lt;BR /&gt; default:&lt;BR /&gt; state = 0;&lt;BR /&gt; break;&lt;BR /&gt; }&lt;BR /&gt; return state;&lt;BR /&gt;}&lt;BR /&gt;/**************************************************&lt;BR /&gt;* DelayGate&lt;BR /&gt;* Wait for timeout, then restart the RTI clock&lt;BR /&gt;*************************************************/&lt;BR /&gt;void DelayGate(void){&lt;BR /&gt; while ( (CRGFLG &amp;amp; 0x80) == 0){&lt;BR /&gt; ;&lt;BR /&gt; }&lt;BR /&gt; CRGFLG = 0x80;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE style="border: 0px; font-size: 13px;"&gt;&lt;/CODE&gt;When I compile the only warnings I get is that 1) result of function call is ignored on this line "UpdateStatetask(input,state)" 2) This is the old style of function call here on this line "int UpdateStatetask(input, state){ "&lt;/P&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;These warnings shouldn't cause the problem I'm having. Thanks for any help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Mar 2017 21:24:04 GMT</pubDate>
    <dc:creator>dylanhammerman</dc:creator>
    <dc:date>2017-03-16T21:24:04Z</dc:date>
    <item>
      <title>CRGFLG register not clearing help!</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/CRGFLG-register-not-clearing-help/m-p/658329#M13902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;I'm using a FreeScale 9S12C micro controller and am coding in Code Warrior. I'm trying to create a SEQ detector for Sequence 10011. When I do a simulation the program gets stuck in the function "DelayGate", everything else appears ok. It seems that the last bit in the CRGFLG register is never getting set like it's supposed to. I believe it's supposed to get set at the end of every real time clock cycle. I set RTICTL = 0b01000000, so the real time clock should have a period of 1.024 ms. So my expected behavior is that the program should stay in the DelayGate for approximately 1.024 ms and than exit, but the program stays in delay gate for ever and never exits. It appears that the last bit in CRGFLG never gets set for some reason, and I'm not sure why. Thanks for any help anyone can provide me! Here's my code. I'm using a 8 MHz crystal.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Constants&lt;BR /&gt;#define CRYSTAL_CLOCK_FREQ 8000000L //set the clock to 8 MHz?&lt;BR /&gt;#define LED_COUNT_MAX 488 //(500 ms)/(1.024 ms) about 488&lt;BR /&gt;// Includes&lt;BR /&gt;#include &amp;lt;hidef.h&amp;gt; /* common defines &amp;amp; macros */&lt;BR /&gt;#include "derivative.h" /* derivative-specific */&lt;BR /&gt;// Prototypes&lt;BR /&gt;void SysInit(void);&lt;BR /&gt;void UpdateLED(void);&lt;BR /&gt;int input;&lt;BR /&gt;int state;&lt;BR /&gt;int nn = 5;&lt;BR /&gt;int value;&lt;BR /&gt;void Delay(int nn);&lt;BR /&gt;int UpdateStatetask(int input, int state);&lt;BR /&gt;void DelayGate(void);&lt;BR /&gt;int BeepFlag = 0;&lt;BR /&gt;int done = 0;&lt;BR /&gt;#endif&lt;BR /&gt;/*****************************************************&lt;BR /&gt;* main - Program main&lt;BR /&gt;****************************************************/&lt;BR /&gt;void main(void){&lt;BR /&gt; COPCTL = 0x00; // Disable the COP timer&lt;BR /&gt; RTICTL = 0b01000000; //8 MHz crystal, period of real time clock is 1.024 ms&lt;BR /&gt; PTT = 0x00; // initally all logical zero&lt;BR /&gt; DDRT = 0b11111100; // PT0 "0" input&lt;BR /&gt; //PT1 "1" input&lt;BR /&gt; //PT2 SEQ state 1 indication&lt;BR /&gt; // PT3 SEQ state 2 indication&lt;BR /&gt; // PT4 SEQ state 3 indicaiton&lt;BR /&gt; // PT5 SEQ state 4 indication&lt;BR /&gt; // PT6 SEQ detection&lt;BR /&gt; // PT7 LED Clock&lt;BR /&gt; PERT = 0b11111111; // enable pulling on all port T&lt;BR /&gt; PPST = 0b11111111; // pull-down to ground all port T&lt;BR /&gt; CLKSEL = 0x00;&lt;BR /&gt; PLLCTL = 0x00;&lt;BR /&gt; CRGINT = 0b10000000;&lt;BR /&gt; while (1){&lt;BR /&gt; UpdateLED();&lt;BR /&gt; DelayGate();&lt;BR /&gt; } &lt;BR /&gt;}&lt;BR /&gt;/**************************************************&lt;BR /&gt;* UpdateLED()&lt;BR /&gt;* When the LED count runs out, toggle and beep&lt;BR /&gt;*************************************************/&lt;BR /&gt;void UpdateLED(void){&lt;BR /&gt; static int state = 0;&lt;BR /&gt; int input;&lt;BR /&gt; int LedCount = LED_COUNT_MAX; //488*1.024 ms = 0.4997 s&lt;BR /&gt; if (--LedCount == 0){ //decrement LED count&lt;BR /&gt; LedCount = LED_COUNT_MAX;&lt;BR /&gt; PTT = 0b10000000; //turn on LED clock&lt;BR /&gt; }&lt;BR /&gt; if (PTT &amp;amp; 0x01 == 1){ //bitwise and, checking for clock LED&lt;BR /&gt; if(PTT &amp;amp; 0b00000001){ //"0" input&lt;BR /&gt; input = 0;&lt;BR /&gt; }&lt;BR /&gt; if(PTT &amp;amp; 0b00000010){ //"1" input&lt;BR /&gt; input = 1;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; UpdateStatetask(input,state);&lt;BR /&gt;}&lt;BR /&gt;/**************************************************&lt;BR /&gt;* UpdateStatetask()&lt;BR /&gt;*************************************************/&lt;BR /&gt;int UpdateStatetask(input, state){ &lt;BR /&gt; switch(state){&lt;BR /&gt; case 0:&lt;BR /&gt; PTT = 0b00000000; //state 0 no LEDs should light up&lt;BR /&gt; if (input == 0){ //SEQ = 10011&lt;BR /&gt; state = 0; //if "0" is entered at state zero stay at state zero&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){&lt;BR /&gt; state = 1; //if "1" is entered at state zero go to state 1&lt;BR /&gt; } &lt;BR /&gt; break;&lt;BR /&gt; case 1:&lt;BR /&gt; PTT = 0b00000100; //turn on LED indicating state 1&lt;BR /&gt; if (input == 0){ //if "0" is entered at state one go to state two&lt;BR /&gt; state = 2;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){ //if "1" is entered at state one stay at state one &lt;BR /&gt; state = 1;&lt;BR /&gt; }&lt;BR /&gt; break;&lt;BR /&gt; case 2:&lt;BR /&gt; PTT ^= 0b00001100; //state 2 indication turn on 2 LED&lt;BR /&gt; if (input == 0){ //if "0" is entered at state two go to state three&lt;BR /&gt; state = 3;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){ //if "1" is entered at state two go to state one&lt;BR /&gt; state = 1;&lt;BR /&gt; }&lt;BR /&gt; break;&lt;BR /&gt; case 3:&lt;BR /&gt; PTT = 0b00011100; //state 3 indication turn on 3 LED&lt;BR /&gt; if (input == 0){ //if "0" is entered at state three go to state zero&lt;BR /&gt; state = 0;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){ //if "1" is entered at state three go to state four&lt;BR /&gt; state = 4;&lt;BR /&gt; }&lt;BR /&gt; break; &lt;BR /&gt; case 4:&lt;BR /&gt; PTT = 0b00111100; //state 4 indication turn on 4 LED&lt;BR /&gt; if (input == 0){ //if "0" is entered at state four go to state 2&lt;BR /&gt; state = 2;&lt;BR /&gt; } &lt;BR /&gt; else if(input == 1){//if "1" is entered at state four go to state 1&lt;BR /&gt; PTT = 0b01111100; //SEQ detection turn on 5 LED&lt;BR /&gt; state = 1;&lt;BR /&gt; }&lt;BR /&gt; break;&lt;BR /&gt; default:&lt;BR /&gt; state = 0;&lt;BR /&gt; break;&lt;BR /&gt; }&lt;BR /&gt; return state;&lt;BR /&gt;}&lt;BR /&gt;/**************************************************&lt;BR /&gt;* DelayGate&lt;BR /&gt;* Wait for timeout, then restart the RTI clock&lt;BR /&gt;*************************************************/&lt;BR /&gt;void DelayGate(void){&lt;BR /&gt; while ( (CRGFLG &amp;amp; 0x80) == 0){&lt;BR /&gt; ;&lt;BR /&gt; }&lt;BR /&gt; CRGFLG = 0x80;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE style="border: 0px; font-size: 13px;"&gt;&lt;/CODE&gt;When I compile the only warnings I get is that 1) result of function call is ignored on this line "UpdateStatetask(input,state)" 2) This is the old style of function call here on this line "int UpdateStatetask(input, state){ "&lt;/P&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;These warnings shouldn't cause the problem I'm having. Thanks for any help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Mar 2017 21:24:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/CRGFLG-register-not-clearing-help/m-p/658329#M13902</guid>
      <dc:creator>dylanhammerman</dc:creator>
      <dc:date>2017-03-16T21:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: CRGFLG register not clearing help!</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/CRGFLG-register-not-clearing-help/m-p/658330#M13903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dylanhammerman,&lt;/P&gt;&lt;P&gt;RTI is real time interrupt.&lt;/P&gt;&lt;P&gt;I am afraid that it cannot work as you expected. The RTI is enabled/disabled by RTIE bit.&lt;/P&gt;&lt;P&gt;So, you should create RTI interrupt routine and service your delay by some user flags.&lt;/P&gt;&lt;P&gt;The other option is using a different module like TIM timer for such purpose.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;BR /&gt;Radek&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Mar 2017 14:25:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/CRGFLG-register-not-clearing-help/m-p/658330#M13903</guid>
      <dc:creator>RadekS</dc:creator>
      <dc:date>2017-03-27T14:25:41Z</dc:date>
    </item>
  </channel>
</rss>

