Page 1 of 1

Project problem

Posted: Wed Feb 03, 2010 4:28 pm
by erwan
I am hoping someone will help me on this.

I was asked to do a simple counter. I am using one switch (input), 3 green led (reset output) and 1 red led (warning output). The desired outputs are when I push the switch once, the first led will be on for only three seconds. The same thing will happen again for the second and third led when I push the switch for the second and third time. When I push the switch for the fourth time, I want the red led to turn on permanently as a warning sign and stop the program.

The problem is I can't make the green led to turn off because the loop will repeat itself and the green led will be blinking. I'm using Flowcode 3.2.2.40, 16F88, clock speed 3276800 and one interrupt macro. My calculation is cal= cal + 1 for one cycle of the loop and the program will stop when cal = 4.

I am really desperately need of help on this one.

Please check the file and let me know what's wrong.

Re: Project problem

Posted: Wed Feb 03, 2010 4:32 pm
by Benj
Hello

Sounds like you need some more decision icons in your program.

eg

decision: cal = 1
yes: switch on led 1

decision: cal = 2
yes:switch on led 2 switch off led 1

etc...

Re: Project problem

Posted: Wed Feb 03, 2010 4:37 pm
by erwan
Thanks for the suggestion.

I already did that part but still I can't figure out how to make it right. Please see the program and see how you can help me.

Thanks

Re: Project problem

Posted: Wed Feb 03, 2010 4:46 pm
by Benj
Hello

Ok I see the problem.

You are outputting a value to a pin on porta and then straight away afterwards you are writing 0 to all of porta which is clearing the original bit that you set. Maybe swap the port output with the single pin output and that should fix the problem.

You are also outputting the count variable to the porta pin. I would change this to a 1 as the count value is changing during the operation of the program.

Re: Project problem

Posted: Wed Feb 03, 2010 5:08 pm
by erwan
Thanks, that cleared some of the problem.

However I still face problems with the blinking led. I need the led to be on for only 3 seconds and the next one will on when I pressed the switch. I guess the cause is the endless looping unless I press the switch. Any idea on how to do that?

Here Γ­s what I've done based on what you recommend.

Re: Project problem

Posted: Wed Feb 03, 2010 5:24 pm
by Benj
Hello

Ok now you are outputting a 1 and then straight away outputting a 0.

I would instead do this.

count = 1
Yes: 1 -> A0

count = 2
Yes: 0 -> A0
Yes: 1 -> A1

count = 3
Yes: 0 -> A1
Yes: 1 -> A2

etc

This should stop the LEDs from flashing on and off.

Re: Project problem

Posted: Wed Feb 03, 2010 5:40 pm
by erwan
Hi.

Thanks a lot for your solution. However I still can't turn off the led after three second. Any idea on how to do that? I tried using delay but I can't figure out where to put it. The desired output is green led on for only three second and off automatically and the process is repeated when I press the switch.

I know I look desperate but I just can't get it right. I really appreciate what you did.

Re: Project problem

Posted: Wed Feb 03, 2010 8:21 pm
by medelec35
Hope this helps.
Each green LED is only on for 3 seconds.
This is how I did it.
When you press the switch, as soon as interrupt is accessed, 1 is added to count then it sets and Time_Out Variable is reset to 0.
Only if Time_Out Variable = 0 the decision branch containing green LED is accessed. Led is lit until delay of 3 seconds has elapsed, then Time_Out Variable is set to 1. This means the Green LED can't be reactivated And all is repeated when button is pressed again.

Re: Project problem

Posted: Wed Feb 03, 2010 11:58 pm
by erwan
Hi.

Wow! Thank you very much. I owe you big time on this one. I'm really glad I join this forum and knowing you guys.

Best regards.

Re: Project problem

Posted: Thu Feb 04, 2010 6:20 am
by medelec35
Your welcome.
Thank you for letting us know.
Just glad your happy with the end result.