Cant get switch to work?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Cant get switch to work?

Post by JDR04 »

I'm hoping somebody will be able to point out where I have gone wrong.

All I am trying to achieve is when SW1 makes PIN 5 go HIGH, the program runs and the two led's flash twice together. I'm using a 16F688 PIC. Is it possibly something to do with shorting Vdd and PIN 5 together is not working? If it is, I really would appreciate somebody showIng me a better way of doing this.

I've attached datasheet, schematic and flowchart.

Thanks a lot......JDR04
Attachments
16F688 DATASHEET.pdf
(3.57 MiB) Downloaded 252 times
LDDD 2.fcf
(8.5 KiB) Downloaded 235 times
Circuit 1 Jpeg.jpg
Circuit 1 Jpeg.jpg (11.88 KiB) Viewed 3881 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Cant get switch to work?

Post by medelec35 »

Hi John,
You will need a pull-down resistor (e.g, between 2K2 & 10K) connected between i/p pin and 0V.
Without a pull-down resistor the i/p pin will be floating.
Due to the high i/p resistance of the i/p pin, if left floating then it will randomly change state from loging 0 to logic 1 or even stay at logic 1 depending on surrounding electrical fields/noise being induced onto the i/p pin.

Looking at your flowchart, the switch will only operate once.
Is that what you indented to happen?
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Cant get switch to work?

Post by JDR04 »

Hi Martin, thanks for that.

Is the purpose of using the suggested resistor to make sure that when the pin is LOW, there is no voltage on it whatsoever? I did measure about 0.5V on the pin when the switch was in the OFF position.

So if I have say an OUTPUT PIN that also sits with some voltage on it when "NOT HIGH" I should apply the same principle?

Thanks a lot....John

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Cant get switch to work?

Post by medelec35 »

Hi John,
JDR04 wrote:Is the purpose of using the suggested resistor to make sure that when the pin is LOW, there is no voltage on it whatsoever?
Yes the purpose is to ensure that the i/p pin does not float and stays as near to 0V as possible if switch is open circuit.
JDR04 wrote:So if I have say an OUTPUT PIN that also sits with some voltage on it when "NOT HIGH" I should apply the same principle?
No not at all.
pull-down & pull-up resistors only apply to high resistance/impedance inputs and not to output which had a low resistance so its not affected in the same way by electromagnetic fields.

There is one exception with an output.
Only if it is classed as open collector or open drain. Then you must have a pull-up load or resistor.
If its a TTL output which is the case of all the pins on your device, then no resistor is required.

The is one more issue and that is you have got the internal osc set to 20000000 (20MHz)
Internal osc is not like the external osc i.e you can't just connect a crystal within range and it will run at the frequency.

If you look at page 22 of the data sheet, you will see that the internal osc can be set to run at the following frequencies (within green box):
setting int osc.png
(47.71 KiB) Downloaded 2400 times
This is done by setting osccon register value depending on required frequency.
The same frequency must be set for the target clock speed within flowcode.
for example if you want internal osc to run at 8MHZ you must add a c code box at the very start of main with

Code: Select all

osccon=0x70;
How I derived at that value was shown here
You must also change target clock speed to 8000000
If you look at the data sheet it shows 4MHz as the default.
This means you will not have to use a c code box with an osccon value if 4MHz internal osc is required.

Martin
Martin

Post Reply