- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Labels:
-
PSoC 3
-
PSoC 3 Device Programming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are certain KBA's and forum threads which may be useful as they discuss the same-
https://community.cypress.com/docs/DOC-10762