Confused about inverting input logic

Willie...

New Member
I'm using pull-to-ground logic inputs, and need to invert them on a 20M2. I'm using editor V6.0.9.2.

I am interfacing the inputs of the PICaxe to existing equipment which uses active low outputs. I've searched the Forum, but couldn't find an answer.

I have the PULLUP command on the inputs, and that is working perfectly. I just need to have the logic inverted, so an "active low" input looks like active high. There are a total of 4 inputs, all working the same way, so I am only going to illustrate one of them here.

Here's what I've tried so far without success:

Code:
symbol WEAK  = not pin b.7
doesn't work, it gives a syntax error.

So I tried this

Code:
symbol WEAK = 0

main:
WEAK = not pinb.7
Also doesn't work. I've tried "INV" instead of "NOT", but get a syntax error either way.

I also tried

Code:
WEAK = not WEAK
in the code, but that doesn't work, as it seems to cancel itself out.

Using a variable seems to work

Code:
symbol WEAK  = pinb.7
symbol RED = pinc.0

main:
RED = not WEAK ;light the LED when input goes low
pause 10 ; slow it down a bit
goto main ;loop forever
This works to make a red LED on pinc.0 "follow" the action of the button, (LED goes ON when the button is pressed, pulling it's input LOW) but isn't helping me with the "logic" of the program I'm trying to write.


The solution is probably staring me in the face, but I'm just not seeing it. ;) Should I use a bunch of BIT variables?

Thank you in advance. :)

Willie...
 

hippy

Technical Support
Staff member
Input signals can only be inverted when assigned as you are doing in your program which works. There is no means to specify an automatic inversion of an input pin signal level using a SYMBOL statement.

That may not be as inconvenient as it first appears. If you can describe the logic of the program, members of the forum may be able to suggest the best approach to use for that.
 

lbenson

Senior Member
If you are going to set "WEAK" to a value in a program, it needs to be a variable (bit, byte, word) or a pin. "symbol WEAK = 0" makes WEAK a constant (can't be changed) with a value of 0.

I'm still not exactly sure what you are attempting to do with which pins in response to what event. Can you explain that further?
 

BESQUEUT

Senior Member
I'm using pull-to-ground logic inputs, and need to invert them on a 20M2. I'm using editor V6.0.9.2.

I am interfacing the inputs of the PICaxe to existing equipment which uses active low outputs. I've searched the Forum, but couldn't find an answer.

I have the PULLUP command on the inputs, and that is working perfectly. I just need to have the logic inverted, so an "active low" input looks like active high. There are a total of 4 inputs, all working the same way, so I am only going to illustrate one of them here.


Code:
symbol WEAK  = pinb.7
symbol RED = pinc.0

main:
RED = not WEAK ;light the LED when input goes low
pause 10 ; slow it down a bit
goto main ;loop forever
This works to make a red LED on pinc.0 "follow" the action of the button, (LED goes ON when the button is pressed, pulling it's input LOW) but isn't helping me with the "logic" of the program I'm trying to write.


The solution is probably staring me in the face, but I'm just not seeing it. ;) Should I use a bunch of BIT variables?

Thank you in advance. :)

Willie...
Try this for light show :
Code:
[color=Blue]symbol WEAKout  [/color][color=DarkCyan]= [/color][color=Blue]b.7
symbol [/color][color=Purple]WEAK  [/color][color=DarkCyan]= [/color][color=Purple]pinb.7[/color]
[color=Blue]symbol [/color][color=Purple]RED [/color][color=DarkCyan]= [/color][color=Purple]pinC.0
dirC.0[/color][color=DarkCyan]=[/color][color=Navy]1[/color]


[color=Blue]do
      toggle WEAKout
      [/color][color=Purple]RED[/color][color=DarkCyan]= not [/color][color=Purple]WEAK     [/color][color=Green]; light the LED when input goes low
      [/color][color=Blue]pause [/color][color=Navy]250         [/color][color=Green]; slow it down a bit[/color]
[color=Blue]loop[/color]
And now this to follow the button :
Code:
[color=Blue]symbol [/color][color=Purple]WEAK  [/color][color=DarkCyan]= [/color][color=Purple]pinb.7[/color]
[color=Blue]symbol [/color][color=Purple]RED [/color][color=DarkCyan]= [/color][color=Purple]pinC.0
dirC.0[/color][color=DarkCyan]=[/color][color=Navy]1[/color]


[color=Blue]do
      [/color][color=Purple]RED[/color][color=DarkCyan]= not [/color][color=Purple]WEAK     [/color][color=Green]; light the LED when input goes low
      [/color][color=Blue]pause [/color][color=Navy]20          [/color][color=Green]; slow it down a bit[/color]
[color=Blue]loop[/color]
 

Willie...

New Member
If you are going to set "WEAK" to a value in a program, it needs to be a variable (bit, byte, word) or a pin. "symbol WEAK = 0" makes WEAK a constant (can't be changed) with a value of 0.

I'm still not exactly sure what you are attempting to do with which pins in response to what event. Can you explain that further?
DING! OK, that light just came on! :) THANK YOU!
(Like I said... it was probably staring me in the face, but I wasn't seeing it! )

Changing that to use...
Code:
symbol WEAK  = bit4 ;Input for WEAK Signal warning
symbol RED = pinc.0 ; Red LED

main:
pause 10 ; Slow things down a bit
WEAK = not pinb.7 ; Invert input so a LOW (active) input = 1
RED = WEAK ; Light the LED if input goes low
goto main ; Loop forever
...is working! :)

As for what I'm doing, I'm glad you asked. ;)

It's for a satellite receiver system here at the radio station I work for. (WIHS FM in the USA) I'm building a "status display" system that will react to various status line outputs from that receiver, and a reset button for users to temporarily stop the flashing lights. (So they won't be distracted while they go on the air to read news or weather.)

There are three outputs from the receiver: "Weak signal", "No Signal" and a "Moody Network Message alert". The "Message Alert" lets us know that the satellite network has sent out an e-mail with important information about something on the network. (It is called "Moody" because it is named after the famous Evangelist, D.L. Moody.)

The "Message Alert" is only a momentary "LOW" input, so it needs to "latch" a blue LED on. (I have that part working, I'm working on getting the RESET button to clear it, now.)

The "Weak" input will light a yellow LED and the "No signal" input will light a bright red flashing module.

The RESET button will only PAUSE the flashing for 4 minutes. (A smaller red LED will always be lit.) The flashing will resume, as long as the "NO SIGNAL" input is still active. Only clearing the problem will stop the alarm. (When the satellite dish gets snow in it, it affects the signal. We need to alert someone to get out there and sweep it out!)

When there are no active inputs, a white LED glows. ANY active input extinguishes it... this will be more for diagnostics than actual use. I'm considering just using the GREEN one... this whole thing is only in the very earliest stages of development right now.

For anyone that is curious, here is the program, as it exists now... the inputs & LED's are working... the blue latches, but I haven't figured out the reset code to "un-latch" it, just yet. This is only VERY early in the development process! :)

Code:
#no_data; Don't update EEPROM areas to save upload time
#picaxe 20m2;Force compiler mode to the correct chip
;-----------------------------------------------
; This program is written for the 20M2 chip by Willie...
; Started: 02/06/2017
; Last updates: V0.00 ~ 2/15/17
; Current Version & Date: V0.01 - 2/20/17 - Tweak date: 3/1/17
; Working on I/O 3/1/17 - No VERSION increments until more advanced
;-----------------------------------------------
start: 
sertxd("Sat System Alerter V0.01",cr,lf);Identify chip program at power-on
	let dirsb = %00000000		; set port b as inputs
	let dirsc = %11111111		; set port C to outputs
	pullup on ; Turn on the internal pullup resistors for inputs

symbol BLU = pinc.5 ; Blue LED ; Lights if there has been a "Moody Message Alert"
symbol WHT = pinc.4 ; White LED ; Used to indicate any input active for diagnostic/testing
symbol FLASHER = pinc.3 ; Big flashing indicator, resettable for 4 mins until alert cleared.
symbol GRN = pinc.2 ; Green LED Steady = OK  (possible changes coming)
symbol YEL = pinc.1 ; Yellow LED (currently lights for more than one active input)
symbol RED = pinc.0 ; Red LED (NO SIGNAL Warning indicator, stays on until cleared)
symbol MOODYLIGHT = b3 ;Variable to "latch" the blue light

symbol MOODY = bit1 ; Input for Moody Message Alert relay
symbol RSET  = bit2 ; Input for reset button (Only pauses the flasher for 4 mins & clears Moody Msg Alert)
symbol FAULT = bit3 ; Input for NO SIGNAL WARNING (Flasher & red LED)
symbol WEAK  = bit4 ; Input for WEAK Signal warning (Yellow LED)

main:
pause 100 ; Slow things down a bit
WEAK = not pinb.7 ; Invert inputs so a LOW (active) input = 1 (Applies to all 4)
FAULT = not pinb.6
RSET = not pinb.5
MOODY = not pinb.4

FLASHER = FAULT ; Flash the big light if NO SIGNAL
GRN = RSET ; (Temporarily, lights when the reset button is pressed)

let b2 = MOODY ;For latching logic
if b2 = 1 then 
	MOODYLIGHT=1 ; Turn on the LED if this input is active
endif
RED = WEAK ; Using RED LED for now
let B1 = FAULT | RSET | MOODY | WEAK ; White LED goes dark if ANY input is active
WHT = not b1
let b4 = FLASHER + GRN + MOODYLIGHT + RED ; Add up the number of active inputs
YEL = 0
if b4 > 1 then	; Light the YELLOW LED only if more than one input is active (Temporary diagnostic tool)
YEL = 1
endif 
BLU = MOODYLIGHT ; LED follows latch variable status
if b2=1 and RSET = 1 then ;This should clear the BLU LED with RSET but isn't
	b2=0
	MOODYLIGHT=0
endif

goto main
Only 4 emoticons per message? Interesting.

Willie...
 

Willie...

New Member
I just fixed the reset for the blue LED. :)

Code:
BLU = MOODYLIGHT ; LED follows latch variable status
if RSET = 1 then ;This clears the BLU LED
	b2=0
	MOODYLIGHT=0
endif
Willie...
 

Willie...

New Member
Try this for light show :
Code:
[color=Blue]symbol WEAKout  [/color][color=DarkCyan]= [/color][color=Blue]b.7
symbol [/color][color=Purple]WEAK  [/color][color=DarkCyan]= [/color][color=Purple]pinb.7[/color]
[color=Blue]symbol [/color][color=Purple]RED [/color][color=DarkCyan]= [/color][color=Purple]pinC.0
dirC.0[/color][color=DarkCyan]=[/color][color=Navy]1[/color]
The flashing light display is a module. All it needs is a "HIGH" input, and it flashes. A "LOW" turns it off, so that makes programming the PICaxe that much easier.

Thanks, tho. :)

Willie...
 
Top