Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 1 month ago.
PWM outputs interfere with each other(?)
I have a project that assigns two pins as pwmOut
PwmOut dled(p23); PwmOut spkr(p21); Timeout beepOff;
One is for a piezo buzzer and the other controls the brightness of the LCD backlight.
I've noticed that, at the end of the tone, when the speaker is turned off by the Timeout, the display is also turned off. Since I refresh the display setting once a second it gets turned back on on the next tick. I have a work-around were I (re)set the display immediately after turning off the speaker tone so it is only a flicker but still annoying.
void spkrOff(void){ spkr=0; dled=0.7; // Work-around added to prevent the display from also turning off } void beep(float freq, float time){ if (enableSound) { spkr.period(1.0/freq); spkr=0.5; beepOff.attach(&spkrOff, time); } }
Any ideas why setting the spkr pwmOut to zero also sets the dled pwmOut to zero?
2 Answers
11 years, 1 month ago.
Hi Tick,
The reason you are seeing this behaviour is that the PWM hardware on the LPC1768 has individual registers for settings for the pulsewidth, but a global one for setting the period - i.e. the period is shared by all PWM outputs.
When you set spkr to 0, it should not impact the pulsewidth. So in your code, when you set the period in beep is actually when the display is impacted unless i've overlooked something - if you try setting the dled to 0.7 after setting the spkr period and pulsewidth in your beep routine, you may find the flicker goes away.
Not ideal, but basically it is a limitation of the underlying hardware.
Simon
11 years, 1 month ago.
Thanks. This does explain a lot. The phenomenon seems to be influenced by the period of the tone, too. I tried your suggestion and it did work (re-setting the dled immediately after setting the speaker period). I do see a slight difference in the backlight brightness with changes in the period from the beep routine so I also restore that after the tone is done.