<?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 Re: KV5x eFlexPWM capture example. in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752392#M45833</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Ari,&lt;/P&gt;&lt;P&gt;I have developed an example which can demo the capture function of eFlexPWM module. I post it here.&lt;/P&gt;&lt;P&gt;On the demo code, I generate PWM signals with SM0/SM1/SM2 of PWMA module, I connect the PWMA_0A signal to the PWMA_1X pin so that I can check if the captured value is correct or not.&lt;/P&gt;&lt;P&gt;software configuration:&lt;/P&gt;&lt;P&gt;1)enable all module clock&lt;/P&gt;&lt;P&gt;void CLOCK_init(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_PCE3|=0x00FF;&amp;nbsp; //enable PWMA and PWMB all channels&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_PCE0|=0xFF7F;&amp;nbsp; //enable all Timer and GPIO A/B/C/D/E/G/F&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_PCE2|=0x180; //enable SAR ADC clock and Cyclic ADC clock&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;2)I configure the PWMA_1X pin GPIO_G9 as PWMA_1X with the code:&lt;/P&gt;&lt;P&gt;//GPIOG9 PWMB_1X PWMA_1X TA3 XB_OUT11, pin 30 on J503 on TWR-8400 board&lt;BR /&gt;//connect the measured signal to PWMA_1A pin GPIOG9, test the duty cycle of the signal&lt;BR /&gt;void pinPWMA_1X(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//let PWMA_1X signal output&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;GPIOG_PER|=0x200;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_GPSGH&amp;amp;=~(0x30);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_GPSGH|=0x01&amp;lt;&amp;lt;2; //set G9 bits to be 01 in binary:01 Function = PWMA_1X;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PWMA_OUTEN&amp;amp;=~(0x0F); //disable all PWMA_X pins&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;configure the GPIO_G9 as PWMA_1X: clear the corresponding bit in PWMA_OUTEN, the PWMA_1X will be a capture signal input, set the orresponding bit in PWMA_OUTEN, the PWMA_1X will be an PWM signal output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3)configure capture function:&lt;/P&gt;&lt;P&gt;void captureFuncPWMA_1A(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//bit setting:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//EDGCNTX_EN=1 Edge counter enabled&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//INP_SELX=0 Raw PWM_X input signal selected as source.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//EDGX1=01 Capture falling edges&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//EDGX0=10 Capture rising edges&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//ONESHOTX=0 Free running mode is selected.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1CAPTCTRLX&amp;amp;=0x00;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1CAPTCTRLX=0x98;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1CAPTCTRLX|=0x01; //start capture function&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_OUTEN&amp;amp;=~(0x0F); //disable all PWMA_X pins&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;4)interrupt mode configuration:&lt;/P&gt;&lt;P&gt;void PWM_ISR_SETTING()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//interrupt priority setting&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTC_IPR8|=0xC000; //set PWMA_CAP interrupt source priority&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//enable the PWM_SM0 reload interrupt&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1INTEN|=0x80; //edge1(falling edge) trigger interrupt&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5)ISR function of capture:&lt;/P&gt;&lt;P&gt;#pragma interrupt on&lt;BR /&gt;void captureISR(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;static unsigned int i=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varEdge0[i]=PWMA_SM1CVAL0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varEdge1[i]=PWMA_SM1CVAL1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varDiff[i]=varEdge1-varEdge0;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varsm0cnt[i]=PWMA_SM0CNT;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varsm1cnt[i]=PWMA_SM1CNT;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;i++;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(i&amp;gt;=50) &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;asm(debughlt);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//clear the interrupt flag&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1STS|=0xC0; //clear the CFX1 and CFX0 bits&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;GPIOA_DR^=0x100; //toggle the A8 bit&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hardware connection:&lt;/P&gt;&lt;P&gt;I developed the project on CodeWarrior for mcu ver10.6 and TWR-8400 board. Connect the PWMA_0A(pin 40 of primary A connector) to GPIO_G9(pin 30 of J503), it is okay. you'd better connect a 2~5K ohm serial resistor when you test in case you configure both pin as output by mistake.&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Xiangjun Rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 17 May 2018 09:20:30 GMT</pubDate>
    <dc:creator>xiangjun_rong</dc:creator>
    <dc:date>2018-05-17T09:20:30Z</dc:date>
    <item>
      <title>KV5x eFlexPWM capture example.</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752390#M45831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;I would like to receive an&amp;nbsp; example showing how to configure the KV5x or KV4x eFlexPWM in capture mode. The example can be at register level or using the KDS 2.x api. And it also can be an example for the MC56F84xxx PWMA/PWMB in capture mode, because the peripheral IP is the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Ari.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 May 2018 19:28:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752390#M45831</guid>
      <dc:creator>arimendes</dc:creator>
      <dc:date>2018-05-14T19:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: KV5x eFlexPWM capture example.</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752391#M45832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Ari,&lt;/P&gt;&lt;P&gt;Based on your requirement, I am developing the application of capture function, I will post the code based on TWR-8400 board, pls be patient.&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Xiangjun rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2018 07:21:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752391#M45832</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2018-05-15T07:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: KV5x eFlexPWM capture example.</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752392#M45833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Ari,&lt;/P&gt;&lt;P&gt;I have developed an example which can demo the capture function of eFlexPWM module. I post it here.&lt;/P&gt;&lt;P&gt;On the demo code, I generate PWM signals with SM0/SM1/SM2 of PWMA module, I connect the PWMA_0A signal to the PWMA_1X pin so that I can check if the captured value is correct or not.&lt;/P&gt;&lt;P&gt;software configuration:&lt;/P&gt;&lt;P&gt;1)enable all module clock&lt;/P&gt;&lt;P&gt;void CLOCK_init(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_PCE3|=0x00FF;&amp;nbsp; //enable PWMA and PWMB all channels&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_PCE0|=0xFF7F;&amp;nbsp; //enable all Timer and GPIO A/B/C/D/E/G/F&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_PCE2|=0x180; //enable SAR ADC clock and Cyclic ADC clock&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;2)I configure the PWMA_1X pin GPIO_G9 as PWMA_1X with the code:&lt;/P&gt;&lt;P&gt;//GPIOG9 PWMB_1X PWMA_1X TA3 XB_OUT11, pin 30 on J503 on TWR-8400 board&lt;BR /&gt;//connect the measured signal to PWMA_1A pin GPIOG9, test the duty cycle of the signal&lt;BR /&gt;void pinPWMA_1X(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//let PWMA_1X signal output&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;GPIOG_PER|=0x200;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_GPSGH&amp;amp;=~(0x30);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;SIM_GPSGH|=0x01&amp;lt;&amp;lt;2; //set G9 bits to be 01 in binary:01 Function = PWMA_1X;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PWMA_OUTEN&amp;amp;=~(0x0F); //disable all PWMA_X pins&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;configure the GPIO_G9 as PWMA_1X: clear the corresponding bit in PWMA_OUTEN, the PWMA_1X will be a capture signal input, set the orresponding bit in PWMA_OUTEN, the PWMA_1X will be an PWM signal output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3)configure capture function:&lt;/P&gt;&lt;P&gt;void captureFuncPWMA_1A(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//bit setting:&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//EDGCNTX_EN=1 Edge counter enabled&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//INP_SELX=0 Raw PWM_X input signal selected as source.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//EDGX1=01 Capture falling edges&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//EDGX0=10 Capture rising edges&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//ONESHOTX=0 Free running mode is selected.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1CAPTCTRLX&amp;amp;=0x00;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1CAPTCTRLX=0x98;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1CAPTCTRLX|=0x01; //start capture function&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_OUTEN&amp;amp;=~(0x0F); //disable all PWMA_X pins&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;4)interrupt mode configuration:&lt;/P&gt;&lt;P&gt;void PWM_ISR_SETTING()&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//interrupt priority setting&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;INTC_IPR8|=0xC000; //set PWMA_CAP interrupt source priority&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//enable the PWM_SM0 reload interrupt&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1INTEN|=0x80; //edge1(falling edge) trigger interrupt&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5)ISR function of capture:&lt;/P&gt;&lt;P&gt;#pragma interrupt on&lt;BR /&gt;void captureISR(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;static unsigned int i=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varEdge0[i]=PWMA_SM1CVAL0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varEdge1[i]=PWMA_SM1CVAL1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varDiff[i]=varEdge1-varEdge0;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varsm0cnt[i]=PWMA_SM0CNT;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;varsm1cnt[i]=PWMA_SM1CNT;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;i++;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(i&amp;gt;=50) &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;asm(debughlt);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//clear the interrupt flag&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;PWMA_SM1STS|=0xC0; //clear the CFX1 and CFX0 bits&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;GPIOA_DR^=0x100; //toggle the A8 bit&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hardware connection:&lt;/P&gt;&lt;P&gt;I developed the project on CodeWarrior for mcu ver10.6 and TWR-8400 board. Connect the PWMA_0A(pin 40 of primary A connector) to GPIO_G9(pin 30 of J503), it is okay. you'd better connect a 2~5K ohm serial resistor when you test in case you configure both pin as output by mistake.&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Xiangjun Rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 May 2018 09:20:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752392#M45833</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2018-05-17T09:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: KV5x eFlexPWM capture example.</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752393#M45834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Xiangjun Rong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Ari.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 May 2018 18:24:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KV5x-eFlexPWM-capture-example/m-p/752393#M45834</guid>
      <dc:creator>arimendes</dc:creator>
      <dc:date>2018-05-17T18:24:22Z</dc:date>
    </item>
  </channel>
</rss>

