AnsweredAssumed Answered

MPC5746C Input Pulse Width Measurement

Question asked by Mandar Pande on Jul 17, 2017
Latest reply on Jul 24, 2017 by Petr Stancik

I am using eMIOS_0 module of #MPC5746C for controlling Motor Drives and measuring Input Pulse Width and Period.


I am using channel number 23 configured in MCB mode as a timebase channel to drive Counter Bus A. 

For Motor Drive control I am using OPWMB mode and for Input pulse width measurement I am using IPWM mode.


I am using Counter Bus A as a timebase for both OPWMB mode and IPWM mode. 


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.


I tried to count the number of MCB counter overflows that happened between the leading and trailing edge of the pulse by setting the FEN bit in C register of channel 23 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:


if (eMIOS_UC_0.UC[ucChannel].S.B.FLAG) {
   unEdge2Cnt = (uint32_t)eMIOS_UC_0.UC[ucChannel].A.R; /* Read 2nd edge count */
   unEdge1Cnt = (uint32_t)eMIOS_UC_0.UC[ucChannel].B.R; /* Read 1st edge count */

   eMIOS_UC_0.UC[ucChannel].S.B.FLAG = (vuint32_t)1; /* Clear flag */
   unDutyInuSec = (uint32_t)(unEdge2Cnt + (g_ucMcbFlgSetEvntCnt * g_usEmiosGblBusACount) - unEdge1Cnt);



ucChannel = eMIOS channel which is configured in IPWM mode

g_ucMcbFlgSetEvntCnt = the counter variable I am incrementing in the ISR of MCB flag

g_usEmiosGblBusACount = the MCB A register value which will be used for MCB up counter 


But even using this method I am not getting proper value.


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.


Please suggest a possible solution as to what I can do to get proper values for pulse width measurement.