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) :
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
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