Sequence of statements makes code work differently. (PIC16F628A)


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

    Default Re: Sequence of statements makes code work differently. (PIC16F628A)

    628A has analog functions?

    P.S. I do have CMCON disabled...

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Sequence of statements makes code work differently. (PIC16F628A)

    Quote Originally Posted by CuriousOne View Post
    628A has analog functions?
    Page 1 of the data sheet !

    2 analogue comparitors - Pins PORTA.0 to PORTA.3

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: Sequence of statements makes code work differently. (PIC16F628A)

    628A has analog functions?
    Yes it does, the comparators are analog and enabled by default.

    P.S. I do have CMCON disabled...
    Your code doesn't show that. What does having CMCON disabled mean? What are you writing to it?

    From the datasheet
    The PORTA pins are multiplexed with comparator and
    voltage reference functions. The operation of these
    pins are selected by control bits in the CMCON
    (Comparator Control register) register and the VRCON
    (Voltage Reference Control register) register. When
    selected as a comparator input, these pins will read
    as ‘0’s.
    When you do stuff like
    Code:
    PortA.0 = 1
    PortA.1 = 1
    All bit operations on a register is performed as a read-modify-write operation. The port is read, modified and written back - it's the way it works inside the PIC itself. If the read operation returns a state of a pin that is different to what you set then that erroneous state will be written back to the port and you get "weird" and "unexpected" results. Having analog functions enabled is THE most (un)popular cause of this happening.

    Having too much load, or a capacartive load on the actual output is another cause. In this case the voltage level at the pin isn't allowed to rise to a level where the read operation of the second command actually "gets" a logic 1.

    /Henrik.

    If you Google read modify write you'll find loads and loads of explainations.

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Sequence of statements makes code work differently. (PIC16F628A)

    Simple trick to shadow the port with a latch byte and send that to the port at the expense of some speed.

    Code:
    portalatch var byte
    portalatch = 0’
    
    portalatch.bit0 = 1
    PORTA = portalatch'
    Even though it would have been pins left analogue this time, it will still cause hard to debug problems.

Similar Threads

  1. Darrels interrupts and multiple SOUND statements, will it work?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 31
    Last Post: - 26th January 2015, 07:42
  2. Replies: 13
    Last Post: - 10th July 2012, 18:05
  3. LED chaser - Scanner Sequence PIC16F628A
    By izzyblackout in forum Code Examples
    Replies: 4
    Last Post: - 3rd February 2011, 14:09
  4. Why doesn't this servo code work?
    By artswan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th December 2009, 22:18
  5. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31

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