Logic Gate Analyser With Cytron EDU PICO or Adafruit CLUE Demonstrated With MH-EDU-Electronics LogicBoard and Kitronik Inventor's Kit

by kevinjwalters in Circuits > Electronics

815 Views, 5 Favorites, 0 Comments

Logic Gate Analyser With Cytron EDU PICO or Adafruit CLUE Demonstrated With MH-EDU-Electronics LogicBoard and Kitronik Inventor's Kit

lga-edupico-logicboard-xor1-65.jpg
lga-clue-inventorskit-nor1-65.jpg

This article shows a logic gate analyser. The program observes the inputs and outputs on any logic gate gradually filling in a truth table on the display. The symbol for the logic gate appears when the truth table is complete and the gate is identified. This program could be useful as an aid for learning about logic gates.

The CircuitPython program has been developed for and tested on the Adafruit CLUE and the Cytron EDU PICO, a Pi Pico WH-powered descendent of the BBC micro:bit-based EDU:BIT.

The program is demonstrated in this article using

The program uses the SSD1306 displayio driver when not running on the CLUE to provide a consistent displayio interface. This is compatible with the SSD1315 screen on the EDU PICO. This driver allows many small, affordable displays to be used with almost any CircuitPython compatible board as an alternative hardware setup.

Instructables: Making a Full Adder With LogicBoard From MH-EDU-Electronics includes more information about the logic gate board.

The EDU PICO board in this article is a sample that Cytron kindly sent to me to evaluate.

Supplies

  • Microcontroller
  • Option 1
  • Adafruit CLUE: Kitronik | DigiKey (this has the same edge connector as BBC micro:bit.)
  • Adapter options
  • Four crocodile (alligator) leads might be viable.
  • Kitronik Edge Connector Breakout Board for BBC micro:bit (part of the Kitronik Inventor's Kit.)
  • Adafruit DragonTail for micro:bit: DigiKey - another useful connector intended for use with breadboards.
  • Option 2
  • Cytron EDU PICO: DigiKey
  • Five jumper wires or a Grove adapter to jumper wires and one jumper wire: DigiKey
  • Option 3
  • Any board which supports CircuitPython (needs to have ulab library in the build) with a display or an external SSD1306 display (using i2c).
  • Suitable leads to connect to logic gates.
  • Logic gates
  • MH-EDU-Electronics LogicBoard: Tindie
  • Kitronik Inventor's Kit: Kitronik | DigiKey - this has enough components to construct gates like NOT, NOR and NAND.

Introduction to the EDU PICO

edupico-lipo-demosw-usblight-1-43.JPG
edupico-box-contents-1-43.JPG
edupico-lipo-demosw-anim-1-43.JPG
edupico-box-1-65.JPG
edupico-box-contents-2-43.JPG
edupico-box-contents-3-43.JPG
edupico-board-accessories-1-65.JPG
edupico-lipo-demosw-rgb-1-43.JPG

The Cytron EDU PICO is a large sensor-packed board using a socketed Pi Pico WH microcontroller board. It's similar to the excellent EDU:BIT following a similar layout with the ingenious snap-off modules which can be reconnected with Grove cables. There are a few major differences listed below with the EDU:BIT equivalent in round brackets.

  • Uses the Pi Pico WH which includes Wi-Fi capabilities (EDU:BIT is designed for BBC micro:bit V1 or V2);
  • The accompanying 188 page book and quick reference cards use CircuitPython in Thonny editor (block-based MakeCode).
  • Power options are terminal block, JST-PH with LiPo charging or micro-USB (USB adapter for a 2.1mm barrel).
  • 128x64 monochrome display (micro:bit's 5x5 LED matrix).
  • Lots of extra peripherals: micro SD card slot, AHT20 temperature/humidity sensor, APDS9960 proximity/gesture/colour/light sensor, USB A port for relay-controlled 5V power and a proto board for small soldered projects.

The choice of programming language and advanced features suggest it is intended for progression beyond the EDU:BIT.

For more information see Cytron's EDU PICO resource hub and Les Pounder's review of the EDU PICO on Tom's Hardware.

Installing CircuitPython and Program on EDU PICO and CLUE

circuitpy-fs-lga1.png

If you are not familiar with CircuitPython then it's worth reading the Welcome to CircuitPython guide first.

  1. Install the latest version of CircuitPython (9.0.4 on May 2024) from https://circuitpython.org/ - this process is described in CircuitPython for Adafruit CLUE. The EDU PICO will have a version of CircuitPython already installed on it together with some libraries in the lib directory.
  2. Verify the new installation by connecting to the serial console over USB. The REPL prompt shows the version number. The version can also be checked by inspecting the boot_out.txt file on the CIRCUITPY drive.
  3. Install this library from a recent bundle from https://circuitpython.org/libraries into the lib directory on CIRCUITPY:
  4. adafruit_display_text
  5. adafruit_displayio_ssd1306.mpy (not adafruit_ssd1306.mpy)
  6. Download the example program to CIRCUITPY by clicking Save link as... on logic-gate-analyser.py and on the extra graphics library ymgp.py.
  7. Rename or delete any existing code.py file on CIRCUITPY, then rename the logic-gate-analyser.py to code.py. This file is run when the CircuitPython interpreter starts or reloads.

The versions used for this article were:

  • CircuitPython: 9.0.4 (9.0.0 to 9.0.2 are buggy)
  • CircuitPython library bundle: adafruit-circuitpython-bundle-9.x-mpy-20230513

Design

screendesignlayout1.JPG

The CircuitPython program has to perform the following steps.

  1. Observe the two inputs and one output of a two input logic gate.
  2. Display the truth table on the screen and update it as the different combinations of inputs are observed.
  3. Look up the gate which matches the truth table when it's complete.
  4. Draw the logic gate symbol on the screen.

There are a few issues to deal with for observing the inputs.

  1. The propagation time for the output to change when when inputs have changed (gate delay).
  2. Brief erratic inputs due to either switch bounce or a person manually connecting a wire to low or high.
  3. Inputs and outputs will not necessarily be at exactly 0.0V for low and 3.3V for high.

The gate delay is likely to be in the tens or hundreds of nanoseconds making it very unlikely to cause a problem for a program running on an interpreter. The various forms of contact bounce could be problematic - looking at the inputs with frequent sampling over a period of time and then checking for a high percentage of consistent values sounds like a feasible approach to deal with this.

The digital inputs on a microcontroller will typically register high for values above about half the supply voltage (1.65V) and low for those below. If analogue inputs are available then the program can make its own decision about how to convert the voltage to a digital logic level.

The fonts, symbols and layout may need to be adjusted for different screen resolutions, aspect ratios and colour depths. The CLUE has a 240x240 pixel (square) 18bit display, the EDU PICO has a 128x64 pixel (2:1 ratio) monochrome display.

The two buttons could be used to change the number of inputs and to clear the truth table.

Demonstration on EDU PICO With LogicBoard CMOS Gates

Logic Gate Analyser on Cytron EDU PICO and MH-EDU-Electronics LogicBoard #CircuitPython

The EDU PICO can easily be connected to the LogicBoard using a Grove adapter cable. This provides power and two GPIO which can be used as inputs. The gate's output also needs to be connected - the four GPIO intended as outputs to drive servos are unused here allowing one of those to be used as a third input to connect to the gate's output.

  • Grove 9 connector (middle left) connects
  • 3V3 to logic 1 (red),
  • GND to logic 0 (black),
  • GP26 to top input of the XOR gate (white) and
  • GP27 to bottom input of the XOR gate (yellow).
  • GP6 (top left pin on servo block) has a jumper wire connecting to the output of the XOR gate (green).

The video shows these connections being made together with the EDU PICO being connected to USB power via the Pi Pico WH. The EDU PICO board is then turned on and the logicians toggle the A and B LogicBoard switches to go through all of the combinations for the truth table.

It is very important to get the power wires going to 0 and 1 on the LogicBoard the correct way around. The LogicBoard only has reverse polarity protection for power supplied from its barrel connector.

Diode Transistor Logic

logic-family-tree.png

Electronic logic gates can be created with a variety of components. The early Diode-Transistor Logic (DTL) was eclipsed by Transistor-Transistor Logic (TTL) and CMOS but a DTL design happens to work well with the small number of components available from the Kitronik Inventor's Kit.

Light-emitting diodes can substitute for normal diodes with some care around the considerably higher forward voltage. The unidirectional conductance feature of diodes (here in LED form) is required on each input. The visual indication of the input state by the LEDs (off for low, illuminated for high) can be an additional useful feature or a potential source of confusion if the value is inverted!

DTL NOR and NAND Gates

fcs-primitive-nor.gif
fcs-primitive-nand.gif

The two animations above show a primitive NOR gate (circuit simulator) and NAND gate (circuit simulator) created in the diode-transistor logic style implemented using the Kitronik Inventor's Kit's components in Falstad Circuit Simulator.

The logic levels are shown as L for low and H for high, the associated voltage levels are also shown for this 3.3V powered circuit. The symbols for the LEDs unfortunately do not show their polarity, for the pair on the inputs of the NOR gate the (conventional) current flows from left to right and for the NAND from right to left. The LEDs on the NAND gate visually indicate the inverted value of each input.

Resistors in parallel are used to create lower values not present in the kit, e.g. three 2.2k resistors in parallel are equivalent to a single 730 ohm resistor.

These gates are just examples and are unlikely to be power efficient, fast or work well when connected to other gates.

Demonstration With CLUE With DTL NOR Gate Using Inventor's Kit

lga-clue1.gif

A NOR gate has been constructed on the breadboard of a Kitronik Inventor's Kit following the circuit shown on the previous page. The Adafruit CLUE provides power at 3.3V and the program monitors the gate via P0, P1 and P2. The connectivity is listed below.

  • 3V to upper red/pink power rail (red).
  • 0V to lower blue power rail (black).
  • Pin 0 to top input of the NOR gate (white).
  • Pin 1 to bottom input of the NOR gate (yellow).
  • Pin 2 to output of the NOR gate (green).

The logicians jump on the A and B input buttons (with the aid of some added pressure from jewellers' screwdrivers) to go through all of the combinations for the truth table.

A Look at Contact Bounce and Propagation Time on DTL NOR Gate

zoyiscope-dtl-norgate-contactbounce.JPG
zoyiscope-dtl-norgate-buttondown.JPG
zoyiscope-dtl-norgate-buttonup.JPG

An oscilloscope with a capture feature can be used to look for contact bounce and examine the propagation time of the logic gate. A Zoyi ZT-703S is used here with CH1 (yellow) connected to the anode of the output led and CH2 (cyan) connected to the anode of one of the input leds and set for single event trigger. Both probes are set to 10x to minimise the likelihood of affecting the circuit.

The small push-to-make button on the breadboard** is surprisingly good for a transition from off to on and good for on to off - it took about ten captures to get this long duration bounce. This button is a few years old but has never been used and was still in its sealed plastic bag. The capture above at 200us per division shows the button being released with a small initial drop in voltage over ~50us then a drop to 0V for ~80us but then backup to 3.3V for ~1100us (1.1ms) then finally back down to 0V.

The oscilloscope is running faster at 250ns per division to look at the propagation time. This is based on inputs from mechanical buttons which would not be the approach for a value in a datasheet.

  • button down (input from low to high): The delay for input to cause the output to fall below the midpoint voltage (1.5V is being used to represent this here, slightly below 1.65V) is ~150ns, for below 0.5V it's ~280ns.
  • button up (input from high to low): The delay for input to cause the output to rise above the midpoint voltage is ~1360ns, for above 2.5V it's ~1780ns. This is considerably higher than the button down time. Broadly speaking, there appear to be two types of delay observed here for many button ups, this is the longer version.

The exact values aren't that important here, the key observations are

  • the gate delay is small but isn't zero and
  • it can vary on whether an input is changing from low to high or high to low*** and how rapidly that change occurs.

The trigger level on CH2 (gate's input) was set to the midpoint voltage for these captures. It would be better to use a low voltage for the rise and a high voltage for the fall as contact bounce can cause some initial small voltage changes.

** A breadboard adds parasitic capacitance between the rows which is likely to affect the performance of the logic gate.

*** P-n junctions in diodes and bipolar transistors have a junction (or depletion) capacitance (Cj) and a diffusion (or charge storage or transit time) capacitance (Cd), the latter is more significant for a forward-biased diode and is the likely dominant factor for the slow button up times.

1960s RTL Logic Gates

11661h.jpg
fairchild-catalog-1965-ul915-reformatted-65.jpg
agc-blockii-dual3nor-mitschematic.jpg

It's interesting to compare the improvised DTL NOR gate with the designs of the early logic gates for some of the first commercial integrated circuits. The images above are:

A recreation of the AGC NOR gate cites typical values of 450 ohms for the six base resistors and 680 ohms for the two collector resistors.

Going Further

lgis-mdic-1-65.jpg

The low-relevance image above is from Microsoft's Image Creator given a prompt asking for logic gate symbols floating in space being sucked into a blackhole.

Here's some ideas for areas to explore:

  • Add support for one input and more than two inputs.
  • Add an identify mode where the microcontroller outputs values to the logic gate inputs to automatically identify a logic gate.
  • Add a check of the analogue voltage levels to report on how close the logic values are to 0.0V and 3.3V or whether they are in the permissible input range for a logic family like CMOS.
  • Complete the logic gate library for all combinations of inputs and outputs.
  • Look at a port to the BBC micro:bit - it has a limiting 5x5 LED matrix display but this may still be viable with some thought about representation of the data.
  • Investigate adding support for sequential logic.
  • Try different arrangements on a breadboard for DTL logic gates to see if the gate delay changes due to changes in parasitic capacitance.

Related projects:

There is a list of commercial products containing logic gates at the end of Instructables: Making a Full Adder With LogicBoard From MH-EDU-Electronics. Kitronik offer a Digital Logic Pack for Kitronik Inventor's Kit for the BBC micro:bit which contains some dip 4000 series CMOS logic chips.

Further reading: