PIC18F4550 timer programming>> need help!

Thread Starter

yvonnezoe

Joined Oct 30, 2008
8
hello !:)
i'm a student currently studying MicroController Technology. i am doing a project that requires timer that counts up to 40 minutes and trigger some vibrators. then the timer can be reset once a certain puch button is deactivated. another 3 minutes timer is required for tha same PIC board too.
so, here are my problems:
1. how to write the codes for configuring the timer?
2. how to calculate the exact timing of 40 minutes (or 3 minutes) for the PIC? i have read through the notes given by lecturer, but i still can't figure them out. the notes aren't useful at all. can anyone suggest me where to get better info ( ebook etc)
3. how to reset the timer to 0?

there might be more questions when i start programming my project though... =( i hope someone can help me to solve this. X[ i'm really stress!!
 

AlexR

Joined Jan 16, 2008
732
The answer is to use timers and interrupts.

Obviously none of the timers can count up to 3 minutes but you can set up a 16 bit timer to give you a periodical interrupt, the period will depend on your clock frequency but you should be able to achieve somewhere between 100mSec and 1 Sec.

If the timer period is set so that it can be evenly divided into 1 second then all you have to do is set up some variables to hold minutes, seconds and milliseconds (if necessary) which you can increment in the interrupt routine.
 

Thread Starter

yvonnezoe

Joined Oct 30, 2008
8
The answer is to use timers and interrupts.

Obviously none of the timers can count up to 3 minutes but you can set up a 16 bit timer to give you a periodical interrupt, the period will depend on your clock frequency but you should be able to achieve somewhere between 100mSec and 1 Sec.

If the timer period is set so that it can be evenly divided into 1 second then all you have to do is set up some variables to hold minutes, seconds and milliseconds (if necessary) which you can increment in the interrupt routine.
thank you so much for your reply.:)
however... i do not understand well for what you've explained. well, i haven't learn timer and interrupt in school but my project requires them. =(
so, do you mean that it's really impossible to configure the timer to count up to 40 or 3 minutes?

btw, i'm using MPLAB IDE to write the programmes.
 

AlexR

Joined Jan 16, 2008
732
There are many ways to do delays in a PIC. The timer/interrupt method is the most efficient since it allows you to do other things while the timers do their work but if you haven't covered timers and interrupts yet, you will have to do it with delay loops.

Take a look at http://www.massmind.org/techref/microchip/delay/general.htm and read up on delay loops. For your longer delays you will need to use nested delay loops.

For a more detailed look at delay loops including a good explanation on how to work out your timing see http://www.piclist.com/techref/microchip/PIC16DelayTutorial.htm

You can also find lots of useful info about delays and timing at http://www.massmind.org/techref/microchip/delays.htm
 

Thread Starter

yvonnezoe

Joined Oct 30, 2008
8
There are many ways to do delays in a PIC. The timer/interrupt method is the most efficient since it allows you to do other things while the timers do their work but if you haven't covered timers and interrupts yet, you will have to do it with delay loops.

Take a look at http://www.massmind.org/techref/microchip/delay/general.htm and read up on delay loops. For your longer delays you will need to use nested delay loops.

For a more detailed look at delay loops including a good explanation on how to work out your timing see http://www.piclist.com/techref/microchip/PIC16DelayTutorial.htm

You can also find lots of useful info about delays and timing at http://www.massmind.org/techref/microchip/delays.htm
thank you so much for your reply and all those links. i'll read them up and try to understand. :)
thanks again! have a nice day.:D
 

Thread Starter

yvonnezoe

Joined Oct 30, 2008
8
There are many ways to do delays in a PIC. The timer/interrupt method is the most efficient since it allows you to do other things while the timers do their work but if you haven't covered timers and interrupts yet, you will have to do it with delay loops.

Take a look at http://www.massmind.org/techref/microchip/delay/general.htm and read up on delay loops. For your longer delays you will need to use nested delay loops.

For a more detailed look at delay loops including a good explanation on how to work out your timing see http://www.piclist.com/techref/microchip/PIC16DelayTutorial.htm

You can also find lots of useful info about delays and timing at http://www.massmind.org/techref/microchip/delays.htm
btw, i have thought about this for a night... but i don't know whether it works or not.
i was thinking of using the PIC to count up and display the numbers on 2 7-segments led displays. so when the number is "40", it will triggers my project to do the things...
and instead of 40 minutes ( and another 3 minutes), i planned to change it to 40 seconds ( and 3 seconds), as i only need to do a prototype and demonstrate it to my lecturer (and 40 minutes might be too long for him to wait.. haha)
so, what do you think? will this way be more workable? :confused:
thanks again for your time. =D
 
Top