How can I do this (reversing high & low states depending on deployment & user need)


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default How can I do this (reversing high & low states depending on deployment & user need)

    Forgive the esoteric subject but it's hard to articulate what I'm trying to resolve.

    I have a MOSFET under PIC control.....a mosfet gate is normally low but when a tactile switch is pressed, a PIC interrupt happens & a PIC output pin goes high & switches the MOSFET on - no worries thus far.

    *but* occasionally, depending on the deployment (& I won't know in advance so it'll be down to the end user to establish) I will need the above scenario to reversed & this will then be the default .....therefore the MOSFET gate will normally be high & when a tactile switch is pressed an interrupt is triggered and a PIC output pin goes low & switches the MOSFET off.

    So what I'm thinking here is when the user deploys & it doesn't want the default...that he can change it.

    But what I don't want is a massive long program to cater for both scenarios...I'm thinking that if the user holds a switch prior to powering up, then the 'default' can be selected to the non default (in other words, a toggle).

    You following this at the back?

    in summary, this is what I'm trying to achieve....

    factory_default...
    mosfet_gate = low
    when switched pressed mosfet_gate = high

    user_selectable_new_default....
    mosfet_gate = high
    when switched pressed mosfet_gate = low

    How do I tackle this in an efficient way?
    Last edited by HankMcSpank; - 17th May 2012 at 00:32.

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: How can I do this (reversing high & low states depending on deployment & user nee

    Try something like this:
    Code:
    IF factory_default THEN
    StateOn=1
    StateOff=0
    ELSE
    StateOn=0
    StateOff=1
    ENDIF
    
    IF SwitchPressed THEN Gate=StateOn
    IF SomeThingElse THEN Gate=StateOff

  3. #3
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: How can I do this (reversing high & low states depending on deployment & user nee

    I probably do it like pedja089, but used the eeprom to save the setting!
    Thanks and Regards;
    Gadelhas

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: How can I do this (reversing high & low states depending on deployment & user nee

    Code:
    EE_Polarity DATA 0            ; Factory Default
    SW1         VAR PORTB.0       ; Switch input pin
    mosfet_gate VAR PORTB.1       ; mosfet output
    Polarity    VAR BIT           
    
    READ EE_Polarity, Polarity
    IF !SW1 THEN WRITE EE_Polarity, !Polarity
    READ EE_Polarity, Polarity
    
    mosfet_gate = 1 ^ Polarity    ; Turn OFF
    OUTPUT mosfet_gate
    ;----------------------------------------------
    
    mosfet_gate = 0 ^ Polarity    ; Turn ON
    mosfet_gate = 1 ^ Polarity    ; Turn OFF
    Last edited by Darrel Taylor; - 17th May 2012 at 04:38. Reason: Oops, forgot to set the pin to output.
    DT

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: How can I do this (reversing high & low states depending on deployment & user nee

    Thanks to everyone...embarrasingly simple in the end! (hey, it was late!)

    Hi Darrel, I was with you up to this bit....

    Quote Originally Posted by Darrel Taylor View Post
    Code:
    EE_Polarity DATA 0            ; Factory Default
    mosfet_gate = 1 ^ Polarity    ; Turn OFF
    OUTPUT mosfet_gate
    ;----------------------------------------------
    
    mosfet_gate = 0 ^ Polarity    ; Turn ON
    mosfet_gate = 1 ^ Polarity    ; Turn OFF

    Can anyone shed a little light on what's going on there (never used a ^ before!)

  6. #6
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: How can I do this (reversing high & low states depending on deployment & user nee

    That is XOR.
    0^0=0
    0^1=1
    1^0=1
    1^1=0
    If Polarity is 1 or 0, depending on user settings. If Polarity is 0 then bit isn't inverted and result is same as:
    mosfet_gate = 0 ; Turn ON
    mosfet_gate = 1 ; Turn OFF
    If Polarity is 1 then then bit are inverted so result is
    mosfet_gate = 1 ; Turn ON
    mosfet_gate = 0 ; Turn OFF

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