<?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 K64 driver for standard PWM always resets start point in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64-driver-for-standard-PWM-always-resets-start-point/m-p/1172998#M58608</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a very very simple requirement but just couldn't seem to find the answer in a reasonable amount of time.&lt;/P&gt;&lt;P&gt;I am using MCUXpresso and the K64 baremetal C drivers supplied. This job is super simple, I just have two PWM's on FTM0.I just want 100Hz PWM with varied high time, super simple motor controller application. For some reason the gap between high pulses varies when i update the PWM using the driver like this instead of just changing the hi time it seems to "start agian" or something and the low time increases between pulses.&lt;/P&gt;&lt;P&gt;I read the reference manual and figered i should set it like this:&lt;/P&gt;&lt;P&gt;//SETUP&lt;/P&gt;&lt;P&gt;ftm_config_t ftmInfo;&lt;/P&gt;&lt;P&gt;ftm_chnl_pwm_signal_param_t ftmParam[2];&lt;/P&gt;&lt;P&gt;PORT_SetPinMux(RC1_M_PORT, RC1_M_PIN, RC1_M_ALT);&lt;BR /&gt;PORT_SetPinMux(RC2_M_PORT, RC2_M_PIN, RC2_M_ALT);&lt;/P&gt;&lt;P&gt;ftmParam[0].chnlNumber = (ftm_chnl_t)RC1CH_PWM;&lt;BR /&gt;ftmParam[0].level = kFTM_LowTrue;&lt;BR /&gt;ftmParam[0].dutyCyclePercent = 0U;&lt;BR /&gt;ftmParam[0].firstEdgeDelayPercent = 0U;&lt;BR /&gt;ftmParam[0].enableDeadtime = false;&lt;/P&gt;&lt;P&gt;ftmParam[1].chnlNumber = (ftm_chnl_t)RC2CH_PWM;&lt;BR /&gt;ftmParam[1].level = kFTM_LowTrue;&lt;BR /&gt;ftmParam[1].dutyCyclePercent = 0U;&lt;BR /&gt;ftmParam[1].firstEdgeDelayPercent = 0U;&lt;BR /&gt;ftmParam[1].enableDeadtime = false;&lt;/P&gt;&lt;P&gt;FTM_GetDefaultConfig(&amp;amp;ftmInfo);&lt;BR /&gt;ftmInfo.prescale = kFTM_Prescale_Divide_16;&lt;BR /&gt;ftmInfo.pwmSyncMode = (uint32_t)kFTM_SoftwareTrigger;&lt;/P&gt;&lt;P&gt;//I thought this flag hsould tell it to update the PWM when it clocks back over to min and i should get my perfect 2XKhz PWM with varied "high time"&lt;/P&gt;&lt;P&gt;ftmInfo.reloadPoints = kFTM_CntMin;&lt;BR /&gt;FTM_Init(FTM0, &amp;amp;ftmInfo);&lt;/P&gt;&lt;P&gt;if(FTM_SetupPwm(FTM0, ftmParam, 2U, kFTM_EdgeAlignedPwm, 100U, TPM_SOURCE_CLOCK) != kStatus_Success)&lt;BR /&gt;{&lt;BR /&gt;while(1);&amp;nbsp; //Stop for debug&lt;BR /&gt;}&lt;BR /&gt;FTM_StartTimer(FTM0, kFTM_SystemClock);&lt;/P&gt;&lt;P&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC1CH_PWM, 0);&lt;BR /&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC2CH_PWM, 0);&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;for(;;)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;//software to do things to the PWM values&lt;/P&gt;&lt;P&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC1CH_PWM, new_HighTimePulseValue);&lt;/P&gt;&lt;P&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC2CH_PWM, new_LowTimePUlseValue);&lt;BR /&gt;FTM_SetSoftwareTrigger(FTM0, true);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;//I dont want to use a percentage, i want exact numbers for my PWM, so I just made this function which does the same as the drvier&amp;nbsp;FTM_UpdatePwmDutycycle(); function&lt;/P&gt;&lt;P&gt;void FTM_SetDutyCycle(FTM_Type *base, ftm_chnl_t chnlNumber, uint16_t dutyCycle)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;base-&amp;gt;CONTROLS[chnlNumber].CnV = dutyCycle;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;I just want exactly 100Hz PWM with my custom high time...&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2020 09:09:20 GMT</pubDate>
    <dc:creator>CarlFST60L</dc:creator>
    <dc:date>2020-10-26T09:09:20Z</dc:date>
    <item>
      <title>K64 driver for standard PWM always resets start point</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64-driver-for-standard-PWM-always-resets-start-point/m-p/1172998#M58608</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a very very simple requirement but just couldn't seem to find the answer in a reasonable amount of time.&lt;/P&gt;&lt;P&gt;I am using MCUXpresso and the K64 baremetal C drivers supplied. This job is super simple, I just have two PWM's on FTM0.I just want 100Hz PWM with varied high time, super simple motor controller application. For some reason the gap between high pulses varies when i update the PWM using the driver like this instead of just changing the hi time it seems to "start agian" or something and the low time increases between pulses.&lt;/P&gt;&lt;P&gt;I read the reference manual and figered i should set it like this:&lt;/P&gt;&lt;P&gt;//SETUP&lt;/P&gt;&lt;P&gt;ftm_config_t ftmInfo;&lt;/P&gt;&lt;P&gt;ftm_chnl_pwm_signal_param_t ftmParam[2];&lt;/P&gt;&lt;P&gt;PORT_SetPinMux(RC1_M_PORT, RC1_M_PIN, RC1_M_ALT);&lt;BR /&gt;PORT_SetPinMux(RC2_M_PORT, RC2_M_PIN, RC2_M_ALT);&lt;/P&gt;&lt;P&gt;ftmParam[0].chnlNumber = (ftm_chnl_t)RC1CH_PWM;&lt;BR /&gt;ftmParam[0].level = kFTM_LowTrue;&lt;BR /&gt;ftmParam[0].dutyCyclePercent = 0U;&lt;BR /&gt;ftmParam[0].firstEdgeDelayPercent = 0U;&lt;BR /&gt;ftmParam[0].enableDeadtime = false;&lt;/P&gt;&lt;P&gt;ftmParam[1].chnlNumber = (ftm_chnl_t)RC2CH_PWM;&lt;BR /&gt;ftmParam[1].level = kFTM_LowTrue;&lt;BR /&gt;ftmParam[1].dutyCyclePercent = 0U;&lt;BR /&gt;ftmParam[1].firstEdgeDelayPercent = 0U;&lt;BR /&gt;ftmParam[1].enableDeadtime = false;&lt;/P&gt;&lt;P&gt;FTM_GetDefaultConfig(&amp;amp;ftmInfo);&lt;BR /&gt;ftmInfo.prescale = kFTM_Prescale_Divide_16;&lt;BR /&gt;ftmInfo.pwmSyncMode = (uint32_t)kFTM_SoftwareTrigger;&lt;/P&gt;&lt;P&gt;//I thought this flag hsould tell it to update the PWM when it clocks back over to min and i should get my perfect 2XKhz PWM with varied "high time"&lt;/P&gt;&lt;P&gt;ftmInfo.reloadPoints = kFTM_CntMin;&lt;BR /&gt;FTM_Init(FTM0, &amp;amp;ftmInfo);&lt;/P&gt;&lt;P&gt;if(FTM_SetupPwm(FTM0, ftmParam, 2U, kFTM_EdgeAlignedPwm, 100U, TPM_SOURCE_CLOCK) != kStatus_Success)&lt;BR /&gt;{&lt;BR /&gt;while(1);&amp;nbsp; //Stop for debug&lt;BR /&gt;}&lt;BR /&gt;FTM_StartTimer(FTM0, kFTM_SystemClock);&lt;/P&gt;&lt;P&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC1CH_PWM, 0);&lt;BR /&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC2CH_PWM, 0);&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;for(;;)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;//software to do things to the PWM values&lt;/P&gt;&lt;P&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC1CH_PWM, new_HighTimePulseValue);&lt;/P&gt;&lt;P&gt;FTM_SetDutyCycle(FTM0, (ftm_chnl_t)RC2CH_PWM, new_LowTimePUlseValue);&lt;BR /&gt;FTM_SetSoftwareTrigger(FTM0, true);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;//I dont want to use a percentage, i want exact numbers for my PWM, so I just made this function which does the same as the drvier&amp;nbsp;FTM_UpdatePwmDutycycle(); function&lt;/P&gt;&lt;P&gt;void FTM_SetDutyCycle(FTM_Type *base, ftm_chnl_t chnlNumber, uint16_t dutyCycle)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;base-&amp;gt;CONTROLS[chnlNumber].CnV = dutyCycle;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;I just want exactly 100Hz PWM with my custom high time...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 09:09:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64-driver-for-standard-PWM-always-resets-start-point/m-p/1172998#M58608</guid>
      <dc:creator>CarlFST60L</dc:creator>
      <dc:date>2020-10-26T09:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: K64 driver for standard PWM always resets start point</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64-driver-for-standard-PWM-always-resets-start-point/m-p/1173580#M58626</link>
      <description>&lt;P&gt;Ok, so I have produced the problem using the supplied example driver from MCUXpresso!&lt;/P&gt;&lt;P&gt;To produce the fault and see it on scope simply slow the PWM down to 100hz (and prescaler /16 as required) and you can continually see it break PWM timing&lt;/P&gt;&lt;P&gt;Here is the code and some images showing that it sometimes destroys the PWM and outputs the wrong timing completely&lt;/P&gt;&lt;P&gt;void delay(void)&lt;BR /&gt;{&lt;BR /&gt;volatile uint32_t i = 0U;&lt;BR /&gt;for (i = 0U; i &amp;lt; 10000000U; ++i)&lt;BR /&gt;{&lt;BR /&gt;__asm("NOP"); /* delay */&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt;/* Init board hardware. */&lt;BR /&gt;uint32_t error = 0;&lt;BR /&gt;BOARD_InitBootPins();&lt;BR /&gt;Global_IOConfig();&lt;BR /&gt;BOARD_InitBootClocks();&lt;/P&gt;&lt;P&gt;//TEST START&lt;BR /&gt;{&lt;BR /&gt;uint8_t prevupdatedDutycycle = 0;&lt;BR /&gt;bool brightnessUp = true; /* Indicate LEDs are brighter or dimmer */&lt;BR /&gt;ftm_config_t ftmInfo;&lt;BR /&gt;uint8_t updatedDutycycle = 0U;&lt;BR /&gt;ftm_chnl_pwm_signal_param_t ftmParam[2];&lt;BR /&gt;/* Configure ftm params with frequency 24kHZ */&lt;BR /&gt;ftmParam[0].chnlNumber = (ftm_chnl_t)RC1CH_PWM;&lt;BR /&gt;ftmParam[0].level = kFTM_LowTrue;&lt;BR /&gt;ftmParam[0].dutyCyclePercent = 0U;&lt;BR /&gt;ftmParam[0].firstEdgeDelayPercent = 0U;&lt;BR /&gt;ftmParam[0].enableDeadtime = false;&lt;/P&gt;&lt;P&gt;ftmParam[1].chnlNumber = (ftm_chnl_t)RC2CH_PWM;&lt;BR /&gt;ftmParam[1].level = kFTM_LowTrue;&lt;BR /&gt;ftmParam[1].dutyCyclePercent = 0U;&lt;BR /&gt;ftmParam[1].firstEdgeDelayPercent = 0U;&lt;BR /&gt;ftmParam[1].enableDeadtime = false;&lt;/P&gt;&lt;P&gt;PORT_SetPinMux(RC1_M_PORT, RC1_M_PIN, RC1_M_ALT);&lt;BR /&gt;PORT_SetPinMux(RC2_M_PORT, RC2_M_PIN, RC2_M_ALT);&lt;/P&gt;&lt;P&gt;/* Print a note to terminal */&lt;BR /&gt;PRINTF("\r\nFTM example to output PWM on 2 channels\r\n");&lt;BR /&gt;PRINTF("\r\nYou will see a change in LED brightness if an LED is connected to the FTM pin");&lt;BR /&gt;PRINTF("\r\nIf no LED is connected to the FTM pin, then probe the signal using an oscilloscope");&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt;* ftmInfo.prescale = kFTM_Prescale_Divide_1;&lt;BR /&gt;* ftmInfo.bdmMode = kFTM_BdmMode_0;&lt;BR /&gt;* ftmInfo.pwmSyncMode = kFTM_SoftwareTrigger;&lt;BR /&gt;* ftmInfo.reloadPoints = 0;&lt;BR /&gt;* ftmInfo.faultMode = kFTM_Fault_Disable;&lt;BR /&gt;* ftmInfo.faultFilterValue = 0;&lt;BR /&gt;* ftmInfo.deadTimePrescale = kFTM_Deadtime_Prescale_1;&lt;BR /&gt;* ftmInfo.deadTimeValue = 0;&lt;BR /&gt;* ftmInfo.extTriggers = 0;&lt;BR /&gt;* ftmInfo.chnlInitState = 0;&lt;BR /&gt;* ftmInfo.chnlPolarity = 0;&lt;BR /&gt;* ftmInfo.useGlobalTimeBase = false;&lt;BR /&gt;*/&lt;BR /&gt;FTM_GetDefaultConfig(&amp;amp;ftmInfo);&lt;BR /&gt;/* Initialize FTM module */&lt;BR /&gt;ftmInfo.prescale = kFTM_Prescale_Divide_16;&lt;/P&gt;&lt;P&gt;FTM_Init(FTM0, &amp;amp;ftmInfo);&lt;BR /&gt;// FTM_SetupPwm(FTM0, ftmParam, 2U, kFTM_EdgeAlignedPwm, 24000U, CLOCK_GetFreq(kCLOCK_BusClk));&lt;BR /&gt;//My Version&lt;BR /&gt;FTM_SetupPwm(FTM0, ftmParam, 2U, kFTM_EdgeAlignedPwm, 100U, TPM_SOURCE_CLOCK);&lt;/P&gt;&lt;P&gt;FTM_StartTimer(FTM0, kFTM_SystemClock);&lt;BR /&gt;while (1)&lt;BR /&gt;{&lt;BR /&gt;/* Delay to see the change of LEDs brightness */&lt;BR /&gt;delay();&lt;/P&gt;&lt;P&gt;if (brightnessUp)&lt;BR /&gt;{&lt;BR /&gt;/* Increase duty cycle until it reach limited value */&lt;BR /&gt;if (++updatedDutycycle == 100U)&lt;BR /&gt;{&lt;BR /&gt;brightnessUp = false;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;/* Decrease duty cycle until it reach limited value */&lt;BR /&gt;if (--updatedDutycycle == 0U)&lt;BR /&gt;{&lt;BR /&gt;brightnessUp = true;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;// if(prevupdatedDutycycle != updatedDutycycle)&lt;BR /&gt;{&lt;BR /&gt;prevupdatedDutycycle = updatedDutycycle;&lt;BR /&gt;/* Start PWM mode with updated duty cycle */&lt;BR /&gt;FTM_UpdatePwmDutycycle(FTM0, (ftm_chnl_t)RC1CH_PWM, kFTM_EdgeAlignedPwm, updatedDutycycle);&lt;BR /&gt;FTM_UpdatePwmDutycycle(FTM0, (ftm_chnl_t)RC2CH_PWM, kFTM_EdgeAlignedPwm, updatedDutycycle);&lt;BR /&gt;/* Software trigger to update registers */&lt;BR /&gt;FTM_SetSoftwareTrigger(FTM0, true);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;You can see the attached view with examples of this. It happens "a lot". This PWM configuration is dangerous and certainly not obvious this is how the driver works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make it keep timing, i need that 100Hz to ALWAYS be 100Hz&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 06:01:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64-driver-for-standard-PWM-always-resets-start-point/m-p/1173580#M58626</guid>
      <dc:creator>CarlFST60L</dc:creator>
      <dc:date>2020-10-27T06:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: K64 driver for standard PWM always resets start point</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64-driver-for-standard-PWM-always-resets-start-point/m-p/1173713#M58628</link>
      <description>&lt;P&gt;You guys need to update your example to either include this as an option, or, just turn it off&lt;/P&gt;&lt;P&gt;I have created this function call to fix the problem of PWM resetting its count.&lt;/P&gt;&lt;P&gt;I cannot really imagine many real examples where you would want your PWM to "start again" randomly or use this feature...&amp;nbsp;&lt;/P&gt;&lt;P&gt;uint16_t FTM_DisableReset(FTM_Type *base)&lt;BR /&gt;{&lt;BR /&gt;base-&amp;gt;SYNCONF &amp;amp;= (~FTM_SYNCONF_SWRSTCNT_MASK);&lt;BR /&gt;return base-&amp;gt;SYNCONF;&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 08:52:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/K64-driver-for-standard-PWM-always-resets-start-point/m-p/1173713#M58628</guid>
      <dc:creator>CarlFST60L</dc:creator>
      <dc:date>2020-10-27T08:52:18Z</dc:date>
    </item>
  </channel>
</rss>

