Timer

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Timer

Postby wjwong » Sat Oct 29, 2011 10:35 pm

i am stuck on how to ON my project every 1hour?
Hope for some clue.....
wjwong
Novice
 
Posts: 19
Joined: Sat Oct 29, 2011 9:35 pm

Re: Timer

Postby low5545 » Sun Oct 30, 2011 12:06 pm

first you need a microcontroller.
low5545
Discoverer
 
Posts: 70
Joined: Wed Jul 27, 2011 5:55 pm
Location: Kuala Lumpur

Re: Timer

Postby shahrul » Mon Oct 31, 2011 12:39 am

For timing, I think you need RTC. This is suitable design.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Timer

Postby wjwong » Mon Oct 31, 2011 2:49 pm

i thinking of doing 60s delay and looping 6o times is that possible? RTC is a burden to add on to my project instead i choose timer 555 and decade counter as hardware control.

60s Delay with PIC16F877A 20MHz
is there any example for delay program and looping?
wjwong
Novice
 
Posts: 19
Joined: Sat Oct 29, 2011 9:35 pm

Re: Timer

Postby shahrul » Mon Oct 31, 2011 3:22 pm

RTC is very easy, if you know.
Easily can program what to do for every hour.

For delay, you can use
CODE: SELECT_ALL_CODE
for(i=0;i<3600;i++) __delay_ms(1000); //delay 1 hour
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Timer

Postby sich » Mon Oct 31, 2011 5:06 pm

Shahrul is right that using the RTC is really simple. You can refer to this DIY project.

If you're using delay to get the time, the error will increase over time. Moreover, you can't do anything while the delay is counting...it means that within the one hour, your system is just working on the delay loop and nothing productive can be done.

Timer interrupt is more advisable to be used compared to delay function, if you don't want to use the RTC chip. Some microcontroller also has RTC module built-in. You can have a look in Microchip's product tree too.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 604
Joined: Tue Apr 21, 2009 2:15 pm

Re: Timer

Postby wjwong » Mon Oct 31, 2011 11:14 pm

Thanks for the advise. Yeap i am considering and going to start study on it.

RTC capable to trigger my project every 1 hour? Just slightly confirmation. :o
Anyways thanks alot
wjwong
Novice
 
Posts: 19
Joined: Sat Oct 29, 2011 9:35 pm

Re: Timer

Postby sich » Tue Nov 01, 2011 9:51 am

wjwong WROTE:RTC capable to trigger my project every 1 hour? Just slightly confirmation.

RTC keeps the time and your program will need to retrieve the current time from the RTC. So it's your program which triggers certain function when the time is up.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 604
Joined: Tue Apr 21, 2009 2:15 pm

Re: Timer

Postby yonghui » Wed Nov 02, 2011 8:39 pm

RTC is real time clock, for sure it can do the task.

if no precise timing is required, __delay_ms() with Hitech compiler can do the task.
or else u can use the available timers in the PIC to do counting and keep accumulating the time in a variable. and compared it while loop to trigger hourly.

if u have microcontroller which has the internal RTC like new PIC18F u can use the function in RTC to generate interrupt to wake and trigger.

regards,
yh
thanks&regards,
yh
yonghui
Professional
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Timer

Postby ABSF » Thu Nov 03, 2011 9:14 am

wjwong WROTE:i thinking of doing 60s delay and looping 6o times is that possible? RTC is a burden to add on to my project instead i choose timer 555 and decade counter as hardware control.

60s Delay with PIC16F877A 20MHz
is there any example for delay program and looping?


It's not so easy and not accurate to generate 60 second pulses using 555 timer. You may generate shorter duration pulses and further divide them down using counters like 4020, 4040 or 4060 (dont need 555 as there is a built in osc). You can even cascade the 4040 to make longer chain of dividers to finally get 3600 second pulse. connect the out put to one of the RB ports (IIRC) which has edge trigger function. It can trigger an interrupt when it senses H-L or L-H edge.

Or just set up the 555 to generate 1 second pulse and connect it to RB0. On every pulse let there be an interrupt (has to setup the SFR properly). Set up two counters (CountH and countL)to increment the pulses in the ISR() till it reaches 3600 then set the variable One_Hour_Flag high. Your main routine would poll this flag to see if time is up to start up your project.

Or you can even do the above without the 555 timer. Just use the 16-bit TMR1 inside the PIC. Refer to this link to see how to do it

viewtopic.php?f=21&t=10676&p=13420&hilit=interrupt#p13420

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 1 guest

cron