Adjustable timer with PIC 16F

Discussion in 'Embedded Systems and Microcontrollers' started by Tiago NET, Mar 13, 2018.

  1. Tiago NET

    Thread Starter New Member

    Oct 27, 2015
    3
    0
    Hello,

    Need a code for adjustable timer using PIC 16F628A or 16F877A (have 16F877A on my house, but, 16F628A is easy to find and buy).
    This timer maybe count 1 minute to 20 minutes and have a 16x2 LCD display with start/stop, up and down buttons for select time desired.
    Thanks for help!
     
  2. jpanhalt

    Expert

    Jan 18, 2008
    6,197
    1,126
    At what frequency is the chip operating. How far have you gotten in the assignment? What programming language?
     
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    15,514
    4,515
  4. Tiago NET

    Thread Starter New Member

    Oct 27, 2015
    3
    0
    Frequency is 4MHz. I've using IDE MIKROC PRO FOR PIC
     
  5. jpanhalt

    Expert

    Jan 18, 2008
    6,197
    1,126
    I can't help with that language. One easy way would be to use a 32,768 kHz crystal for your timers.

    Slightly more difficult (depending on your point of view) would be to use TMR0 and TMR1 with their prescalers. Twenty minutes is 1.2X10^9 microseconds. At 4 MHz, your instruction cycle is 1 us. At a maximum, TMR0 is a 15-bit timer (i.e., 8-bit timer and up to 7-bit prescale); TMR1 is a 19-bit timer (i.e., 16-bit timer and up to 3-bit prescale). So applying that simple analysis gives you 34-bits or 1.7x10^10 counts. You could even go much higher by using registers to keep track or rollovers. For example, a pair of H/L registers will give 16 more bits.

    Working out the details is something you can do, as you will need to know the resolution needed. For example, a timer that gave one count/min could be built, but your assignment may want 1-sec resolution or better. I would not go for more precision than required. If it is 1-sec, for example, you might make a 1-second timer and then use that to increment or decrements a pair of registers. There are of course other ways to approach the up/down requirement.
     
  6. MaxHeadRoom

    Expert

    Jul 18, 2013
    15,514
    4,515
    To expand, the 32Khz Xtal offers 1sec resolution exactly.
    Max.
     
Loading...