<?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>Kinetis MicrocontrollersのトピックMotor controller acceleration profiles with FTM PWM?</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963102#M55065</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using a Kinetis MK22FN512 and controlling some stepper motor drivers that take pulse inputs. I'm currently using the FTMs to generate 50% duty cycle pulse&amp;nbsp;trains. It works perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I'm trying to implement an acceleration profile. This requires modulation of the PWM period while sending&amp;nbsp;the pulse series (duty cycle fixed at 50%). The frequency of the signal will increase in a linear fashion, plateau and then decrease.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At first glance, it looks like this may be possible to do using the "Combine Mode" of the FTM. I was also thinking that DMA could be employed so that the processor doesn't need to be constantly servicing a routine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone implemented something like this? Is it even possible? Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Jun 2019 16:51:57 GMT</pubDate>
    <dc:creator>andy1</dc:creator>
    <dc:date>2019-06-07T16:51:57Z</dc:date>
    <item>
      <title>Motor controller acceleration profiles with FTM PWM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963102#M55065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using a Kinetis MK22FN512 and controlling some stepper motor drivers that take pulse inputs. I'm currently using the FTMs to generate 50% duty cycle pulse&amp;nbsp;trains. It works perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I'm trying to implement an acceleration profile. This requires modulation of the PWM period while sending&amp;nbsp;the pulse series (duty cycle fixed at 50%). The frequency of the signal will increase in a linear fashion, plateau and then decrease.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At first glance, it looks like this may be possible to do using the "Combine Mode" of the FTM. I was also thinking that DMA could be employed so that the processor doesn't need to be constantly servicing a routine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone implemented something like this? Is it even possible? Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2019 16:51:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963102#M55065</guid>
      <dc:creator>andy1</dc:creator>
      <dc:date>2019-06-07T16:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Motor controller acceleration profiles with FTM PWM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963103#M55066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andrew&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The uTasker project has a Stepper Motor interface which allows DMA based FlexTimer operation to generate ramps and such. For optimal use of stepper motor torque exponential ramps can be programmed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The interface is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Prepare ramp tables (frequencies and the number of cycles each frequency is present for in the ramp):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;static&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;const&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;short&lt;/SPAN&gt; rampFrequencyValue&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4800&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                             &lt;SPAN class="comment token"&gt;// 4800Hz&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4200&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                             &lt;SPAN class="comment token"&gt;// 4200Hz&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3200&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                             &lt;SPAN class="comment token"&gt;// 3200Hz&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1000&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                             &lt;SPAN class="comment token"&gt;// 1000Hz&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;100&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                              &lt;SPAN class="comment token"&gt;// 100Hz&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;800&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                              &lt;SPAN class="comment token"&gt;// 800Hz&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1800&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                             &lt;SPAN class="comment token"&gt;// 1800Hz&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;20000&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                            &lt;SPAN class="comment token"&gt;// 20kHz&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;static&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;const&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;short&lt;/SPAN&gt; rampCountValue&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;                         &lt;SPAN class="comment token"&gt;// accumulated&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;10&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                                                  &lt;SPAN class="comment token"&gt;// 10 pulses at first frequency&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;18&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                                                  &lt;SPAN class="comment token"&gt;// 8 pulses at next frequency&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;22&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;24&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;25&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;27&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;33&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;53&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;                                                                   &lt;SPAN class="comment token"&gt;// end (dummy due to buffer delay)&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Configure two FlexTimers - one generating a frequency and the other using this as clock input (eg. CLKIN0) to count the cycles (with no output).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;    PWM_INTERRUPT_SETUP pwm_setup&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;int_type &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; PWM_INTERRUPT&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_mode &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;PWM_EXTERNAL_CLK &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_PRESCALER_0 &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_NO_OUTPUT &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_FULL_BUFFER_DMA &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_DMA_CHANNEL_ENABLE &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_DMA_CONTROL_PWM&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;// clock PWM timer from external clock (use channel DMA)&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;int_handler &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                                           &lt;SPAN class="comment token"&gt;// no user interrupt call-back on PWM cycle&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_reference &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;_TIMER_1 &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                            &lt;SPAN class="comment token"&gt;// timer module 1, channel 0&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_frequency &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0xffff&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                                    &lt;SPAN class="comment token"&gt;// cause maximum timer count to be used&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_value &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; rampCountValue&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                             &lt;SPAN class="comment token"&gt;// first match value&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ucDmaChannel &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                                          &lt;SPAN class="comment token"&gt;// use DMA channel 2&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dma_int_priority &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;usDmaTriggerSource &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; DMAMUX0_CHCFG_SOURCE_FTM1_C0&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;         &lt;SPAN class="comment token"&gt;// load next value on own timer match&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ptrPWM_Buffer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;short&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt;rampCountValue&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;      &lt;SPAN class="comment token"&gt;// buffer controlling the DMA trigger points&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ulPWM_buffer_length &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;sizeof&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rampCountValue&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;sizeof&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;short&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dma_int_handler &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; fnEndOfRamp&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                             &lt;SPAN class="comment token"&gt;// call back on DMA termination&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;fnConfigureInterrupt&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;void&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt;pwm_setup&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                            &lt;SPAN class="comment token"&gt;// enter configuration for DMA trigger generation&lt;/SPAN&gt;

    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_mode &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;PWM_SYS_CLK &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_PRESCALER_16 &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_FULL_BUFFER_DMA &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_DMA_CHANNEL_ENABLE &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; PWM_DMA_CONTROL_FREQUENCY&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_reference &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;_TIMER_0 &lt;SPAN class="operator token"&gt;|&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                            &lt;SPAN class="comment token"&gt;// timer module 0, channel 2&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ucDmaChannel &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                                          &lt;SPAN class="comment token"&gt;// use DMA channel 1&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_frequency &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; rampFrequencyValue&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                     &lt;SPAN class="comment token"&gt;// set start frequency&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pwm_value &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;_PWM_PERCENT&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;50&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;PWM_FREQUENCY&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;20000&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;16&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;    &lt;SPAN class="comment token"&gt;// 50% PWM (high/low) when the frequency is 20kHz&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ptrPWM_Buffer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;short&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt;rampFrequencyValue&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;// buffer controlling the frequencies&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ulPWM_buffer_length &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;sizeof&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rampFrequencyValue&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;sizeof&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;unsigned&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;short&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    pwm_setup&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dma_int_handler &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                                       &lt;SPAN class="comment token"&gt;// no callback on DMA buffer transfer termination&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;fnConfigureInterrupt&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;void&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;amp;&lt;/SPAN&gt;pwm_setup&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                            &lt;SPAN class="comment token"&gt;// configure and start the PWM output&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;FTM1, channel 0 is used as DMA trigger each time the required cycles have been detected.&lt;BR /&gt;FTM0, channel 2 is used to generate an output frequency (50% MSR at the maximum frequency of 20kHz)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On each DMA trigger (after each cycle count match) the next frequency is set and the next cycle count value incremented.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the end of the ramp the interrupt call back fnEndoOfRamp() is called, which can prepare the next job or stop the operation. Eg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;static&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;void&lt;/SPAN&gt; __callback_interrupt &lt;SPAN class="token function"&gt;fnEndOfRamp&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;void&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    FTM0_SC &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;                                                         &lt;SPAN class="comment token"&gt;// stop the PWM output when the sequence has completed&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The stepper motor pulse is a fixed width one (not 50% duty cycle throughout) and the maximum ramp cycle count is 64k due to the 16 bit timer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Complete Kinetis solutions for professional needs, training and support:&lt;A href="http://www.utasker.com/kinetis.html" target="_blank"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Kinetis K22:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;- &lt;A href="http://www.utasker.com/kinetis/FRDM-K22F.html" rel="nofollow noopener noreferrer" target="test_blank"&gt;http://www.utasker.com/kinetis/FRDM-K22F.html&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;- &lt;A href="http://www.utasker.com/kinetis/TWR-K22F120M.html" rel="nofollow noopener noreferrer" target="test_blank"&gt;http://www.utasker.com/kinetis/TWR-K22F120M.html&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;- &lt;A href="http://www.utasker.com/kinetis/BLAZE_K22.html" rel="nofollow noopener noreferrer" target="test_blank"&gt;http://www.utasker.com/kinetis/BLAZE_K22.html&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;- &lt;A href="http://www.utasker.com/kinetis/tinyK22.html" rel="nofollow noopener noreferrer" target="test_blank"&gt;http://www.utasker.com/kinetis/tinyK22.html&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;uTasker: supporting &amp;gt;1'000 registered Kinetis users get products faster and cheaper to market&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Request Free emergency remote desk-top consulting at &lt;A href="http://www.utasker.com/services.html" rel="nofollow noopener noreferrer" target="test_blank"&gt;http://www.utasker.com/services.html&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;A href="https://github.com/uTasker/uTasker-Kinetis" rel="nofollow noopener noreferrer" target="test_blank"&gt;https://github.com/uTasker/uTasker-Kinetis&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jun 2019 02:32:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963103#M55066</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-06-10T02:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Motor controller acceleration profiles with FTM PWM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963104#M55067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;This definitely gives me something to start with. Unfortunately, all 4 of my FTMs are all being used (2 motors, 2 encoders). So I wouldn't be able to employ this particular solution if I wanted to move two motors at once. But this gets me closer to a solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've only been using Kinetis and ARM for a few months. So, I'm still learning the ins and out of the architecture.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps&amp;nbsp;the&amp;nbsp;PIT module could be used instead of a second FTM to perform the counting/DMA-triggering...Any apparent reasons why that would not be possible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jun 2019 14:09:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963104#M55067</guid>
      <dc:creator>andy1</dc:creator>
      <dc:date>2019-06-10T14:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Motor controller acceleration profiles with FTM PWM?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963105#M55068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The PITs have neither an input nor an output so can't be used for counting PWM output cycles or generating output signals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you don't have high speeds and long ramping sequences you could use a single PWM output to update its next frequency on 'every' cycle (that is, when it needs to generate 10 cycles at a certain frequency it would have the same frequency value 10x in the table and then not need an input to count its output cycles.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would however be less inefficient, especially for generating a controlled distance movement (say 1000 steps before generating a distance-moved interrupt) because it would need a 1000 entry table with the same "speed" value at each location - although DMA based operations are very efficient it still does load the bus slightly - eg. a 1MHz DMA trigger/transfer rate can become noticeable since it begins to starve the CPU's bus access.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jun 2019 17:21:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Motor-controller-acceleration-profiles-with-FTM-PWM/m-p/963105#M55068</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2019-06-10T17:21:48Z</dc:date>
    </item>
  </channel>
</rss>

