Page 1 of 1

Control speed of LEDs.

Posted: Sat Jun 06, 2015 4:16 am
by hprane
Hi,

I tried to add a new topic on V5 forum. But I can't add one. That's why I posted this here. Sorry for that.

Anyway I want to get some help.
I mostly use Flowcode for make light designs. I want to know how to add a potentiometer to the IC to control the speed of lights.

I have V5 and I'm using 4MHz crystal. I mostly use 16F84A and 16F877A.

I made simple 4 LED running program and can you guide me through it to how to add a potentiometer for it please.
If you can describe your doings step by step I would be very glad.
Because then I can study them and can try to understand them.

If we have to use ADC what ICs can I use for this and what value of potentiometer is suitable and how can I connect it to my circuit?

I attached a basic program and this is my normal circuit diagram. I modify it and use it for my purposes.

Image

I want to know how to add a potentiometer to this circuit and code it from Flowcode.

[/youtube]

Thank you.

Re: Control speed of LEDs.

Posted: Sat Jun 06, 2015 9:25 am
by medelec35
Hi hprane,
hprane wrote:I tried to add a new topic on V5 forum. But I can't add one. That's why I posted this here. Sorry for that.
Have you read this post?
hprane wrote:I made simple 4 LED running program and can you guide me through it to how to add a potentiometer for it please.
Using a pot for controlling you will need a microcontroller that supports analogue to digital conversion or ADC for short.
16F84 which is now very old does not have ADC but 16F877A does, so you can use that.

You will need a potentiometer or pot for short which is a variable resistor.
I would choose a value between 2K2 and 10K
You will need to add ADC component(within Inputs menu) in your flowchart.
That will add a knob to the control panel.
If you right click on the knob and select Ext properties, yo can change style of knob, add a label etc.
If you select View from the menu then chip you will seen on the chip diagram AN0, AN1 etc.
These are your analogue channels available.
You will need to right click on knob on the panel (analogue component ) then select connections to select correct ADC channel (AN0 to ANn).
ANn being the highest channel number.
If you look at the connection of the pot within the flowchart you can see it's connected to AN4
On the chip diagran you see that AN4 is on pin 7.
So wiper of pot connects to pin 7 of 16F877A

You will need to add the analogue component macro to the flowchart itself.
If you drag a component macro and double click on it
You just select ADC(0) then select if you want to ReadAsByte (value will be 0 to 255 = 0 to 5V) or ReadAsInt (value will be 0 to 1023 = 0 to 5V) :
Adding ADC1.png
(71.41 KiB) Downloaded 3077 times
The number within brackets is how many components you have added - 1 & not the analogue channel of microcontroller.
This allows you to select which component you would like to use.
For example you may have added two analogue components so you will have ADC(0) & ADC(1)

On your hardware. you will need to connect pot as follows:
Centre wiper on the analogue pin of the microcontroller.
Two outer pins of pot connect to the microcontroller supply (0 & 5V)
All the pot does is form a potential divider so voltage going on ADC pin can vary from 0 to 5V

When developing a flowchart it's always best to add variables to the variable watch window.
If you press F8 key once so it starts in single step mode.
Then right click in variable window, and select add variable.
Jut like normal windows explorer menu, you can click top variable (if multiple variables), hold shift, then click bottom variable.
Or you can just select variable your interested in.
Select OK
Now just single step by keep pressing F8. or you can slow simulation down to observe values.

Note the calculation

Code: Select all

Delay = Delay * 16 / 10 + 100 
use within the flowchart I posted just takes the digital value derived by ADC (0 to 255) and converts it in to a value suitable for a milliseconds delay (about 100 to just over 500)

Have a play with the flowcharts I have added.

One final thing.
Looking at your circuit you have left out 100nF caps which is always recommend to connect across the supply pins of microcontroller and on the voltage regulator.
If I was you I would look at the voltage regulator datasheet to confirm this.

Let me know how you get on.

Hope this helps

Martin

Re: Control speed of LEDs.

Posted: Mon Jun 08, 2015 2:26 pm
by hprane
Hi,

Thank you very much for your reply.

I read your reply and understood how to do it. Your step by step information really helped very much.
I'm going to use 16F88 as a replacement for 16F84. Then I can use it without changing my old circuits.

Also I checked about circuit and going to add that capacitors also. I think they are using for reduce noise. Am I right?
I have another question also. Can you guide me to fade a LED like this by step by step.
I saw it uses PWM. I studied about PWM. But I can't figure out how to apply it in Flowcode. Because I'm not a professional in Flowcode. I simply used it by normal commands by using if, outputs and calculations to turn lights on and off.

If we going to fade a LED and turn it again on how can we do it?
If we are going to use that method in a LED chaser like in my first uploaded code how do we apply it to fade a tail light and running like on this vide?

www.youtube.com/watch?v=zgpFC91MSVU

Very sorry if I'm asking lot of questions. I want to understand how to code these things in Flowcode. I read many threads in this forum. But still can't understand them. That's why I asked to guide through step by step.

Thank you.

Re: Control speed of LEDs.

Posted: Tue Jun 09, 2015 8:16 am
by medelec35
Hi hprane,
No problem.
Glad my post has helped.
There are are two main ways of controlling brightness of LED's and both involve PWM (Pulse Width Modulation)
One method is to use built in PWM component and the other is to bit bang which uses a timer interrupt to force port bit high and low at the correct times.
There will be plenty examples of both.
For example Bit bang PWM
If you want to try with PWM component then if you look in the learning centre there is Flowcode v5 Example - Components to download.
Check out 1. ADC Controlled PWM 16F88.fcf

I will see if I can get the chance this evening to put something together if you are still stuck.

Martin