<?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>8-bit MicrocontrollersのトピックRe: help with coding in c a timer</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142045#M6115</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I don't have the actual chip in front of me, so I can only confirm my answer with the simulator...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The reason this is not working for you is because you turned the timer on before you configured it and - at least in the simulator - the configuration can not be changed after the timer is already running.&amp;nbsp; So the problem lies only with the ordering of your code.&amp;nbsp; The timer is enabled as soon as you define the timer's clock source.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This works in the simulator:&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */void main(void) {  EnableInterrupts; /* enable interrupts */// SET DIVIDER TO DIVIDE BY 32  TPM1SC_PS0 = 1; TPM1SC_PS1 = 0; TPM1SC_PS2 = 1;  //TPM1MOD = 112;  TPM1MOD = 0; //CENTER ALIGNED CLOCKS //TIMER OVERFLOW INTERRUPT ENABLED  TPM1SC_TOIE = 1; TPM1SC_CPWMS = 1; //TPM1SC = 0x60;   // CLOCKS SET TO BUS RATE CLOCK TPM1SC_CLKSA = 1;                     // &amp;lt;---- This line moved to the end TPM1SC_CLKSB = 0;  for(;;) {    __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */  /* please make sure that you never leave this function */}interrupt 8 void ProcessMyInterrupt(void){//  TPM1SC;  TPM1SC_TOF = 0; }&lt;/PRE&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 08:42:24 GMT</pubDate>
    <dc:creator>rhinoceroshead</dc:creator>
    <dc:date>2020-10-29T08:42:24Z</dc:date>
    <item>
      <title>help with coding in c a timer</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142044#M6114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I have generated the following test code to use with the simulator debugger.&amp;nbsp; I am utilizing a s08gt16 processor.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I am unable to get the interrupt to be generated.&amp;nbsp; Can one of you help me with where I am going wrong?&amp;nbsp; The frequency of the interrupt at this point is not important as that can be changed with the prescaler.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thanks in advance,&lt;/DIV&gt;&lt;DIV&gt;Bud&lt;/DIV&gt;&lt;DIV&gt;// SET DIVIDER TO DIVIDE BY 32&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;TPM1SC_PS0 = 1;&lt;BR /&gt;&amp;nbsp;TPM1SC_PS1 = 0;&lt;BR /&gt;&amp;nbsp;TPM1SC_PS2 = 1;&lt;BR /&gt;&amp;nbsp;// CLOCKS SET TO BUS RATE CLOCK&lt;BR /&gt;&amp;nbsp;TPM1SC_CLKSA = 1;&lt;BR /&gt;&amp;nbsp;TPM1SC_CLKSB = 0;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;//TPM1MOD = 112;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;TPM1MOD = 0;&lt;BR /&gt;&amp;nbsp;//CENTER ALIGNED CLOCKS&lt;BR /&gt;&amp;nbsp;//TIMER OVERFLOW INTERRUPT ENABLED&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;TPM1SC_TOIE = 1;&lt;BR /&gt;&amp;nbsp;TPM1SC_CPWMS = 1;&lt;BR /&gt;&amp;nbsp;//TPM1SC = 0x60;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp; for(;&lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif"&gt;&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/A&gt; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; __RESET_WATCHDOG(); /* feeds the dog */&lt;BR /&gt;&amp;nbsp; } /* loop forever */&lt;BR /&gt;&amp;nbsp; /* please make sure that you never leave this function */&lt;BR /&gt;}&lt;BR /&gt;interrupt 8 void ProcessMyInterrupt(void){&lt;BR /&gt;//&amp;nbsp; TPM1SC;&lt;BR /&gt;&amp;nbsp; TPM1SC_TOF = 0;&lt;BR /&gt;}&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jul 2006 08:59:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142044#M6114</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2006-07-05T08:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: help with coding in c a timer</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142045#M6115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I don't have the actual chip in front of me, so I can only confirm my answer with the simulator...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The reason this is not working for you is because you turned the timer on before you configured it and - at least in the simulator - the configuration can not be changed after the timer is already running.&amp;nbsp; So the problem lies only with the ordering of your code.&amp;nbsp; The timer is enabled as soon as you define the timer's clock source.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This works in the simulator:&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;#include &amp;lt;hidef.h&amp;gt; /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */void main(void) {  EnableInterrupts; /* enable interrupts */// SET DIVIDER TO DIVIDE BY 32  TPM1SC_PS0 = 1; TPM1SC_PS1 = 0; TPM1SC_PS2 = 1;  //TPM1MOD = 112;  TPM1MOD = 0; //CENTER ALIGNED CLOCKS //TIMER OVERFLOW INTERRUPT ENABLED  TPM1SC_TOIE = 1; TPM1SC_CPWMS = 1; //TPM1SC = 0x60;   // CLOCKS SET TO BUS RATE CLOCK TPM1SC_CLKSA = 1;                     // &amp;lt;---- This line moved to the end TPM1SC_CLKSB = 0;  for(;;) {    __RESET_WATCHDOG(); /* feeds the dog */  } /* loop forever */  /* please make sure that you never leave this function */}interrupt 8 void ProcessMyInterrupt(void){//  TPM1SC;  TPM1SC_TOF = 0; }&lt;/PRE&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:42:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142045#M6115</guid>
      <dc:creator>rhinoceroshead</dc:creator>
      <dc:date>2020-10-29T08:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: help with coding in c a timer</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142046#M6116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thanks, somewhere in the documentation I must have missed the ordering sequence of the code.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Bud&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jul 2006 17:41:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142046#M6116</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2006-07-05T17:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: help with coding in c a timer</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142047#M6117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I don't think you missed anything - I looked in the datasheet and saw nothing requiring the clocks to be selected last.&amp;nbsp; I suspect that usually you would write that configuration register all at once instead of one bit at a time so you would never run into that.&amp;nbsp; For all I know, this is just a peculiarity of the simulator and the problem might never occur on the real chip.&amp;nbsp; Maybe someone here can test it on the real thing and get back to us.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jul 2006 01:13:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/help-with-coding-in-c-a-timer/m-p/142047#M6117</guid>
      <dc:creator>rhinoceroshead</dc:creator>
      <dc:date>2006-07-06T01:13:13Z</dc:date>
    </item>
  </channel>
</rss>

