Simple pulse input counter

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
jbs4wd
Posts: 46
Joined: Thu Dec 03, 2009 7:29 am
Has thanked: 4 times
Contact:

Simple pulse input counter

Post by jbs4wd »

I am having trouble getting this code to work in real life. Using 16f690
It's just a simple counter. Where it detects a pulse on A5, when the count gets to 50, turns an LED on, when the count gets to 100, turns that LED off and turn LED2 on. when it reaches 150 LED1 on, 200 LED1 off LED2 & 3 on etc.
Works on on PC but on my board, no go.
Any sugections please, I may be looking too deep into it.

Cheers
JOHN
Attachments
pulse counter.fcf
(17 KiB) Downloaded 304 times

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

Re: Simple pulse input counter

Post by medelec35 »

Hi John,

Since osc is at 10MHz I would assume you are using a crystal osc?
I would change external RC to HS.
Also your timer interrupt frequency is 9.7 KHz. This means while the switch is pressed in, count = count+1
is accessed and incremented every 100 microseconds until timer0 is disabled. This will happen quiet a few times within 10ms, so count variable is going to keep rolling over producing what looks like random counts. It will work on your simulator since timer0 is not accessed every 100uS on the simulator.
just remove timer0 and place count = count+1 just below waituntilhigh. Only reason for keeping timer0 is to count duration ( not amount of times) of switch pressed.
Perhaps if you give a more detailed description of your objective since you not mentioned a timing period, we can help you achieve that.
If you are not using Eblocks, then Pin 4 of chip will need to be pulled high if you keep master clear enable on External.

I would recommend turning off watchdog timer, until you are happy that program works..it removes watchdog time out issues, if program does not work.
Finally the update macro will never be accessed.

You could think about either polling i/p or using port interrupt for switch detection. With the latter you won't be able to use A5.

Hope this helps

Martin

Martin
Martin

Post Reply