DT_Interrupts - TMR1 Issue With 16F88


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    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

    Bala,

    Glad to be of help and that you have it working as you wanted.

    I am a little curious about your statements and reported observations though.

    Your posted code does indeed create a ~1Hz blinking led (~.5sec on / ~.5sec off).
    It does this by creating a TMR0 Overflow Interrupt that fires every 1.024ms and your T0Count tests for 512 counts which makes LED2 toggle every ~524ms.

    TMR0 Overflow = (1 / [4000000/4]) * 4 * 256 = 0.001024 seconds (You are setting the Prescaler to 1:4 as "OPTION_REG = OPTION_REG & $80 | 1" does)
    BTW, I guess the comments have not be updated in the posted code for the above OPTION_REG line? ("Set TMR0 Prescaler to 256")

    LED2 Toggle = TMR0 Overflow * 512 = 0.001024 * 512 = 0.524288 seconds
    This creates a ~0.5sec On / ~0.5sec Off rate for ~1Hz.

    You state that my suggestion of setting the TMR0 Prescaler to 1:32 and T0Count test to 61, blinks the light at 0.5Hz (1 second On, 1 second Off).
    And you then set the Prescaler to 1:16 and then LED2 blinks at 1Hz.

    Well, setting up the configuration as I suggested here on my end does create a blinking led at ~1Hz.

    TMR0 Overflow = (1 / [4000000/4]) * 32 * 256 = 0.008192 seconds
    LED2 Toggle = TMR0 Overflow * 61 = 0.008192 * 61 = 0.499712 seconds (~0.5sec On / ~0.5sec Off).

    I have verified your code with my suggested settings added via the simulator (do not have the 16F88 IC) and it blinks at ~1Hz.
    I also verified your posted code as is via the simulator and have the same ~1Hz blinking rate as would be expected from the calculations.

    If you set the Prescaler to 1:16 and leave the T0Count test to 61 then the result would be different.
    TMR0 Overflow = (1 / [4000000/4]) * 16 * 256 = 0.004096 seconds
    LED2 Toggle = TMR0 Overflow * 61 = 0.004096 * 61 = 0.249856 seconds
    Which would cause LED2 to blink at ~2Hz (~.250sec On / ~.250sec Off)

    Perhaps your setting of the OPTION_REG register was not quite right when you tested the suggestions?
    To set the PORTB Pullups enabled and TMR0 Prescaler to 1:32, OPTION_REG = $84 %10000100.
    To set the PORTB Pullups enabled and TMR0 Prescaler to 1:16, OPTION_REG = $83 %10000011.

    Again, just curious about your observations...
    Regards,
    TABSoft

  2. #2
    Join Date
    May 2011
    Location
    Bangalore, India
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: DT_Interrupts - TMR1 Issue With 16F88

    Tabsoft, you are absolutely right on both the counts.

    In the case of the code taken from Darrel's test program, the Option_Reg setting is hex 81 which is binary 10000001. Bits 2-0 are "001" which means that the prescaler is set to 1:4 and not 1:256 as shown in the comment. As you have mentioned, possibly, the comment has not been updated. Henrik was also right in saying that the TMR0 setting did not seem to match the comment in the code.

    The settings you suggested are 1:32 prescaler for TMR0 and if the count >= 61, toggle the LED and reset the counter. This indeed gives ~1Hz blinking rate. In my previous post I mentioned that I tried 1:32 prescaler and changed it to 1:16 to make the LED blink at 1Hz. This is incorrect. In the 16F87/88 datasheet under Option_Reg, a table is shown with 3 column headings - BitValue, TMR0 Rate & WDT Rate. For 1:32 prescaler, by mistake I took the WDT value (101 in Col. 3) instead of TMR0 value (100 in Col. 2). This was the reason for the 0.5Hz rate. In fact in my final version, I have used the value you suggested (100 for 1:32) and they work perfectly.

    Thanks again for all the help.

    Regards,
    Bala

Similar Threads

  1. TMR1 issue
    By Lestat in forum General
    Replies: 6
    Last Post: - 29th August 2012, 16:41
  2. Replies: 6
    Last Post: - 24th November 2011, 17:46
  3. Issue with 16F88 startup
    By Plcguy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st October 2010, 16:11
  4. Question on DT_Interrupts
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th May 2010, 18: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, 09: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