Strange Behavior in setting several pin outputs states.


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior in setting several pin outputs states.

    I want to thank you very much.

    The problem is resolved, now I am setting the pin output states super fast!

    The final working code was the one posted by rmteo, but thank you all really!


    ShadowC VAR byte
    ShadowC = PORTC

    ShadowC.0 = 1
    PORTC = ShadowC

    ShadowC.1 = 1
    PORTC = ShadowC

    ShadowC.2 = 1
    PORTC = ShadowC

    ShadowC.3 = 1
    PORTC = ShadowC

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


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior in setting several pin outputs states.

    You can do it even faster by doing it the way Charles originally showed you, (did you REALLY try that and it didn't work?) in other words:
    Code:
    ShadowC VAR BYTE
    ShadowC = PortC
    
    ShadowC.0=1
    ShadowC.1=1
    ShadowC.2=1
    ShadowC.3=1
    
    PortC = ShadowC
    /Henrik.

  3. #3
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior in setting several pin outputs states.

    Quote Originally Posted by HenrikOlsson View Post
    You can do it even faster by doing it the way Charles originally showed you, (did you REALLY try that and it didn't work?) in other words:
    Code:
    ShadowC VAR BYTE
    ShadowC = PortC
    
    ShadowC.0=1
    ShadowC.1=1
    ShadowC.2=1
    ShadowC.3=1
    
    PortC = ShadowC
    /Henrik.
    Even faster would be this way - but obviously the OP did not try it the way Charles described.
    Code:
    ShadowC VAR BYTE
    ShadowC = PortC
    
    ShadowC.0 = $F
    
    PortC = ShadowC
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior in setting several pin outputs states.

    Sorry for the typo - and the inability to edit a post.

    Code:
    ShadowC VAR BYTE 
    ShadowC = PortC  
    
    ShadowC = $f 
    
    PortC = ShadowC
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior in setting several pin outputs states.

    Hi,
    Even faster would be this way - but obviously the OP did not try it the way Charles described.
    Not really because then the top four bits will be 0 which they might not have been when PortC was read. And IF the top four bits doesn't matter then I see no reason for not simply writing to PortC directly, ie PortC = $F which would make THIS particular example even faster....

    However, I suspect that setting the low four bits to 1 are just an example. Using bitwise AND/OR could also work but I'm not sure it's faster than simply flipping the four bits in ShadowC and then writing it to the port.

    /Henrik.

  6. #6
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior in setting several pin outputs states.

    All of this is basic stuff - using a bit mask and writing directly to PORTC is the fastest way. Bottom line is that the OP did not do it the way Charles described and that is why it did not work for him. I just re-wrote it in a way that I felt would make sense to the OP.
    Last edited by rmteo; - 9th December 2011 at 18:16.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  7. #7
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: Strange Behavior in setting several pin outputs states.

    One of the best threads dealing with RMW and solutions to solve the problem is here:

    http://www.picbasic.co.uk/forum/showthread.php?t=15843

    Charles also explains that using this method should not affect your USART pins if they are on that particular port.

    Just out of curiosity, is this method affecting your PWM if it is active on the same port and how?
    Are there any other special or ordinary functions that could be affected?
    I’m especially interested to know about inputs on the port that might be used for interrupts and the external source changes while this action is in progress.

    Regards,

    Nick

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