I need 30 min timer circuit using PIC

Thread Starter

EngineeringStudentTR

Joined Aug 17, 2017
8
Hello,

I need a circuit with the following characteristics:

- when a pushbutton is pressed a led will be on for exact 30min then it will be off
- if pushbutton is pressed when led is on, then the time(30 min) will start again.

I have not done anyting with PIC yet. But i think i can do it. Can anyone give me some information about how to do this circuit? Which pic i should use?

Thanks
 

WBahn

Joined Mar 31, 2012
29,978
About the only way you could meet your spec of "exact 30min" would be to use the atomic clock ensemble that defines the second.

Asking for anything that is a continuous quantity to be something exact is pretty much never achievable.

Now, perhaps you might take a moment to transform your desire (exactly 30 minutes) into a meaning specification of your needs (e.g., 30 minutes plus or minus 1 second). One way you can do this by asking yourself if someone gave you the circuit that you asked for by the time turned out to be some amount of time close to, but not exactly, 30 minutes would that be good enough. Then keep making the performance better or worse, as needed, until you find the edge of what is and what is not acceptable.
 

JohnInTX

Joined Jun 26, 2012
4,787
You can use pretty much any PIC but I would recommend one with interrupts and TIMER 2 with an external crystal oscillator for your required accuracy as opposed to an internal RC oscillator. Set up TIMER 2 / PR2 or free-run a different timer to get an interrupt that emits uniform tiks into a counter. Don't use a timer setup that requires reloading a timer. Count the tiks. By using an interrupt, you have time left over to process the switch.

Good luck!
 

ericgibbs

Joined Jan 29, 2010
18,766
hi,
Check out the DS3231 RTC module, with an onboard battery.
These RTC modules have a high degree of accuracy and have programmable alarms, these could be use to active the 30 minute period or you could use the 1Hz output to raise an Interrupt in the PIC.

E
 

Attachments

WBahn

Joined Mar 31, 2012
29,978
30 min and ± 1 sec is OK.
So that is an accuracy of about 0.05%, which pretty much rules out using any kind of external RC oscillator. I don't know about the accuracy specs of the internal oscillators, but I think some of the new ones are pretty decent. But depending on how much processing you need to perform, using a watch crystal is probably a good option (unless you go to the expense and complexity of using an RTC module, which you should probably at least consider. This becomes more attractive if your system has to operate over variations in supply voltage and temperature.
 

Thread Starter

EngineeringStudentTR

Joined Aug 17, 2017
8
I will use this circuit to prevent the tables in the libraries from being busy for more than 30 minutes. The longer the battery life is, the better. 2-3-4 AA battery is ok I guess
 

Thread Starter

EngineeringStudentTR

Joined Aug 17, 2017
8
I want to do i circuit like this one. The differences are
-no buzzer to allert. Instead of it, a led which is on for 30min will be off.
-no 7segment

It has only one button and a Led.
 

WBahn

Joined Mar 31, 2012
29,978
I will use this circuit to prevent the tables in the libraries from being busy for more than 30 minutes. The longer the battery life is, the better. 2-3-4 AA battery is ok I guess
And you need the timer to be within one second of thirty minutes for this task?

Somehow I doubt that being off by even a minute or so is going to be an issue. A slow RC oscillator will almost certainly be sufficient.

Are you going to have one of these at every table? In which case what prevents someone at the table from just hitting the button to reset the timer as often as they want?

Or are they all going to be back behind the circulation desk or someplace else where they will be monitored? In that case, why not just write a trivial little program in Python or Java or just about any other language to track this? You could have it be a simple console program or a fancy GUI program.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi EngStudent,
Forgive me if I sound blunt, but if you are going to be an Engineer, you will have to start putting more commitment into your project specification.
The longer the battery life is, the better. 2-3-4 AA battery is ok I guess
does not meet that criteria.

Eric
 

Thread Starter

EngineeringStudentTR

Joined Aug 17, 2017
8
And you need the timer to be within one second of thirty minutes for this task?

Somehow I doubt that being off by even a minute or so is going to be an issue. A slow RC oscillator will almost certainly be sufficient.

Are you going to have one of these at every table? In which case what prevents someone at the table from just hitting the button to reset the timer as often as they want?

Or are they all going to be back behind the circulation desk or someplace else where they will be monitored? In that case, why not just write a trivial little program in Python or Java or just about any other language to track this? You could have it be a simple console program or a fancy GUI program.

When they left the table with their stuff, they push the button and for 30 min someone cannot sit that place. If they come in 30 min and push the button and they left again it is ok. If no stuff on desk, it is empty, if there are some stuff the desk is reserved for 30 min.
At every table I use this circuit. And also tables are for 4 people. If I can do the circuit for one person then I will upgrade it for 4 people in one circuit.
 

WBahn

Joined Mar 31, 2012
29,978
Think of your criteria as needing to be things that a customer can pay a high school student to check and either say 'yes' or 'no' to the question of whether it meets spec.

Spec: Long battery life.
Test result: It lasted two weeks.
Student: Meets spec -- uhh.... I don't know.

Spec: Lasts a minimum of three weeks.
Test result: It lasted two weeks.
Student: Meets spec -- NO

The "2-3-4 AA battery is ok I guess" is not a problem, but would be better worded as something like: Requiring up to 4 AA batteries is acceptable.
 

WBahn

Joined Mar 31, 2012
29,978
When they left the table with their stuff, they push the button and for 30 min someone cannot sit that place. If they come in 30 min and push the button and they left again it is ok. If no stuff on desk, it is empty, if there are some stuff the desk is reserved for 30 min.
At every table I use this circuit. And also tables are for 4 people. If I can do the circuit for one person then I will upgrade it for 4 people in one circuit.
That gives a better idea of what you are trying to achieve.

I don't know how practical your solution is. If someone goes off an leaves their stuff at an empty desk then it would seem like they are asking for their stuff to disappear (though, yes, that's a different problem). But what if the 30 minutes expires? Their stuff is still on the table. Does someone else that sees the light off have to come get some staff member to remove the person's stuff? Are the times when no free seats are available anywhere in the library really common enough to justify the expense of putting a system like this at every table? How often do people go off and leave their stuff unattended for thirty minutes?
 

Thread Starter

EngineeringStudentTR

Joined Aug 17, 2017
8
Excuse my ignorance. I am not good at English.
I found a list of pic's. I want to use a pic as much as cheaper and appropriate to my aim.
http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1002


I don't know how practical your solution is. If someone goes off an leaves their stuff at an empty desk then it would seem like they are asking for their stuff to disappear (though, yes, that's a different problem). But what if the 30 minutes expires? Their stuff is still on the table. Does someone else that sees the light off have to come get some staff member to remove the person's stuff? Are the times when no free seats are available anywhere in the library really common enough to justify the expense of putting a system like this at every table? How often do people go off and leave their stuff unattended for thirty minutes?
After 30 min another student can come when no free seats are available anywhere in the library. He/she sees the led is off and pushes the stuff to the edge, sits, studies. When the owner of stuff come, he/she get his/her stuff and try to find another table. Stuff does not disappear because there are security cameras.
 

JohnInTX

Joined Jun 26, 2012
4,787
So if it is to be battery operated, power consumption is a big factor. To minimize power consumption:

Run the system clock at the slowest speed you can. Consider a watch crystal 32.768KHz for the main oscillator. That won't give you much processing speed but you don't need any. That frequency will divide nicely into 1 second tiks.
Consider flashing the LED when it is running - it will give the same 'ON' indication but at less power. Change the output when you service the timer interrupt.
Sleep the processor when it is not timing. Wake it up when the button is pushed by using a 'wake on change' pin (usually available on PORTB) or an external interrupt pin.
Sleep the processor between timer interrupts. There's no sense burning power when there is nothing else to do.
Use one of the Nano-Watt or XLP series of PICs that will keep a timer running when the processor is sleeping.
You might want to revisit the need for 1 sec accuracy in a 30 minute timer. If you can go with a looser time spec, you can use the internal oscillator (usually good to about 1%, ~18 seconds out of 30 minutes.). That would save cost, pins and power (some PICs have an internal 31KHz low power oscillator).
Turn off everything - timers, BrownOut detector etc. that aren't absolutely necessary.

So far, you only have 1 input (the button) and 1 output (the LED). Anything else? Sounds like an 8 pin might work. Make a list of IO and functionality - a block diagram and a flowchart would be a good start. That way you can determine what features the PIC needs. Take a look at the 12LF1840 (for example) 8 pins. 2 for an external XTAL if required. 1 INT pin for the button. 1 pin for the output. 2 for ICSP/debug. Enough memory to program in XC8 free mode. XLP low power features galore. There are lots of others that will do the job but I've used that particular part and like it.
 
Last edited:

Thread Starter

EngineeringStudentTR

Joined Aug 17, 2017
8
So if it is to be battery operated, power consumption is a big factor. To minimize power consumption:

Run the system clock at the slowest speed you can. Consider a watch crystal 32.768KHz for the main oscillator. That won't give you much processing speed but you don't need any. That frequency will divide nicely into 1 second tiks.
Consider flashing the LED when it is running - it will give the same 'ON' indication but at less power. Change the output when you service the timer interrupt.
Sleep the processor when it is not timing. Wake it up when the button is pushed by using a 'wake on change' pin (usually available on PORTB) or an external interrupt pin.
Sleep the processor between timer interrupts. There's no sense burning power when there is nothing else to do.
Use one of the Nano-Watt or XLP series of PICs that will keep a timer running when the processor is sleeping.
You might want to revisit the need for 1 sec accuracy in a 30 minute timer. If you can go with a looser time spec, you can use the internal oscillator (usually good to about 1%, ~18 seconds out of 30 minutes.). That would save cost, pins and power (some PICs have an internal 31KHz low power oscillator).

So far, you only have 1 input (the button) and 1 output (the LED). Anything else? Sounds like an 8 pin might work. Make a list of IO and functionality - a block diagram and a flowchart would be a good start. That way you can determine what features the PIC needs. Take a look at the 12LF1840 (for example) 8 pins. 2 for an external XTAL if required. 1 INT pin for the button. 1 pin for the output. 2 for ICSP/debug. Enough memory to program in XC8 free mode. XLP low power features galore. There are lots of others that will do the job but I've used that particular part and like it.
Thanks a lot. This was very helpful.
 
Top