View previous topic :: View next topic |
Author |
Message |
soulraven
Joined: 08 Feb 2009 Posts: 72 Location: campulung muscel
|
5 minutes timing without RTC |
Posted: Fri Aug 13, 2010 4:55 am |
|
|
Hi, is any solution for counting time, like 5 minutes without using RTC? and is it possible in this time to make another application to run?
I have this project
Ibutton identifier for car security.
IF Ibutton is connected confirm the TAG with beep sound and activate 1 PIN with logic state 1, after that if the motor is started keep the pin state, is not after 5 minutes change the pin state to 0. When the motor is stop change the pin state to 0. |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Aug 13, 2010 7:52 am |
|
|
5 minutes is 300 seconds. If you have a interrupt or polling loop every 2 seconds, when it counts 150 loops then 5 minutes has passed. Scale the numbers for whatever interrupt or loop you have. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
soulraven
Joined: 08 Feb 2009 Posts: 72 Location: campulung muscel
|
|
Posted: Fri Aug 13, 2010 8:09 am |
|
|
and how i do that? i am not verry good in C. Is need to use intrerupts? |
|
![](templates/subSilver/images/spacer.gif) |
Geps
Joined: 05 Jul 2010 Posts: 129
|
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Aug 13, 2010 8:31 am |
|
|
soulraven wrote: | and how i do that? i am not verry good in C. Is need to use intrerupts? |
Most uC programs have some repeated cycle of tasks that loops forever, often called a paced loop. Generally it is of the form:
1) check inputs
2) set outputs
3) wait until it is time to repeat
4) start again at #1
If this loop takes 2 seconds, and you count 150 times through the loop, then 5 minutes have passed. If the loop only takes 0.02 seconds you need to count to 15000 loops for the same 5 minutes. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Fri Aug 13, 2010 8:45 am |
|
|
No, you don't need to use interrupts, especially if the timer is set to give long intervals. Just have your main() routine poll the interrupt flag that's controlled by the timer; if found to be set, clear it and increment a counter, and when the counter reaches the appropriate level (based on how many timer intervals make up your 5-minute period) do whatever you do when the time runs out.
Note that the interrupt flag gets set regardless of whether the processor is programmed to respond to it, and you can just go and look at it whenever you want. You have to remember to clear it if it's set, though.
The one thing to beware of is that you mustn't send the processor off into some very long routine that will cause testing of the flag to be missed. If this happens, your 5 minutes will be stretched. |
|
![](templates/subSilver/images/spacer.gif) |
soulraven
Joined: 08 Feb 2009 Posts: 72 Location: campulung muscel
|
|
Posted: Fri Aug 13, 2010 8:55 am |
|
|
pls, do you have a example source code? something.....I am not very good in C programing... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 13, 2010 2:55 pm |
|
|
Look at this CCS example file. It uses Timer1 interrupts to increment
a global 'seconds' variable. You can modify this to do what you need.
Quote: | c:\program files\picc\examples\ex_stwt1.c |
They use an int8 to count seconds, so it can only count up to 255.
You want 300 seconds, so you need to change it to an int16. When it
counts up to 300, then set a global flag variable = TRUE (inside the isr)
to indicate that your timeout has occurred. Check the flag in main(). |
|
![](templates/subSilver/images/spacer.gif) |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Sat Aug 14, 2010 8:12 am |
|
|
The example PCM programmer listed was based on having the CCS material on your computer in the expected place, but there's also this on the CCS website:
http://www.ccsinfo.com/content.php?page=compexamples#seconds
It actually does use interrupts, which isn't the only way to do the job but it's the way most people would do it. |
|
![](templates/subSilver/images/spacer.gif) |
soulraven
Joined: 08 Feb 2009 Posts: 72 Location: campulung muscel
|
|
Posted: Tue Aug 17, 2010 12:32 am |
|
|
I continue the question...
I am not very good in C and programing. I need that the timer will be activated on some action.
The project is like that:
I use 1wire ibutton.
When ibutton is connected, if is the right one, 1 pin from PIC is HIGH for 5 minutes. If in this interval another pin is not changed from low to high the first pin goes to LOW. If is connected the first pin stay in HIGH until the second PIN goes to LOW. Then the circle repeats.
ibutton, 1 pin to HIGH for 5 minutes...
Sorry for my bad english |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Tue Aug 17, 2010 8:49 am |
|
|
SoulRaven,
You are going to have to do some homework yourself.
People have pointed you to working examples and explained how to accomplish your task in several ways.
If you are not good at C, then here's your chance to learn as you'll find no one will want to do your project for you.
But we are all glad to help when you get stuck.
Good Luck!
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
soulraven
Joined: 08 Feb 2009 Posts: 72 Location: campulung muscel
|
|
Posted: Tue Aug 17, 2010 9:01 am |
|
|
Yes, I know that. The question is, how I enable the timer when I want and when I want. |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Tue Aug 17, 2010 10:51 am |
|
|
soulraven wrote: | Yes, I know that. The question is, how I enable the timer when I want and when I want. |
Depends on how you write your code.
You could have a timer free-wheeling ticks and have some flag that turns on and off controlling the rest of your code...
You could use a counter and just enable-disable that counter.
you could turn on/off the timer interrupt
There's lots of ways.
All depends on what you want, the circuit you designed based on that and how you want to implement the software.
Because your question is so generic any responses have to be as well. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Tue Aug 17, 2010 11:28 am |
|
|
Would it be too rude to suggest hiring a programmer?
You don't seem to want to study and learn a bit so that you can ask very specific questions. You just want a solution created for you - that's what programmers do...for $$. |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Tue Aug 17, 2010 12:58 pm |
|
|
pmuldoon wrote: | Would it be too rude to suggest hiring a programmer?
You don't seem to want to study and learn a bit so that you can ask very specific questions. You just want a solution created for you - that's what programmers do...for $$. |
Heck ya! I'll do it! My oscilloscope has been kinda bored lately.
![Laughing](images/smiles/icon_lol.gif) _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
|