Timers/countdown and what Pots to use

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
F22-Raptor
Posts: 13
Joined: Fri Nov 20, 2009 2:58 pm

Timers/countdown and what Pots to use

Post by F22-Raptor »

I'm trying to come up with a way to implement two countdown timers and I have a hard time figuring out what the best way is to go about it.

The idea is to have 1 timer counting down from say max 90 minutes to min 5 minutes and then close a relay or switch on a transistor, the 2nd timer will countdown from say max 180 mins to min 5 mins. The user will have the option to switch between normal mode (90-5 mins range) and extended mode (180-5 mins range).
To set the number of minutes to countdown from the device will have 2 potentiometers (normal mode and extended).

What I struggle with is the code for this. How does one create a countdown for periods this long and what value should I use for my pots?
The countdown doesn't need to be extremely precise, +/- 30 seconds is acceptable.
If it's not too much to ask, what's the best way to display the countdown on an LCD? I'm not talking about using the LCD macros but showing 16 (minutes) instead of whatever the counter is at at that time (e.g. 23067).
The other requirement is to read the set time all the time, for example if the initial countdown was say 45 mins, the countdown is now at 30 mins but now the user changes the countdown to 10 mins, the 10 mins should become the new countdown from setting.

I know medelec35 has posted some timing code here: http://www.matrixmultimedia.com/mmforum ... 294#p16294 but I just can't wrap my head around it.

BTW, during the count down, the PIC should still be able to receive commands from buttons like Reset (not the PIC reset), turn on a alarm, etc. While I'm on this topic, any suggestion re. a CO sensor I can use with the 16F877A?

Thanks

D.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Timers/countdown and what Pots to use

Post by Benj »

Hello

The best approach is probably to use a timer interrupt to do the timing and counting down.

You should be able to set up and interrupt using CLKO (timer0) and a prescaler that gives you a whole number.

The in your interrupt service routine count up to this number and this will give you a solid second timing.

If you have reached the second number then reset this and decrement your second variable.

If the second variable has reached 60 then reset this and decrement your minute variable.

You should then be able to print out the minute variable on the LCD.

There are a lot of timer interrupt examples out there on the forum and in the main examples pack that should help to get you started.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Timers/countdown and what Pots to use

Post by Benj »

We also sell a CO2 sensor that is compatible with our Sensors E-Block.

http://www.matrixmultimedia.com/product ... PHPSESSID=

F22-Raptor
Posts: 13
Joined: Fri Nov 20, 2009 2:58 pm

Re: Timers/countdown and what Pots to use

Post by F22-Raptor »

Thanks Ben.

The CO2 sensor is way to much, plus I need a CO not a CO2.

D.

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

Re: Timers/countdown and what Pots to use

Post by medelec35 »

If you post some details of osc speed so I can set timer0 to count in seconds. I won't have time to do it all, so you will need to do modifications.
I will do the display and count down part. I will add note on flowchart to help you understand how it works.
Martin

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

Re: Timers/countdown and what Pots to use

Post by medelec35 »

Here is a good start for you. This version is simplified compared to miac and counts down both timers, one at a time and changes LED to show which timer is active.
Hint: If I was you, I would have a routine to read pot and check for changes 1st. no changes then time stays set as it is.
Dual_Countdown0.jpg
Dual_Countdown0.jpg (6.2 KiB) Viewed 5912 times
Dual_Countdown1.jpg
Dual_Countdown1.jpg (5.88 KiB) Viewed 5912 times
Attachments
dual_countdown1.fcf
(17.53 KiB) Downloaded 408 times
Martin

F22-Raptor
Posts: 13
Joined: Fri Nov 20, 2009 2:58 pm

Re: Timers/countdown and what Pots to use

Post by F22-Raptor »

That is geat, thank you so much for your help.

I'll be using a 20MHz crystal.

Thanks again.


D.

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

Re: Timers/countdown and what Pots to use

Post by medelec35 »

Your welcome.
Also did you want it to count down using the the format in minutes e.g. 180,179,176...etc. Or is the way I have posted OK, i.e for 180 mins = 03:00:00 , 02:59:59 etc?
Martin

F22-Raptor
Posts: 13
Joined: Fri Nov 20, 2009 2:58 pm

Re: Timers/countdown and what Pots to use

Post by F22-Raptor »

The way you posted is fine for what I need but there might be other people intersted in displaying minutes. I guess if you are bored one day you can post that as well or give some hints as to how it's done.

You have already done more than I expected for me. I really really appreciate your help and your contribution on this forum.

D.

Post Reply