CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

5 minutes timing without RTC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
soulraven



Joined: 08 Feb 2009
Posts: 72
Location: campulung muscel

View user's profile Send private message Send e-mail Yahoo Messenger

5 minutes timing without RTC
PostPosted: Fri Aug 13, 2010 4:55 am     Reply with quote

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.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 7:52 am     Reply with quote

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.
soulraven



Joined: 08 Feb 2009
Posts: 72
Location: campulung muscel

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Aug 13, 2010 8:09 am     Reply with quote

and how i do that? i am not verry good in C. Is need to use intrerupts?
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 8:19 am     Reply with quote

Have a read through these (2nd part can be found via Google)
http://ww1.microchip.com/downloads/en/DeviceDoc/51682A.pdf

And then read through the help sections and examples in CCS.

That should give you a good idea of how to approach it.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 8:31 am     Reply with quote

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.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 8:45 am     Reply with quote

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.
soulraven



Joined: 08 Feb 2009
Posts: 72
Location: campulung muscel

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Aug 13, 2010 8:55 am     Reply with quote

pls, do you have a example source code? something.....I am not very good in C programing...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 2:55 pm     Reply with quote

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().
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Sat Aug 14, 2010 8:12 am     Reply with quote

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.
soulraven



Joined: 08 Feb 2009
Posts: 72
Location: campulung muscel

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Tue Aug 17, 2010 12:32 am     Reply with quote

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
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 8:49 am     Reply with quote

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
soulraven



Joined: 08 Feb 2009
Posts: 72
Location: campulung muscel

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Tue Aug 17, 2010 9:01 am     Reply with quote

Yes, I know that. The question is, how I enable the timer when I want and when I want.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 10:51 am     Reply with quote

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
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 11:28 am     Reply with quote

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 $$.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Aug 17, 2010 12:58 pm     Reply with quote

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
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group