<?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 How do I set the TPM prescaler? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-I-set-the-TPM-prescaler/m-p/306464#M13045</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;I have been trying to flash an LED in a TPM interrupt at 5HZ using a 48MHZ MCGFLLCLK. I cannot seem to set the TPM0 prescaler to divide down the MCGFLLCLK. I'm clearly doing something wrong and maybe not figured out the TPM fully yet. &lt;/P&gt;&lt;P&gt;My code is below. Note I have not set the prescaler and TPM0_C0V value to the correct values for 5HZ operation yet. Any help or pointwers greatly appreciated, as its driving me mad.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7f0055; font-size: 10pt; text-decoration: underline;"&gt;&lt;STRONG&gt;int&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;STRONG&gt;timerInit&lt;/STRONG&gt;()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;NVIC_ICER = 1 &amp;lt;&amp;lt; (17%32);&lt;/P&gt;&lt;P&gt;SIM_SOPT2 &amp;amp;= ~(SIM_SOPT2_TPMSRC_MASK);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// MCGFLLCLK is source&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; SIM_SCGC6 = SIM_SCGC6_TPM0_MASK;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// enable clock for Uart0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_SC = 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_SC = TPM_SC_PS(7);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_MOD = 0xFFFF;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_CNT = 0;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;TPM0_SC = TPM_SC_TOIE_MASK|TPM_SC_CMOD(1); &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// NB Default to 'up-counting' mode.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;TPM0_C0SC = TPM_CnSC_MSB_MASK| TPM_CnSC_ELSB_MASK; &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// MSB:MSA 1:0 Edge Aligned mode (A defaults to 0)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;//TPM0_C0SC |= TPM_CnSC_CHIE_MASK; &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;//channel interrupt enable&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_C0V = 0x00;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;NVIC_ICPR |= 1 &amp;lt;&amp;lt; (17%32);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7f0055; font-size: 10pt;"&gt;&lt;STRONG&gt;void&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;STRONG&gt;FTM0_IRQHandler&lt;/STRONG&gt; (&lt;/SPAN&gt;&lt;STRONG style=": ; color: #7f0055; font-size: 10pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tick = TPM0_CNT;&lt;/P&gt;&lt;P&gt;TPM0_SC |= TPM_SC_TOF_MASK;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;TPM0_C0V = 0x1FFF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_C0SC |= TPM_STATUS_CH0F_MASK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NegLED();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 May 2014 15:17:18 GMT</pubDate>
    <dc:creator>clivepalmer</dc:creator>
    <dc:date>2014-05-27T15:17:18Z</dc:date>
    <item>
      <title>How do I set the TPM prescaler?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-I-set-the-TPM-prescaler/m-p/306464#M13045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;I have been trying to flash an LED in a TPM interrupt at 5HZ using a 48MHZ MCGFLLCLK. I cannot seem to set the TPM0 prescaler to divide down the MCGFLLCLK. I'm clearly doing something wrong and maybe not figured out the TPM fully yet. &lt;/P&gt;&lt;P&gt;My code is below. Note I have not set the prescaler and TPM0_C0V value to the correct values for 5HZ operation yet. Any help or pointwers greatly appreciated, as its driving me mad.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7f0055; font-size: 10pt; text-decoration: underline;"&gt;&lt;STRONG&gt;int&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;STRONG&gt;timerInit&lt;/STRONG&gt;()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;NVIC_ICER = 1 &amp;lt;&amp;lt; (17%32);&lt;/P&gt;&lt;P&gt;SIM_SOPT2 &amp;amp;= ~(SIM_SOPT2_TPMSRC_MASK);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// MCGFLLCLK is source&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; SIM_SCGC6 = SIM_SCGC6_TPM0_MASK;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// enable clock for Uart0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_SC = 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_SC = TPM_SC_PS(7);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_MOD = 0xFFFF;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_CNT = 0;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;TPM0_SC = TPM_SC_TOIE_MASK|TPM_SC_CMOD(1); &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// NB Default to 'up-counting' mode.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;TPM0_C0SC = TPM_CnSC_MSB_MASK| TPM_CnSC_ELSB_MASK; &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;// MSB:MSA 1:0 Edge Aligned mode (A defaults to 0)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;//TPM0_C0SC |= TPM_CnSC_CHIE_MASK; &lt;/SPAN&gt;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;//channel interrupt enable&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_C0V = 0x00;&lt;SPAN style="color: #3f7f5f; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;NVIC_ICPR |= 1 &amp;lt;&amp;lt; (17%32);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #7f0055; font-size: 10pt;"&gt;&lt;STRONG&gt;void&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;STRONG&gt;FTM0_IRQHandler&lt;/STRONG&gt; (&lt;/SPAN&gt;&lt;STRONG style=": ; color: #7f0055; font-size: 10pt;"&gt;void&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tick = TPM0_CNT;&lt;/P&gt;&lt;P&gt;TPM0_SC |= TPM_SC_TOF_MASK;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;TPM0_C0V = 0x1FFF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TPM0_C0SC |= TPM_STATUS_CH0F_MASK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NegLED();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 May 2014 15:17:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-I-set-the-TPM-prescaler/m-p/306464#M13045</guid>
      <dc:creator>clivepalmer</dc:creator>
      <dc:date>2014-05-27T15:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I set the TPM prescaler?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-I-set-the-TPM-prescaler/m-p/306465#M13046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Clive&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think that you are overwriting the prescaler setting which you first set to 7 [&lt;STRONG&gt;TPM0_SC = TPM_SC_PS(7);&lt;/STRONG&gt;] and later set back to 0 with &lt;SPAN style="font-size: 10pt;"&gt;&lt;STRONG&gt;TPM0_SC = TPM_SC_TOIE_MASK|TPM_SC_CMOD(1);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Also note that you won't be able to get a 5Hz interrupt (200ms) since the longst delay that you can set from 48MHz clock is about 174ms (prescaler at max = 7 and divide at max 0xffff) .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Mark&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 May 2014 17:51:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-I-set-the-TPM-prescaler/m-p/306465#M13046</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2014-05-27T17:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I set the TPM prescaler?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-I-set-the-TPM-prescaler/m-p/306466#M13047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Mark.&amp;nbsp; What a plonker I am. Yes I missed a '|' .A case of not seeing the woods for the trees! That was indeed the problem. &lt;/P&gt;&lt;P&gt;Yes I realise that wont give me the 5Hz that I ideally would like.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 06:02:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/How-do-I-set-the-TPM-prescaler/m-p/306466#M13047</guid>
      <dc:creator>clivepalmer</dc:creator>
      <dc:date>2014-05-28T06:02:58Z</dc:date>
    </item>
  </channel>
</rss>

