While running, duty cycle change to a PWM block output has glitch.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
melac_296496
Level 2
Level 2

When I change the duty cycle for my LED pwm output, before going to dim it turns off, and then, goes to dim.  Seems like it is glitching.  Is there a solution for this or am I doing something wrong?

Below are my values for period and compare:

// Period, Compare value

    {65535,     0},//0 OFF

    {65535, 65535},//1 ON

    {65535, 32000},//2 BLINK

    {100,      75} //3 DIM

};

Here is my function:

static void SetPWMLEDIndicators(void){

    uint8 BtnLoc;

    uint16 wPeriod, wCMP;

    for(BtnLoc = 0; BtnLoc < NUM_PHYSICAL_BUTTONS; BtnLoc++){

        if(wLEDIndicatorPWMSrvMask & (1 << BtnLoc)){

            wPeriod = abLEDindicPWMRxMsg[BtnLoc][0];

            wCMP = abLEDindicPWMRxMsg[BtnLoc][1];

            ChangeLEDMode((BtnLoc + 1), wPeriod, wCMP);           

            wLEDIndicatorPWMSrvMask &= ~(1 << BtnLoc);

        }

    } 

}

PWM Mode: One Output

CMP Type 1: Greater or Equal

Dead Band: Disable

Enable Mode: Software Only

Run Mode: Continuous

Trigger Mode: None

Kill Mode: Disableed

Capture Mode: None

Interrupts: None

extern void ChangeLEDMode(LOGICAL_STATION_BUTTON button, uint16 wPeriod, uint16 wCMP){  

    switch(button){

        case TOP:

            PWM_TL_WritePeriod(wPeriod);

            PWM_TL_WriteCompare(wCMP);

            break;

        case MIDDLE:

            PWM_ML_WritePeriod(wPeriod);

            PWM_ML_WriteCompare(wCMP);

            break;

        case BOTTOM:

            PWM_BL_WritePeriod(wPeriod);

            PWM_BL_WriteCompare(wCMP);

            break;

        default:

            break;

    }

}

Appropriate help!

0 Likes
3 Replies
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

The problem happens because you are changing the period from 65535 to 100 while keeping the counter as it is. So the block probably increments the internal counter till it overflows.

You might be able to fix the problem by writing the internal counter to ZERO after changing the period to 100. Use the API WriteCounter().

Thanks Rols! It reconfirm what I was seeing.  However, I could not make it work if I understood you correctly.

extern void ChangeLEDMode(LOGICAL_STATION_BUTTON button, uint16 wPeriod, uint16 wCMP){  

    switch(button){

        case TOP:

            PWM_TL_WritePeriod(wPeriod);

            PWM_TL_WriteCounter(0);

            PWM_TL_WriteCompare(wCMP);

           

            break;

        case MIDDLE:

            PWM_ML_WritePeriod(wPeriod);

            PWM_ML_WriteCounter(0);

            PWM_ML_WriteCompare(wCMP);

           

            break;

        case BOTTOM:

            PWM_BL_WritePeriod(wPeriod);

            PWM_BL_WriteCounter(0);

            PWM_BL_WriteCompare(wCMP);

           

            break;

        default:

            break;

    }

}

The only way I could make it work is to change my values:

// Period, Compare value

    {100, 0},//0 OFF

    {100, 50},    //1 ON

    {65535, 32000},//2 BLINK

    {100,  2}    //3 DIM

};

0 Likes