PWM Issues

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
beneee
Posts: 37
Joined: Tue May 14, 2013 8:18 pm
Has thanked: 6 times
Been thanked: 1 time
Contact:

PWM Issues

Post by beneee »

I am trying to create a little circuit to fade an LED on & off without success so to test I have created a quick multi step pwm using the 10bit option and it works in the simulation but when running on the Chip (12F1501) it seems to only to step 2 then the led goes back to dim.

I am guessing I am doing something daft, please let me know.

In the end I would like all 4 PWM outputs ramping up and down smoothly at different rates but I am struggling at this point and also unsure how to do it using really efficient code as I am limited with this chip.

Thanks
Ben
PWMSteps.PNG
PWMSteps.PNG (34.63 KiB) Viewed 2298 times
PWM_Test.fcfx
(9.7 KiB) Downloaded 151 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM Issues

Post by Benj »

Hello,

The LED will often hit full saturation around 50% duty and you won't be able to tell if it's any brighter.

Here's a simple way to ramp up and down.
PWM_Test.fcfx
(9.8 KiB) Downloaded 141 times

If you wanted it to ramp faster then you could reduce the delay or you could increase the step size from 1 to say 2, 4, 8, 16 etc.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM Issues

Post by Benj »

Here's another example showing a state machine approach. Here PWM2 will ramp at twice the speed of PWM1.
PWM_Test2.fcfx
(14.23 KiB) Downloaded 172 times

beneee
Posts: 37
Joined: Tue May 14, 2013 8:18 pm
Has thanked: 6 times
Been thanked: 1 time
Contact:

Re: PWM Issues

Post by beneee »

Thank you

Ben

chad
Posts: 198
Joined: Sun Nov 04, 2018 7:13 pm
Has thanked: 27 times
Been thanked: 33 times
Contact:

Re: PWM Issues

Post by chad »

Just to clarify a little of what Ben said. The optical output of the led will scale above 50% to 100%. It is actually our eyes that don't scale well. Past a certain brightness our eyes don't perceive the brightness difference well but if you measured the optical output the led is doing what it is supposed to. To add more complexity, that color saturation level changes with the wavelength, or color. Color perception is really interesting and can open a whole can of worms. There is also scoptic and photopic color perception depending on the ambient light level (light, dark) and our eyes are more or less sensitive to different colors.

Just a couple of little tid bits on color theory. :)

Chad

Post Reply