serout2 apparently changing other I/O?


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    5

    Default SOLVED! serout2 apparently changing other I/O?

    ANSELA was the problem. I now set it to zero before turning on bit 4. This fixed the problem!. I wonder if PBP sets the correct ANSELA bit for me when using ADCIN, I didn't have time to test current consumption today to find out. Thanks Mr.E!

    @Henrik, I too suspected RMW trouble and inserted a delay. I also moved the RLY portion of the program around, even putting it in the ISR to no avail.

    Yes, there is a transistor to drive the relay. I have found it troublesome in many ways to drive 5V (Or 3.3V!) relays from my logic supply. I typically power relays from the highest voltage available in the project in order to reduce current consumption and reduce the demand on my regulators, as well as reduce spontaneous resets, glitches, and outright frying stuff.

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

    Default Re: serout2 apparently changing other I/O?

    Hi,
    I still think it WAS a RMW write issue but the cause wasn't heavy loading of the output and/or speed as I initially suspected. The cause was, as Steve noticed, the ANSEL register.

    A pin configured for analog input will, when read, return '0'. The SEROUT2 statement, doing RMW operations, will read the port, flip a bit and re-write the port. What's happening then is that the port is read and since the RLY-pin is configured as analog it will (always) read '0', the STX pin/bit will then be modified and the port will be re-written - this time with the RLY-bit/pin as 0 because that is what was read.

    With ANSEL correctly setup (RLY-bit/pin as digital) the RMW process of the SEROUT2 statement will read the correct state of the RLY-pin so when the port byte is re-written it will keep the '1'-state previously set.

    Steves suggestion of using LAT instead of PORT is great, however in this particular case I don't think it would have made any difference because I don't think (I'm not sure though) SEROUT2 actually targets the LAT registers so the result would have been the same anyway. However, for manual 'bit-flipping' using the LAT register would prevent RMW-issues caused by capacitive loading of the pin etc.

    (Actually it's not the SEROUT2 statement per se that performs the RMW operation, it's just the way the PIC works internally.)

    /Henrik.

Similar Threads

  1. changing osc on the fly
    By viewgsm in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th February 2010, 16:13
  2. Changing Settings ???
    By tico in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th December 2006, 04:10
  3. Mode changing on the fly
    By Angus Anderson in forum GSM
    Replies: 1
    Last Post: - 28th November 2006, 09:58
  4. Changing 18F WDT postscaler on-the-fly
    By Bruce in forum Code Examples
    Replies: 4
    Last Post: - 1st August 2006, 22:09
  5. Changing avatar
    By Demon in forum Off Topic
    Replies: 6
    Last Post: - 9th March 2005, 17:32

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