portA.0 cannot be set


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2007
    Posts
    10

    Default portA.0 cannot be set

    Dear Friends,

    I am experiencing a very frustating situation and I am hoping someone can help me solve this problem.

    I have been using Pics for almost 10 years, now, but this problem baffles me. I am using a pic18F8722, and I cannot set porta.o using the following statement: porta.0=1 or porta.0=0. In either cases, it remains high. The tris setting configures it as an output (trisa=0), and all other bits on the port work fine (excluding a.4 of course, which is open-collector).

    However, I can set the pin by using HIGH porta.0 or LOW porta.0.

    I have been trying to figure out the reason behind this for 3 days now, but I give up. I have found a work around by using select case in the following way:

    dummy= state of the pin I want to set
    select case dummy
    case 0
    low porta.0
    case 1
    high porta.0
    end select

    It works, but it is not very elegant...

    even this small program does not work:

    trisa=0
    main:
    porta.0=0
    porta.1=0
    pause 10
    porta.0=1
    porta.1=1
    pause 10
    goto main

    when I check the pins with my scope, I see a nice square wave on porta.1, but port a.0 stays high.

    If I change the program to:


    trisa=0
    main:
    low porta.0
    porta.1=0
    pause 10
    high porta.0
    porta.1=1
    pause 10
    goto main

    Then I see a square wave on both pins.

    My question is: what is the difference between the code generated with

    porta.0=1
    and
    high porta.0

    why is one expression working and not the other one?

    (by the way, yes, the fuses are properly set, ADCON1=%00000111 to set the outputs as digital, A/D module disabled, etc...)


    I appreciate your help.

    Best regards,

    Patrice

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: portA.0 cannot be set

    Do you have the pins connected to anything? It smells like the good old Read-Modify-Write problem...

    What if you try:
    Code:
    trisa=0
    main:
       porta.0=0
       Pause 1    'Allow PortA.0 to settle low.
       porta.1=0
       pause 10
       porta.0=1  'Allow PortA.0 to settle high
       Pause 1
       porta.1=1
       pause 10
       goto main
    HIGH and LOW also resets the corresponding bit in the TRIS register (making the pin output) for you so even if you have the pin setup as an input doing HIGH PortX.x will switch it to an ouptut and set it high. I'm not sure WHY it matters in THIS case but we can figure that out IF it turns out to BE a RMW-problem.

    /Henrik.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: portA.0 cannot be set

    You will need to turn the ADC off.
    ADCON1 = 15
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Nov 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: portA.0 cannot be set

    Henrik,

    It was a read-write-modify issue.
    a simple PAUSEUS 1 between instructions solved it.
    Thanks!

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default Re: portA.0 cannot be set

    Bonjour Patrice,

    Or simply Write " HIGH or LOW PortA.0 " ... it will automatically add a little time ... ( equal to TRISA.0 = 0 ... )

    hé,hé ... soyons flemmards !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Nov 2007
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: portA.0 cannot be set

    Bonjour Alain,

    You are right, I had noticed that writing "high" or "Low" indeed worked as well.
    This is the first time I design a project running at 40 Mhz, so I am dealing with new issues I have not seen before.

    You learn every day!

    A+

    Pat

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: portA.0 cannot be set

    Salut Patrice,

    With PIC18, there's LAT port made to avoid this problem

    You write to LAT ... but read from PORT
    LATA.0=1
    LATA.1=1
    LATA.2=1
    LATA.3=1
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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