Help with BS2 and 74HCxx logic!
AwesomeCronk
Posts: 1,055
in BASIC Stamp
I have decided to write up a PBASIC 2.5 program to identify different logic gates. IT DOESNT WORK!! I think I am having issues reading the input. I have tested with a 74hc02 NOR chip, got a test failure in debug three times. the fourth time, it identified the chip as a NAND gate. I ahve tested the gate by hand, so I know that it is indeed a functioning NOR gate. Here is the code and the output from debug when it thought it had a NAND gate.
Code:
Debug:
I notice that the block which singles out the gates by their results works, but IN2 tends to read high. Should I maybe have a 200ohm pulldown resistor on P2?
Code:
' {$STAMP BS2} ' {$PBASIC 2.5} AndGate VAR Bit 'Declare variables for gate IDs OrGate VAR Bit XorGate VAR Bit NandGate VAR Bit NorGate VAR Bit XnorGate VAR Bit NotGate VAR Bit Main: DEBUG CLS, "Logic Tester ready." PAUSE 250 AndGate = 1 'Set all variables high, eliminate them as we go. OrGate = 1 XorGate = 1 NandGate = 1 NorGate = 1 XnorGate = 1 NotGate = 1 DEBUG CR, "Testing gate..." LOW 0 'Set both outputs LOW, eliminate different gates by their outputs. LOW 1 DEBUG CR, BIN IN2 'Each IF..THEN block has a DEBUG statement to give the gate output as read by IN2. IF IN2 = 0 THEN NandGate = 0 NorGate = 0 XnorGate = 0 NotGate = 0 ELSEIF IN2 = 1 THEN AndGate = 0 OrGate = 0 XorGate = 0 ENDIF HIGH 0 'Set the first output HIGH, eliminate different gates by their outputs. DEBUG CR, BIN IN2 IF IN2 = 0 THEN OrGate = 0 XorGate = 0 NandGate = 0 ELSEIF IN2 = 1 THEN AndGate = 0 NorGate = 0 XnorGate = 0 NotGate = 0 ENDIF LOW 0 'Set the first output LOW and the second output HIGH, eliminate different gates by their outputs. HIGH 1 DEBUG CR, BIN IN2 IF IN2 = 0 THEN OrGate = 0 XorGate = 0 NandGate = 0 NotGate = 0 ELSEIF IN2 = 1 THEN AndGate = 0 NorGate = 0 XnorGate = 0 ENDIF 'Set the first output HIGH, eliminate different gates by their outputs. HIGH 0 DEBUG CR, BIN IN2 IF IN2 = 0 THEN AndGate = 0 OrGate = 0 XnorGate = 0 ELSEIF IN2 = 1 THEN XorGate = 0 NorGate = 0 NandGate = 0 NotGate = 0 ENDIF DEBUG CR, "Gate test complete. " IF AndGate + OrGate + XorGate + NorGate + XnorGate + NandGate + NotGate = 1 THEN 'If the test was successful, then only one variable will still be 1. DEBUG "The gate was successfully identified as a " IF AndGate = 1 THEN 'Declare the results of the test, tell which gate was still in. DEBUG "AND" ELSEIF OrGate = 1 THEN DEBUG "OR" ELSEIF XorGate = 1 THEN DEBUG "XOR" ELSEIF NorGate = 1 THEN DEBUG "NOR" ELSEIF XnorGate = 1 THEN DEBUG "XNOR" ELSEIF NandGate = 1 THEN DEBUG "NAND" ELSEIF NotGate = 1 THEN DEBUG "NOT" ENDIF DEBUG " gate." ELSE DEBUG "The device failed to identify the gate." 'If there was more than one gate still in, or if they were all out, then the test failed. ENDIF DEBUG CR, "Reset device to perform another test.", CR, DEC AndGate, CR, DEC OrGate, CR, DEC XorGate, CR, DEC NorGate, CR, DEC XnorGate, CR, DEC NandGate, CR, DEC NotGate 'Give the closing message and show the results of all the gates. END
Debug:
Logic Tester ready. Testing gate... 1 1 1 1 Gate test complete. The gate was successfully identified as a NAND gate. Reset device to perform another test. 0 0 0 0 0 1 0
I notice that the block which singles out the gates by their results works, but IN2 tends to read high. Should I maybe have a 200ohm pulldown resistor on P2?
Comments
00 = (add 1 if high)
01 = (add 2 if high)
11 = (add 4 if high)
Then look at the value of the variable:
0 = Stuck Low
1 = NOR
2 = XOR
3 = NAND
4 = AND
5 = XNOR
6 = OR
7 = Stuck High
Bean
AND: 74x08
NAND: 74x00
OR: 74x32
NOR: 74x02 *Pinout not the same as other four
XOR: 74x86
Be very careful to note the 02 has a unique pinout. That bit any number of old-school logic board designers in the 70s.
Power to the gate pack is correct. You say it is an x02 so the output is pin 13 (light blue wire), connected to BS2 pin 2.
You are applying inputs on 11 and 12; good so far.
I would connect pin 13 to a LED (through a, say 1K, resistor) (disconnect BS2 pin 2). Now exercise the gates inputs and see that the gate works correctly (either high makes a low). If not, you have killed the gate. If so, you got a bug in your program.
LEDs:
In>--[+LED-]--{Gnd}
Switches:
In>--[220]--|--[10k]--{Gnd}
|--[Switch]--{5v}
Have you looked at any of the datasheets?
Voltage levels, timing values, pin numbers and functions, etc are all there.
Awesome, are you able to scope IN2 to see if it is actually being driven correctly by the device under test?
Most logic devices can sink current up to a couple tens of mA, and that's noted as Iol on the respective datasheet. However, the drive high current (Ioh) is typically a few hundred uA. I wonder if IN2 is in a state that is sinking all that current and not allowing the device under test output to rise to its Voh.
I assume you are giving the logic chips 5V and what are you doing with the unused pins?
If the BS2 is driving a pin HIGH (or LOW) it is either because the BS2 is broken or it is being programmed to drive that pin. My money would always be on the programmed case. Oftentimes programs left over in the PROM from earlier projects have unexpected consequences. Write and download a little program so that you know what the BS2 is supposed to do. For example
Are your logic chips Chinese clones or older name brand?