CTU Triggering for PWM VAL(0) in the wrong spot?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CTU Triggering for PWM VAL(0) in the wrong spot?

958 Views
duanemattern
Contributor III

I'm trying to implement Peter Vina's "MPC5643L PWM_ADC measurement concept " on the TRK-MPC5604P development board.  I've been having problems, so I'm doing it piece-meal, starting with the CTU triggering.  I finally got the triggering working by setting up an external trigger and monitoring it with the PWM signals using a logic analyzer.  The PWMs are modules 2 & 3 using A&B in independent mode.  They are center-aligned PWM signals (signed-mode), with Module 2B inverted and Module 3A inverted.  All that works fine.  I've been able to setup a trigger based on module2 Values (1-5) and I've setup the CTU such that I can generate an External Trigger on C14.   This works, but I'm having problem interpreting the results, but only for Values 0 and 1.

 

I expect the trigger on C14 to be center-aligned, when Module2 A is high, when the trigger is setup for a value of zero (0).  But that's not the case.  When the trigger values is set for value zero, I get the trigger when Module2 A is low, which is what I would interpret as Val(1), when the counter wraps-around.  The following is an example of what I'm taking about.

 

             FLEXPWM_0.SUB[2].TCTRL.R  = 0x0001;           /* Val(0) center  */

             FLEXPWM_0.SUB[2].INTEN.R = 0x04;                 //interrupt setup on Module2, Val(2); I toggle an output.

               .........

             CTU_0.TGSISR.B.I3_RE = 0x01;                           //Module 2 A is not inverted

             CTU_0.TGSCR.B.ETTM = 0x1;        //enable toggle mode for external trigger

 

172604_172604.pngpastedImage_2.png

I can get the desired result by using VAL(1) instead of VAL(0):

             FLEXPWM_0.SUB[2].TCTRL.R  = 0x0002;           /* Val(1) max  */

            ........

             CTU_0.TGSISR.B.I7_RE = 0x01;                           //Module 2 A is not inverted

But it seems to me that these results are swapped for the two values, VAL(1) and VAL(0). 

 

If I run this same test for Values of VAL(2), VAL(3), VAL(4), VAL(5), it behaves appropriately and I get what I expect, with the CTU external trigger corresponding to the specific PWM signal change.  I want to move on to the next step of triggering analog to digital conversion, but I want to make sure I fully understand this first, as I want to trigger the ADC at a specific time, and I'm going to use VAL(0) for that, but now I'll have to re-interpret when  that time is.

Labels (1)
Tags (3)
0 Kudos
2 Replies

648 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi ,

could you please share complete setting of the FlexPWM, or at least INIT and VAL0-5 and polarity setting?

BR, Petr

0 Kudos

648 Views
duanemattern
Contributor III

I've been using the RAppID Init, so the code is massive because it includes the initializatio of everything and I've not reduced it to a seubset yet.  But here is the FlexPWM setup code for Module 2, which is whatt I'm triggering off of:

void flexpwm0_sub2_init_fnc (void)
{   FLEXPWM_0.SUB[2].CTRL2.R = 0x2000;
    FLEXPWM_0.SUB[2].INTEN.R = 0x00;    //32-16-8-4-2-1   no interrrupt this version

    FLEXPWM_0.SUB[2].CTRL.B.LDFQ = 0;    //every pwm opportunity
    FLEXPWM_0.SUB[2].CTRL.B.HALF = 1;    //reload at midpoint
    FLEXPWM_0.SUB[2].CTRL.B.FULL = 0;
    FLEXPWM_0.SUB[2].CTRL.B.DT = 0;
    FLEXPWM_0.SUB[2].CTRL.B.PRSC = 0x00;    //7=fclk/128
    FLEXPWM_0.SUB[2].CTRL.B.DBLEN = 0;

//  Center Aligned    
    FLEXPWM_0.SUB[2].INIT.R   = (vuint16_t)(-320);    /* Initial count value for the PWM    */
    FLEXPWM_0.SUB[2].VAL[1].R = (vuint16_t)(+320);   
    FLEXPWM_0.SUB[2].VAL[0].R = (vuint16_t)(0);       /* "Mid-cycle" reload point     */
    FLEXPWM_0.SUB[2].VAL[2].R = (vuint16_t)(-176);    /* PWMA high 55%  */
    FLEXPWM_0.SUB[2].VAL[3].R = (vuint16_t)(+176);    /* PWMA low       */
    FLEXPWM_0.SUB[2].VAL[4].R = (vuint16_t)(-256);    /* PWMB high 80%  */
    FLEXPWM_0.SUB[2].VAL[5].R = (vuint16_t)(+256);    /* PWMB low  20% inverted     */
    FLEXPWM_0.SUB[2].OCTRL.R  = 0x0200;               /* B_inverted, PWM A,B,X O/P Fault State

                                                        : Output is forced to Logic 0    */

//  various attempts at triggering
    FLEXPWM_0.SUB[2].TCTRL.R  = 0x002A;           /*      32  + 8 + 2     ODD */
//  FLEXPWM_0.SUB[2].TCTRL.R  = 0x0015;           /*         16 + 4 + 1  EVEN */
    
    FLEXPWM_0.SUB[2].DMAEN.R = 0x0000;            /* DMA write requests : Disabled    */
    FLEXPWM_0.SUB[2].DTCNT0.R = 0x0000;          // No delays, independent control
    FLEXPWM_0.SUB[2].DTCNT1.R = 0x0000;          // No delays, independent control

    FLEXPWM_0.SUB[2].DISMAP.R = 0xFF00;
    FLEXPWM_0.SUB[2].CAPTCTRLX.R = 0x0000;
    FLEXPWM_0.SUB[2].CAPTCOMPX.R = 0x0000;
}

Module three is similar, shifted 180 degrees, but no triggering there

   FLEXPWM_0.SUB[3].TCTRL.R  = 0x0000;               /* Output Trigger Control :  */

0 Kudos