problem with toggle command


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: problem with toggle command

    How else could it work? If it's supposed to toggle a bit it needs to know what state that bit is currently in, right?

  2. #2
    Join Date
    Sep 2016
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: problem with toggle command

    Henrik,
    Well, I guess I don't have to know If I just add 1 to whatever is there, so why should it have to know? - just kidding
    From your original answer, I see that you obviously understand the inner workings of these microcontrollers & what the compiler is doing behind the scenes. I do not, & my last comment about the 2nd part of SUNFLOWER's answer is just this very thing; before I read your answer, I might think that somehow it could just add 1 to whatever is there.
    Last edited by INVTLG; - 4th September 2016 at 01:24.

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


    Did you find this post helpful? Yes | No

    Default Re: problem with toggle command

    Exactly, when you think about it for a bit you'll realise that even PortA.1 = PortA.1 + 1 won't work because of the exact same reason and in this case it's even more "obvious" than with the TOGGLE command because here you have it spelled out. You're telling the compiler to read the state of PortA.1, add 1 to it and write it back. If, when Reading PortA.1 it always reads high because it's got its digital buffer disabled then it will work just as bad as TOGGLE will.

    On top of that you should know that ALL bit operations are executed as Read-Modify-Write by the internal PIC hardware, has nothing to do with the compiler. So, if you're using some pins on PortA as digital outputs but you don't bother to enable the digital buffers and then you do something simple like PortA.0 = 1 what will happen is that the PIC (ie the actual processor) will read all 8 bits from PortA, set bit 0 and write all 8 bits back to the Port register and the state of "the other" pins might change "unexpectedly".

    So, whenever you get "weird" results on any I/O pins, even if you're not actually writing to that specific pin you should always think about the analog peripherals.

    And again, on the device with LAT register you should use those instead of port since they're pretty much unaffected by RMW issues, no matter the actual cause.

    /Henrik.
    Last edited by HenrikOlsson; - 4th September 2016 at 07:49.

Similar Threads

  1. Toggle command question
    By AvionicsMaster1 in forum General
    Replies: 3
    Last Post: - 31st January 2012, 15:34
  2. Toggle command
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2011, 02:07
  3. problem with I2CWRITE command
    By hatzukitzuki in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th October 2010, 22:35
  4. toggle command w/ multiple switches
    By earltyso in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th February 2007, 17:47
  5. PIC16F88 problem with TOGGLE command?
    By russman613 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th September 2006, 23: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