portA problem


Closed Thread
Results 1 to 17 of 17

Thread: portA problem

  1. #1

    Default portA problem

    Hi!

    I do not know what is going on!

    PortB works just fine,
    but
    a) code does NOT toggle the test (test1, test2) pins
    b) code does toggle the test pins

    test1 = portA.1 and test2 = portA.2

    'a)
    loop:
    pause 5
    toggle test1
    toggle test2

    if portB = 0 then
    portB = $ff
    '// toggle test1
    else
    portB = 0
    '// toggle test2
    endif
    goto loop:

    'b)
    loop:
    pause 5
    '// toggle test1
    '// toggle test2

    if portB = 0 then
    portB = $ff
    toggle test1
    else
    portB = 0
    toggle test2
    endif
    goto loop:


    Could somebody please try to explain how this is possible?
    I'm puzzled, how is this possible?
    Using picbasicpro 2.50

    regards
    key

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by keymuu View Post
    I do not know what is going on!
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    And it would REALLY help to know which PIC you are using...

  3. #3


    Did you find this post helpful? Yes | No

    Default portA or TOGGLE problem?

    Quote Originally Posted by skimask View Post
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    And it would REALLY help to know which PIC you are using...
    Thanks for the reply...

    The prosessor is 18F4550

    and before the the code there is:
    trisA = 0
    trisB = 0

    So, actually i do not know if it is a portA problem or a TOGGLE failure?

    Regards
    Key

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Re-read that linked post above...read it good, read it carefully...then re-read the 3rd paragraph...then re-read it again...

    And if you're not sure if it's a TOGGLE failure or not, then don't use TOGGLE...
    Surely you can come up with a different method of changing the state of a bit from one to the other and back again...

  5. #5


    Did you find this post helpful? Yes | No

    Default toggle portA.1 problem

    Quote Originally Posted by skimask View Post
    Re-read that linked post above...read it good, read it carefully...then re-read the 3rd paragraph...then re-read it again...

    And if you're not sure if it's a TOGGLE failure or not, then don't use TOGGLE...
    Surely you can come up with a different method of changing the state of a bit from one to the other and back again...
    ...when I add ADCON1 = 7 to the code after trisA and trisB it does not change the outcome. Here is the code:

    DEFINE OSC 48
    '
    test1 var PORTA.1
    test2 var PORTA.2

    trisA = 0
    trisB = 0
    ADCON1 = 7

    ProgramStart:

    pause 5
    toggle test1 '// comment -- THIS DOES NOT WORK!
    toggle test2 '// these two lines AND

    if portB = 0 then
    portB = $ff
    '//toggle test1 '// uncomment -- THIS WORKS
    else
    portB = 0
    '//toggle test2 '// uncomment
    endif

    goto ProgramStart

    Depending where toggle is it either work or does not work. If you have the possibility to test this, please let me know if works on your pic.

    Thank you in advance

    Regards
    Key

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by keymuu View Post
    ...when I add ADCON1 = 7 to the code after trisA and trisB
    1/2 way there...keep reading and re-reading...
    And again...read the PBP manual about TOGGLE. Not that TOGGLE is a bad command, but there are other ways to flip a bit...

    Anybody got the link to the R-M-W 'writeup' thread here?
    The PIC is running 48Mhz here (apparently). I see possible R-M-W issues...

    Besides that...look at your code...There are logical flow flaws (is that the correct way to put that?) in it...
    How do you know TOGGLE isn't actually working the way it should?
    Can you see that fast? I can't...

  7. #7
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Default Is this the R-M-W thread?

    Quote Originally Posted by skimask View Post
    Anybody got the link to the R-M-W 'writeup' thread here?
    The PIC is running 48Mhz here (apparently). I see possible R-M-W issues...
    http://www.picbasic.co.uk/forum/showthread.php?p=34331
    Last edited by Pic_User; - 15th October 2008 at 00:16. Reason: Fix quote
    Ohm it's not just a good idea... it's the LAW !

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    That's one of them, but somewhere out there is a much longer, more involved explanation of the R-M-W issue. Someday I'll come across it again...

  9. #9
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Red face This one?

    Quote Originally Posted by skimask View Post
    That's one of them, but somewhere out there is a much longer, more involved explanation of the R-M-W issue. Someday I'll come across it again...
    http://www.picbasic.co.uk/forum/showthread.php?p=8886
    Ohm it's not just a good idea... it's the LAW !

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Man, you're finding more than I'm finding.
    Obviously that's a good one too, but the one I'm thinking of is a single-thread in-and-of itself, all about R-M-W...
    Then again, I might be wrong. Maybe that thread was on Microchip's forums. Things like that tend to run together after awhile ya know...

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    1/2 way there...keep reading and re-reading...
    And again...read the PBP manual about TOGGLE. Not that TOGGLE is a bad command, but there are other ways to flip a bit...

    Anybody got the link to the R-M-W 'writeup' thread here?
    The PIC is running 48Mhz here (apparently). I see possible R-M-W issues...

    Besides that...look at your code...There are logical flow flaws (is that the correct way to put that?) in it...
    How do you know TOGGLE isn't actually working the way it should?
    Can you see that fast? I can't...
    Thank you Skimask, you are right, I'm 1/2 way there and in fact even slightly further... I did read a little bit further also...

    Found in the pic18F4550 data sheet that LATA is about the same as PORTA, so I changed PORTA.1 to LATA.1 and that solved the issue. However I do not understand why PORTA does not work and LATA works in this "example". Could somebody try to explain that shortly, I am sure it will help ohter people also. Knowing that LATx is included in the 18F pics, but still does not grasp how it (change toggle place) works like it does?
    How could this be an r-m-w matter?

    Regards
    Key

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Read-Modify-Write, it's briefly explained in the PBP manual somewhere...and it's also explained in those links above a bit...

  13. #13
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by skimask View Post
    Read-Modify-Write, it's briefly explained in the PBP manual somewhere...and it's also explained in those links above a bit...
    This one is pretty good explaining what it is.
    Outside the forum:http://www.piclist.com/techref/readmodwrite.htm
    Ohm it's not just a good idea... it's the LAW !

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


    Did you find this post helpful? Yes | No

    Default

    However I do not understand why PORTA does not work and LATA works in this "example". Could somebody try to explain that shortly
    Setting or clearing port bits directly reads the whole port, alters the bit in question,
    the writes the whole 8-bit value back to the port.

    Example (for 18F parts);

    HIGH PORTB.0
    HIGH PORTB.1
    HIGH PORTB.2, etc

    And PBP will generate assembler code something like;

    bsf PORTB,0 ; reads the whole port, sets RB0, writes the 8-bit value back to the port
    bcf TRISB,0 ; make RB0 an output (now RB0 begins to go high)
    bsf PORTB,1 ; reads whole port again (note that RB0 may not be high yet because this happens fast)
    bcf TRISB,1
    bsf PORTB,2
    bcf TRISB,2, etc.

    What happens is when RB0 goes high, then it's made an output, it may take a while
    before the actual voltage output on RB0 goes high - due to external capacitance.

    If the voltage output on RB0 is below the PIC logic 1 input threhold, when the port was
    read on the 2nd bsf instruction, it gets read back in as zero, and a logic 0 gets output
    back on RB0. It read the port, modified only RB1, and wrote the new value back to the
    port. I.E. That's R-M-W.

    When you use the LAT registers it doesn't cause the whole port to be read back, modified,
    then written again.

    The faster the core is running, and the more external capicitance there is, the more you will
    have problems with read-modify-write.

    Microchip added the LAT registers on 18F series primarily to eliminate this problem.
    Regards,

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

  15. #15


    Did you find this post helpful? Yes | No

    Default Bad ADCON1 perhaps

    You are setting ADCON1 = 7. This sets PortA to analog.

    I would be setting ADCON1 = %00001111 in order to make PortA all digital.

    This has changed froom the PIC16F877 series.

    HTH
    Brian

  16. #16


    Did you find this post helpful? Yes | No

    Default so it was a r-m-w problem

    Quote Originally Posted by Bruce View Post
    ....... The faster the core is running, and the more external capacitance there is, the more you will have problems with read-modify-write. ....
    Thank you Skimask, Bruce, Pic_user and all other for your support.

    The more one comes familiar with PIC, there are more and more that is not advertised by Microchip in the first place, mais c'est la vie....

    Before this problem, I was not aware of such a thing as r-m-w. Now I think I understand what the phenomena is. In a matter of fact, I was kind of lucky when I run into this TOGGLE problem.

    Thank you once again for your kind help....

    Regards
    Key

  17. #17
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by keymuu View Post
    Before this problem, I was not aware of such a thing as r-m-w. Now I think I understand what the phenomena is. In a matter of fact, I was kind of lucky when I run into this TOGGLE problem.
    Besides heat and actual power transmission issues, that r-m-w issue is one of the big reasons why we don't have 100GHz Intel Core2 processors running with a 25GHz Front-Side-Bus...

Similar Threads

  1. PIC16F877A analog problem
    By DeViLa_Q8 in forum mel PIC BASIC
    Replies: 0
    Last Post: - 30th July 2009, 20:19
  2. Problem with porta for 16F886(PIC 28X1)
    By Anghel Cosmin in forum Off Topic
    Replies: 2
    Last Post: - 26th February 2009, 13:07
  3. PIC's ports individual bits manipulation - how to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 27th February 2007, 22:34
  4. Problem with ADC
    By savnik in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 25th November 2006, 07:37
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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