Implementing two timers in PIC

Discussion in 'Programmer's Corner' started by RG23, Apr 11, 2011.

  1. RG23

    Thread Starter Active Member

    Dec 6, 2010
    I have defined the two timers in PIC16F887 as follows


    Doing the above code I am not able to implement the two timers correctly

    If anyone has an idea please let me know

    Last edited: Oct 13, 2011
  2. Markd77

    Senior Member

    Sep 7, 2009
    Can we see the complete code? If you go advanced, select the code and click the # icon it looks better.
    Have you set the Global interrupts Enable bit in INTCON?
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    Why not use just one timer of 120uS, then generate the 2mS event after every 17 events of 120uS?

    That just requires one 120uS timer, and one variable to count to 17. :)
  4. mjhilger


    Feb 28, 2011
    You didn't tell us your clock speed, but an int every 120uS is really pushing that little chip. You are not going to get much processing done outside your interrupt routine, and depending on what you are doing inside your routine, you might not be exiting before the next int. You know you have to clear the individual timer int flags as well as issue the RETI. Are you sure your timers are not running and maybe only executing the int routine only 1 time?

    I like the 16F series, but the 18F is a bunch faster and could do this easier. I like the PIC18F4525 - also has a built in osc, so no external xtal needed (so with the internal 8Mhz and PLL set to 4x you get 32Mhz clk).