DT_Interrupts - TMR1 Issue With 16F88


Results 1 to 7 of 7

Threaded View

  1. #3
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: DT_Interrupts - TMR1 Issue With 16F88

    For the 16F88 I see that you are not setting the OSCCON register which is leaving the oscillator rate at its POR default.
    This coupled with your TMR0 setup and the Timer0 counter is making your LED stay on or off for over a minute.

    By default the OSCCON register is set to %00000000
    Which is 31.250 kHz Internal RC Oscillator Frequency (probably not what you want), and Oscillator mode defined by config bits FOSC<2:0> (which is correct)

    You have the OPTION_REG register set to the following:
    OPTION_REG = OPTION_REG & $80 | 1 which does this.
    OPTION_REG = $FF (default) & $80 | 1 = $81 which does this.
    PORTB pull-ups = disabled
    Interrupt Edge = on falling edge of RB0/INT pin
    TMR0 clock = Internal instruction cycle clock
    Prescaler = set to TMR0
    Prescaler = 1:4

    Now you have Timer0 setup the following way by not setting the OSCCON and OPTION_REG registers set the way you do.

    Internal instruction cycle = 1/[Processor Frequency /4] = 1/(31250/4) = 128us
    Timer0 = 8bit timer
    Timer0 Prescaler = 4
    Timer0 Overflow Interrupt = Internal instruction cycle x Prescaler x 2^8 = 128us x 4 x 256 = 131ms
    So your Timer0 Interrupt fires every 131ms.

    Time to toggle LED2: T0Count x Timer0 Overflow Interrupt = 512 x 131ms = 67.11 seconds.
    So your LED will toggle ~67 on/off.


    For the 16F628 by default the internal oscillator runs at 4Mhz so the Internal instruction cycle is this.
    Internal instruction cycle = 1/[Processor Frequency /4] = 1/(4000000/4) = 1us
    Timer1 = 16bit timer
    Timer1 prescaler = 8

    Timer1 Overflow Interrupt = Internal instruction cycle x Prescaler x 2^16 = 1us x 8 x 65536 = .524 seconds
    So your LED will toggle ~.524 seconds on/off, which is what you would expect.

    To correct your issues you should set the OSCCON and OPTION_REG registers to setup a Timer0 interrupt that you would expect and adjust the Timer0 counter in the interrupt handler appropriately to adjust the on/off rate you are looking for.
    Last edited by Tabsoft; - 23rd March 2015 at 20:43.
    Regards,
    TABSoft

Similar Threads

  1. TMR1 issue
    By Lestat in forum General
    Replies: 6
    Last Post: - 29th August 2012, 15:41
  2. Replies: 6
    Last Post: - 24th November 2011, 16:46
  3. Issue with 16F88 startup
    By Plcguy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st October 2010, 15:11
  4. Question on DT_Interrupts
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th May 2010, 17:32
  5. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts