16F688 problem


Closed Thread
Results 1 to 8 of 8

Thread: 16F688 problem

  1. #1

    Default 16F688 problem

    This is my first shot using a 16F688 and the internal OSC. I am pretty sure I have the config's set right for the OSC because I did a DEBUG command and was able to see the correct output. I have the OSC setting at INTOSCIO, WatchDog , PowerUp, BrownOut, Internale External, and, Fail Safe disabled. I have the MCLR set as a reset and it is pulled high.

    My problem is just turning on and off the PortC pins. When I try to turn on/off 0, 1, and 2, only 0 turns on/off. When I comment out Pin0(ClutchOut), pin 1 turns on and not 2. Of course then when I comment out 0 and 1, then 2 turns on. Below is the code.

    I did notice that I do have the Pull-Ups enabled yet only A2 and A5 are at 5v. A4 is 1.4v. The rest are 0v

    INCLUDE "modedefs.bas"
    Throttle Var PortA.0
    ClutchIn var PortA.1
    LineLockIn var PortA.2
    'MCLR var PortA.3
    'DEBUG var PortA.4
    Arming var PortA.5
    ClutchOut var PortC.0
    LineLockOut var PortC.1
    Aux1Out var PortC.2
    Aux2Out var PortC.3
    Jumper1 var PortC.4
    Jumper2 var PortC.5

    Marker var bit
    Counter var byte
    Timer var byte

    Option_Reg.7=0 'Pull-Ups Enabled
    TRISA=%111111
    TRISC=%110000
    ANSEL=%00000000 'D/A turned off on all pins
    ADCON0.0=0 'ADCON turned off
    VRCON.7=0 'VRef Off
    'INTCON.7=1

    'IOCA.5 = 0
    'IOCA.4 = 0
    'IOCA.3 = 0
    'IOCA.2 = 0
    'IOCA.1 = 0
    'IOCA.0 = 1 'Throttle Interrupt On

    define OSC 4
    DEFINE DEBUG_REG PortA
    DEFINE DEBUG_BIT 4
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 1

    loop:
    high LineLockOut 'Yellow LED PortC.1
    high ClutchOut 'Green LED PortC.0
    high Aux1Out 'White LED PortC.2
    pause 1000
    low LineLockOut 'Yellow LED PortC.1
    low ClutchOut 'Green LED PortC.0
    low Aux1Out 'White LED PortC.2
    pause 1000
    goto loop
    Last edited by Tobias; - 9th May 2009 at 07:24.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    You still have analog functions enabled, specifically the comparators.
    CMCON0 = 0 ' turn off comparators.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    I think Joe nailed it, but check the datasheet for the value to disable comparators. I think
    it should be CMCON0 = 7 on the 16F688.

    Pins configured as analog inputs will be read as 0 when used for digital I/O.

    The HIGH / LOW commands use BSF and BCF read-modify-write assembly language
    instructions. This causes the whole port to be read, the port pin to be modified, then the
    whole port is writen back to each time it lands on a HIGH LOW instruction.

    Example:

    high LineLockOut ' reads whole port, sets C.1, writes whole port back.
    high ClutchOut ' reads whole port, (C.1 is read back as 0), sets C.0, writes it back.
    high Aux1Out ' reads whole port, (C.0 is read back as 0), sets C.2, writes it back.

    If pins are set to analog inputs, then it reads each pin value back as 0, then writes it back
    as a 0 on the next BSF operation, so you end up with only Aux1Out being set once it runs
    through all three lines of code above.

    The same scenario can happen with read-modify-write. Even if the pins are not configured
    as analog inputs.

    If it blazes through these three lines of code at a high-speed, and there's a little bit of
    external capacitance on these pins, the next read-modify-write operation after changing
    the first output pin - may read the pin before it has had time to change, so it writes back
    the wrong value to a previous pin when it changes the next pin.

    When that happens, you can fix it by inserting a short pause between each instruction that
    sets or clears pins, or you can just write to the whole port at once instead of setting or
    clearing individual bits one at a time.
    Regards,

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

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    I think Joe nailed it, but check the datasheet for the value to disable comparators. I think
    it should be CMCON0 = 7 on the 16F688.

    Pins configured as analog inputs will be read as 0 when used for digital I/O.

    The HIGH / LOW commands use BSF and BCF read-modify-write assembly language
    instructions. This causes the whole port to be read, the port pin to be modified, then the
    whole port is written back to each time it lands on a HIGH LOW instruction.

    Example:

    high LineLockOut ' reads whole port, sets C.1, writes whole port back.
    high ClutchOut ' reads whole port, (C.1 is read back as 0), sets C.0, writes it back.
    high Aux1Out ' reads whole port, (C.0 is read back as 0), sets C.2, writes it back.

    If pins are set to analog inputs, then it reads each pin value back as 0, then writes it back
    as a 0 on the next BSF operation, so you end up with only Aux1Out being set once it runs
    through all three lines of code above.

    The same scenario can happen with read-modify-write. Even if the pins are not configured
    as analog inputs.

    If it blazes through these three lines of code at a high-speed, and there's a little bit of
    external capacitance on these pins, the next read-modify-write operation after changing
    the first output pin - may read the pin before it has had time to change, so it writes back
    the wrong value to a previous pin when it changes the next pin.

    When that happens, you can fix it by inserting a short pause between each instruction that
    sets or clears pins, or you can just write to the whole port at once instead of setting or
    clearing individual bits one at a time.
    <h1>RATS !</h1> Misread the chart CMCON0=0 comparators off ANALOG, CMCON0 = 7 comparators off DIGITAL !
    THANK YOU BRUCE !
    Last edited by Archangel; - 9th May 2009 at 19:55.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Misread the chart CMCON0=0 comparators off ANALOG, CMCON0 = 7 comparators off DIGITAL !
    Which is where ALLDIGITAL.pbp comes in really handy.
    http://www.picbasic.co.uk/forum/showthread.php?t=11100
    <br>
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thanks guys, I haven't had a chance to test yet but thanks.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    I got the following errors with the AllDigital.pbp, any ideas?

    opcode expected instead of a variable
    undefined symbol 'showdigitalresult'
    undefined symbol 'showdigitalresult'

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


    Did you find this post helpful? Yes | No

    Default

    Thank you Tobias.

    I made some changes after testing with the PM assembler. Should have tested that assembler again. Sorry bout that.

    Removing the variable opcode and the indent makes it work with PM again.
    Code:
    ;----[Module defaults]------------------------------------------------------
      #define SHOWDIGITALDEFAULT  0
      ifdef SHOWDIGITAL
    SHOWDIGITALRESULT = SHOWDIGITAL
      else
    SHOWDIGITALRESULT = SHOWDIGITALDEFAULT
      endif
      ifndef PM_USED
        ifndef ADLISTALL
          nolist
        endif
      endif
    I'll update the main file.

    Thanks again,
    DT

Similar Threads

  1. 16F688 counter problem
    By jderson in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th February 2008, 05:06
  2. Problem with PWM using 16F688
    By electrocomp in forum General
    Replies: 9
    Last Post: - 1st December 2007, 15:14
  3. A/D problem ON 16F688
    By Christopher4187 in forum General
    Replies: 2
    Last Post: - 19th October 2005, 23:13
  4. 16F688 problem
    By Christopher4187 in forum General
    Replies: 0
    Last Post: - 16th October 2005, 03:00
  5. Problem with 16F688 and Hserout
    By DWV in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 19th March 2005, 06: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