<?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 MPC5746C Input Pulse Width Measurement in MPC5xxx</title>
    <link>https://community.nxp.com/t5/MPC5xxx/MPC5746C-Input-Pulse-Width-Measurement/m-p/671571#M7791</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am&amp;nbsp;using eMIOS_0 module of #MPC5746C for controlling Motor Drives and measuring Input Pulse Width and Period.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using channel number &lt;STRONG&gt;23&lt;/STRONG&gt; configured in &lt;STRONG&gt;MCB&lt;/STRONG&gt; mode as a timebase channel to drive &lt;STRONG&gt;Counter Bus A.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;For Motor Drive control I am using OPWMB mode and for Input pulse width measurement I am using IPWM mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using Counter Bus A as a timebase for both OPWMB mode and IPWM mode.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I configure Motor Drive control frequency at e.g. 500Hz and try to measure pulse width of signals with frequency lower than 500Hz, I am getting wrong values. I found that I was getting wrong values because MCB counter was overflowing multiple times between leading edge and trailing edge captures in IPWM mode(because the period of the pulse under measurement was much more than the period of the counter). Thus, I will not get the proper pulse width by subtracting A register value from B register value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to count the number of MCB counter overflows that happened between the leading and trailing edge of the pulse by setting the &lt;STRONG&gt;FEN bit in C register of channel 23&lt;/STRONG&gt; and increment a counter variable in the ISR of channel 23. The following code snippet is how I am calculating the value of pulse width:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt;if (eMIOS_UC_0.UC[ucChannel].S.B.FLAG) {&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;unEdge2Cnt = (uint32_t)eMIOS_UC_0.UC[ucChannel].A.R; /* Read 2nd edge count */&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;unEdge1Cnt = (uint32_t)eMIOS_UC_0.UC[ucChannel].B.R; /* Read 1st edge count */&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;eMIOS_UC_0.UC[ucChannel].S.B.FLAG = (vuint32_t)1; /* Clear flag */&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;unDutyInuSec = (uint32_t)(unEdge2Cnt + (g_ucMcbFlgSetEvntCnt * g_usEmiosGblBusACount) - unEdge1Cnt);&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here,&lt;/P&gt;&lt;P&gt;ucChannel = eMIOS channel which is configured in IPWM mode&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;g_ucMcbFlgSetEvntCnt = the counter variable I am incrementing in the ISR of MCB flag&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;g_usEmiosGblBusACount = the MCB A register value which will be used for MCB up counter&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But even using this method I am not getting proper value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Due to hardware design limitations, I cannot use any other counter bus other than Counter Bus A to provide timebase for both OPWMB and IPWM modes. And I cannot modify MCB count as it is controlling the frequency of Motor Drive circuits.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please suggest a possible solution as to what I can do to get proper values for pulse width measurement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Jul 2017 09:30:24 GMT</pubDate>
    <dc:creator>mandarpande</dc:creator>
    <dc:date>2017-07-17T09:30:24Z</dc:date>
    <item>
      <title>MPC5746C Input Pulse Width Measurement</title>
      <link>https://community.nxp.com/t5/MPC5xxx/MPC5746C-Input-Pulse-Width-Measurement/m-p/671571#M7791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am&amp;nbsp;using eMIOS_0 module of #MPC5746C for controlling Motor Drives and measuring Input Pulse Width and Period.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using channel number &lt;STRONG&gt;23&lt;/STRONG&gt; configured in &lt;STRONG&gt;MCB&lt;/STRONG&gt; mode as a timebase channel to drive &lt;STRONG&gt;Counter Bus A.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;For Motor Drive control I am using OPWMB mode and for Input pulse width measurement I am using IPWM mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using Counter Bus A as a timebase for both OPWMB mode and IPWM mode.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I configure Motor Drive control frequency at e.g. 500Hz and try to measure pulse width of signals with frequency lower than 500Hz, I am getting wrong values. I found that I was getting wrong values because MCB counter was overflowing multiple times between leading edge and trailing edge captures in IPWM mode(because the period of the pulse under measurement was much more than the period of the counter). Thus, I will not get the proper pulse width by subtracting A register value from B register value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to count the number of MCB counter overflows that happened between the leading and trailing edge of the pulse by setting the &lt;STRONG&gt;FEN bit in C register of channel 23&lt;/STRONG&gt; and increment a counter variable in the ISR of channel 23. The following code snippet is how I am calculating the value of pulse width:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt;if (eMIOS_UC_0.UC[ucChannel].S.B.FLAG) {&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;unEdge2Cnt = (uint32_t)eMIOS_UC_0.UC[ucChannel].A.R; /* Read 2nd edge count */&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;unEdge1Cnt = (uint32_t)eMIOS_UC_0.UC[ucChannel].B.R; /* Read 1st edge count */&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;eMIOS_UC_0.UC[ucChannel].S.B.FLAG = (vuint32_t)1; /* Clear flag */&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;unDutyInuSec = (uint32_t)(unEdge2Cnt + (g_ucMcbFlgSetEvntCnt * g_usEmiosGblBusACount) - unEdge1Cnt);&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="color: #000000;"&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here,&lt;/P&gt;&lt;P&gt;ucChannel = eMIOS channel which is configured in IPWM mode&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;g_ucMcbFlgSetEvntCnt = the counter variable I am incrementing in the ISR of MCB flag&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;g_usEmiosGblBusACount = the MCB A register value which will be used for MCB up counter&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But even using this method I am not getting proper value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Due to hardware design limitations, I cannot use any other counter bus other than Counter Bus A to provide timebase for both OPWMB and IPWM modes. And I cannot modify MCB count as it is controlling the frequency of Motor Drive circuits.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please suggest a possible solution as to what I can do to get proper values for pulse width measurement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Jul 2017 09:30:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/MPC5746C-Input-Pulse-Width-Measurement/m-p/671571#M7791</guid>
      <dc:creator>mandarpande</dc:creator>
      <dc:date>2017-07-17T09:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: MPC5746C Input Pulse Width Measurement</title>
      <link>https://community.nxp.com/t5/MPC5xxx/MPC5746C-Input-Pulse-Width-Measurement/m-p/671572#M7792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did similar some time ago for other customer. See attached example, which uses channel23 interrupt to count counter bus A overflows. The SAIC mode is used but can be easily reused for your IPWM mode.&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR, Petr&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jul 2017 10:02:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MPC5xxx/MPC5746C-Input-Pulse-Width-Measurement/m-p/671572#M7792</guid>
      <dc:creator>PetrS</dc:creator>
      <dc:date>2017-07-24T10:02:16Z</dc:date>
    </item>
  </channel>
</rss>

