16F688 counter problem


Closed Thread
Results 1 to 9 of 9
  1. #1

    Default 16F688 counter problem

    I am trying to use TMR0 as a counter, and eventally display the count on the LCD. I am also running with the 32khz. internal oscillator. The following program works fine:

    TRISC = %000000
    TRISA = %000100
    OSCCON = %00000011
    WDTCON = %0000000

    Define LCD_DREG PORTC 'Set LCD data port
    DEFINE LCD_DBIT 0 'Set LCD starting data bit
    DEFINE LCD_RSREG PORTC 'Set LCD register select port
    DEFINE LCD_RSBIT 4 'Set LCD register select bit
    DEFINE LCD_EREG PORTA 'Set LCD enable port
    DEFINE LCD_EBIT 1 'Set LCD enable bit
    DEFINE LCD_BITS 4 'Set LCD bus size
    DEFINE LCD_LINES 2 'Set LCD number of lines




    Lcdout $fe, 1 ' Clear LCD screen
    Lcdout "I Love" ' Display Hello

    Lcdout $fe, $C0 ' Clear LCD screen
    Lcdout "This"

    end

    When I add this line:

    OPTION_REG = %00110000

    It quits working.

    Does anyone know why?

    Thank you.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, I can't find a specific symptom that exactly matches your description.

    But I have a feeling it has something to do with many of the pins being in Analog mode.

    Try adding ...
    Code:
    ANSEL = 0
    <br>
    DT

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    CMCON0 = 7 wouldn't hurt either..;o}

    Edit: Note that PBP defaults to 4MHz. If you're using the internal 31kHz osc, expect pretty much all timing to be way off.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    CMCON0 = 7 wouldn't hurt either..;o}
    Now how did I miss that?
    I looked, didn't see comparators, DOH!

    Nice catch Bruce.
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    I tried both suggestions, and it doesn't help. I am aware of the severe timing differences, but that shouldn't have anything to do with this, should it?

    Thanks for your help.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Here's another possibility.

    By setting WDTCON = %0000000

    If the config bit's say _WDT_ON then you can't turn off the Watch Dog Timer with the WDTCON.0

    However, in the process, it's reduced the WDT prescaler to 1:32

    Since the processor is running so slow. the WDT might not be getting cleared often enough.

    So, either try turning off the WDT in the configs. Or set WDTCON = %00010110 (1:65536)

    hth,
    DT

  7. #7


    Did you find this post helpful? Yes | No

    Default

    I changed it to WDTCON = %00010110, and it works! Thank you!

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Weird problem - just a comment

    OPTION_REG defaults to $FF on power up. It looks like when you define the OPTION_REG value you are setting bits 4 and 5 but you are actually clearing bits 0-3 and 6-7. Bits 0-3 are harmless since they relate to the prescale of TMRO. Bit 6 sets the method of interrupt for RA2 - but the Interrupts are not enabled. That leaves Bit 7, which turns on the weak pull-ups. How strong of signal are you using to drive pin 11?

    EDIT: a bit late but not the problem - glad it works
    Last edited by paul borgmeier; - 16th February 2008 at 04:03. Reason: solution reached before my post
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Nice catch Darrel.

    I would just set WDT_OFF with PBP assuming 4MHz, and running at 31kHz. Just in case. PBP will insert a NOP where it normally had a CLRWDT for timing, but there may be a library routine that doesn't hit the dog in time with the timing being so far out of whack.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. 16F688 problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th May 2009, 23:09
  2. Replies: 14
    Last Post: - 26th September 2007, 05:41
  3. UP/down counter & shiftout interupt problem
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd July 2007, 15:56
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Problem with 16F688 and Hserout
    By DWV in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 19th March 2005, 05:37

Members who have read this thread : 1

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