PIC18F4550 timer programming>> need help!

Discussion in 'Embedded Systems and Microcontrollers' started by yvonnezoe, Jun 8, 2009.

  1. yvonnezoe

    Thread Starter New Member

    Oct 30, 2008
    8
    0
    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!!
     
  2. yvonnezoe

    Thread Starter New Member

    Oct 30, 2008
    8
    0
    can someone please reply to my post? :(
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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.
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
  5. yvonnezoe

    Thread Starter New Member

    Oct 30, 2008
    8
    0
    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.
     
  6. yvonnezoe

    Thread Starter New Member

    Oct 30, 2008
    8
    0
  7. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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
     
  8. yvonnezoe

    Thread Starter New Member

    Oct 30, 2008
    8
    0
    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
     
  9. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    CCS is a compiler which compiles programs written in C for PIC microcontrollers.
     
  10. yvonnezoe

    Thread Starter New Member

    Oct 30, 2008
    8
    0
    oh... ok.
    thank you for your info!! :)
     
  11. yvonnezoe

    Thread Starter New Member

    Oct 30, 2008
    8
    0
    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
     
Loading...