4. Simple Circuits, Switching, and Logic

4.1. Purpose

Basic concepts in producing inputs and outputs for connection to an embedded system are introduced. Inputs are demonstrated with switches (pushbutton and slide switches), with various combinations producing specific logic outputs. Outputs are are displayed using LEDs.

4.2. Hardware and Tools

  • [USB Test Device]: ADALM1000, ADALM2000, or Analog Discovery

  • Breadboard (provided in parts bag)

  • Components (provided in parts bag):

    • 2x Pushbuttons

    • 1x Slide Switch

    • 1x LEDs

    • 1x BiColor LED (BiLED)

    • Various Resistors (1x 330Ω,2x 1kΩ)

  • Wire (available in classroom)

4.3. Description

The basic building blocks for any embedded system are the Inputs, Outputs, and the Processing. For this class, the Processing block will always be the MSP432P401R microcontroller and we will use various Inputs and Outputs. For example, a simple system might be represented by the schematic below, where there are three inputs: PB1, PB2, and SS1 (two pushbuttons and a slide switch), and two outputs: LED1 and BiLED1 (an LED and a BiColor LED).

In this activity, we look closer at the Inputs and Outputs to hopefully understand the pieces a little better and also to build an understanding of why Processing is so useful in an embedded system as opposed to building “dumb” circuits.

../_images/final_uC.png

Don’t build this! (yet)

4.4. Instructions

For all questions below, you may answer them on either a piece of paper or in a computer document.

4.4.1. Inputs

We will first explore inputs as generated by pushbuttons. These inputs are known as Digital inputs as they can only produce one of two states: True or False. As a note, you might also see True represented as High (HI) or 1. Similarly, False can also be referred to as Low (LO) or 0.

A pushbutton serves to either connect (close) or disconnect (open) an electrical circuit. Let’s consider the circuit as described below (left), where a pushbutton can connect the Input line to Ground (GND). There is a distinct problem with this circuit which we will explore in the first task; which should be clear from the lecture.

Warning

Note that neither 5V or 3.3V are used for the circuit below; only ground and an input channel.

If using the ADALM1000 board: Ensure that your measurement channel is not producing a voltage. That is, CHA and CHB should be in Hi-Z mode in the AWG Window when using the oscilloscope or set to OFF when using the Multimeter mode.

../_images/basic_pushbutton.png
  1. Testing the basic pushbutton circuit. You may skip this task if the problem with the above circuit is already clear to you.

    1. Build the above pushbutton circuit and connect the Oscilloscope lines from your USB Oscilloscope to the points as indicated on schematic on the right. Note: if you are using the ADALM1000, CH1+ would be AIN, and CH1- may be omitted.

    2. Turn on the oscilloscope and configure the window such that you can clearly see the measured voltage waveform.

    3. Press and release the pushbutton.

      1. Did you notice any change in the output? Specifically, did you see a significant voltage level change?

      2. Would this circuit be useful as an input to a system?

Now let’s look at a slightly different circuit:

../_images/pushbutton_with_pullup.png
  1. Add the resistor and 5V connection as shown in the circuit above. For the ADALM2000 and Analog Discovery boards, don’t forget to enable your 5V supply!

    1. Press and release the push button.

      1. Did you notice any change in the output? Specifically, did you see a significant voltage level change?

      2. Would this circuit be useful as an input to a system?

    2. Complete the truth table below with either True and False or 1 and 0:

      Pushbutton State

      “Input” Value

      Pressed

      Released

  2. Now lets switch the components around. Build the circuit below and answer the questions above again.

../_images/pushbutton_with_pulldown.png
  1. You should have noticed that one of the circuits built in steps 2 and 3 produced an inverted response to the pushbutton press. Why?

  2. Let’s try a more complicated circuit with a slide switch. Build the circuit in the figure below. You’ll need both your oscilloscope channels to test this one, one for Input_1 and the other for Input_2.

    ../_images/pbs_w_switch.png
    1. Complete the truth table for this circuit. Assume that the slide switch On value is when it passes the 5V connection.

      PB1

      PB2

      SS1

      Input_1

      Input_2

      Released

      Released

      Off

      Pressed

      Released

      Off

      Released

      Pressed

      Off

      Pressed

      Pressed

      Off

      Released

      Released

      On

      Pressed

      Released

      On

      Released

      Pressed

      On

      Pressed

      Pressed

      On

    1. While this “complex” circuit above demonstrates the possibilities for building logic with switches (and in the same vein, transistors), the usefulness of such a structure is reduced when using a microcontroller. Assuming you have three independent inputs within a program, PB1, PB2, and SS1, which are all independent of each other, what is the effective binary (Boolean) logic commands that could be used to generate the equivalent value for variable Input_2 in terms of AND (&), OR (|), and NOT (~) operations?

4.4.2. Outputs

Similar to the pushbuttons and slide switch providing a digital input to a microcontroller, the microcontroller can also provide a digital output for applications including control, communication, user interfaces, etc. For this activity, we’ll consider an LED and a BiColor LED (BiLED).

  1. Modify the last build schematic by adding in a single LED and BiLED as shown.

    ../_images/pbs_w_switch_and_LEDs.png
    1. Add two more columns to the truth table above to denote the state of the LEDs. LED1 can only be on or off, whereas BiLED1 can be red, green, or off. Do not reanalyze Input_1 and Input_2.

    2. What are the states of Input_1 and Input_2 that cause the BiLED1 to be off and why?

  2. Take a picture of your final circuit and submit with your answers to the above questions and completed tables to the corresponding Gradescope assignment.

This final circuit is effectively a “dumb” circuit that could be replaced by the first schematic contained on this page; however, in using the microcontroller, it is also possible to make quick and easy changes to the final truth table through code alone, as opposed to rebuilding the circuit for each desired instance. That is, a simple software edit is all that is needed as opposed to a physical hardware reconfiguration.