<?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 precise blocking timer in S32K3 in S32K</title>
    <link>https://community.nxp.com/t5/S32K/precise-blocking-timer-in-S32K3/m-p/1354976#M12434</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would like to implement a precise blocking timer that can also be set for a delay of 1us. I am using the code written for the S32K1 MCU and have transferred it to the S32K3 MCU. Unfortunately it does not work properly and I measured about 389us for 1ms (expected time).&lt;/P&gt;&lt;P&gt;Maybe I have chosen the wrong clock source (Core_CLK) or the code is 1:1 transferable for the S32K3.&lt;/P&gt;&lt;P&gt;If someone has a tip for this problem or maybe a better way to implement a blocking timer, that would be great.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#define WAIT_FOR_MUL4_CYCLES(cycles) \
  __asm( \
    "movs r0, %[cycles] \n"  \
    "0: \n"                  \
      "subs r0, r0, #4 \n"   \
      "nop \n\t"             \
    "bne 0b \n"              \
     :                       \
     : [cycles] "r" (cycles) \
     : "r0", "r1", "cc"      \
  )


void BCC_MCU_WaitMs(uint16_t delay)
{
    g_sysClk = Clock_Ip_GetClockFrequency(CORE_CLK);

    uint32_t cycles = (uint32_t) g_sysClk / 1000;

    /* Advance to next multiple of 4. Value 0x04U ensures that the number
     * is not zero. */
    cycles = (cycles &amp;amp; 0xFFFFFFFCU) | 0x04U;

    for (; delay &amp;gt; 0U; delay--) {
        BCC_WAIT_FOR_MUL4_CYCLES(cycles);
    }
}
  
int main(void){
    uint8 tggGPIO = 0u;
    while(1){
        Siul2_Dio_Ip_WritePin(	GPIO_BlINKY_PORT, GPIO_BlINKY_PIN, tggGPIO);
        tggGPIO ^= 0x01;
        WaitMs(1); // approx 389us
        //WaitMs(2); // approx 760us
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Oct 2021 12:30:41 GMT</pubDate>
    <dc:creator>JoDo</dc:creator>
    <dc:date>2021-10-13T12:30:41Z</dc:date>
    <item>
      <title>precise blocking timer in S32K3</title>
      <link>https://community.nxp.com/t5/S32K/precise-blocking-timer-in-S32K3/m-p/1354976#M12434</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I would like to implement a precise blocking timer that can also be set for a delay of 1us. I am using the code written for the S32K1 MCU and have transferred it to the S32K3 MCU. Unfortunately it does not work properly and I measured about 389us for 1ms (expected time).&lt;/P&gt;&lt;P&gt;Maybe I have chosen the wrong clock source (Core_CLK) or the code is 1:1 transferable for the S32K3.&lt;/P&gt;&lt;P&gt;If someone has a tip for this problem or maybe a better way to implement a blocking timer, that would be great.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#define WAIT_FOR_MUL4_CYCLES(cycles) \
  __asm( \
    "movs r0, %[cycles] \n"  \
    "0: \n"                  \
      "subs r0, r0, #4 \n"   \
      "nop \n\t"             \
    "bne 0b \n"              \
     :                       \
     : [cycles] "r" (cycles) \
     : "r0", "r1", "cc"      \
  )


void BCC_MCU_WaitMs(uint16_t delay)
{
    g_sysClk = Clock_Ip_GetClockFrequency(CORE_CLK);

    uint32_t cycles = (uint32_t) g_sysClk / 1000;

    /* Advance to next multiple of 4. Value 0x04U ensures that the number
     * is not zero. */
    cycles = (cycles &amp;amp; 0xFFFFFFFCU) | 0x04U;

    for (; delay &amp;gt; 0U; delay--) {
        BCC_WAIT_FOR_MUL4_CYCLES(cycles);
    }
}
  
int main(void){
    uint8 tggGPIO = 0u;
    while(1){
        Siul2_Dio_Ip_WritePin(	GPIO_BlINKY_PORT, GPIO_BlINKY_PIN, tggGPIO);
        tggGPIO ^= 0x01;
        WaitMs(1); // approx 389us
        //WaitMs(2); // approx 760us
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 12:30:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/precise-blocking-timer-in-S32K3/m-p/1354976#M12434</guid>
      <dc:creator>JoDo</dc:creator>
      <dc:date>2021-10-13T12:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: precise blocking timer in S32K3</title>
      <link>https://community.nxp.com/t5/S32K/precise-blocking-timer-in-S32K3/m-p/1356541#M12465</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/191027"&gt;@JoDo&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;The S32K3 has a different core.&lt;/P&gt;
&lt;P&gt;Why don't use Systick?&lt;/P&gt;
&lt;P&gt;You can use the OSIF RTD driver.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BR, Daniel&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 14:20:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/precise-blocking-timer-in-S32K3/m-p/1356541#M12465</guid>
      <dc:creator>danielmartynek</dc:creator>
      <dc:date>2021-10-15T14:20:26Z</dc:date>
    </item>
  </channel>
</rss>

