Digital Signals

Here we look at the digital input and output from the device. The typical hardware devices that handle the physical aspects of digital signals are LEDs and Switches.

  1. LED output
  2. Push Button input
  3. Application Shield IO
  4. exercises
  5. extension

LED output

Clone the repository s1.1 this contains a basic blinky program.

Build the program and upload it into the FRDM-K64F. Once done you will need to press the reset button.

resources

  1. Refer to the LED diagram in the FRDM K64F Userguide section 10, page 14 for pin connections.
  2. Summary of important pin names
  3. An overview of the board and the mbed library

The start point is (s1.1):

#include <mbed.h>

int main() {

    DigitalOut red(PTB22);

    while(1) {
      red.write(0);
      wait(0.5);
      red.write(1);
      wait(0.5);
    }
}
  1. Using the FRDM K64F Userguide and/or the FRDM K64F Schematic, identify the pins that drive the Green and Blue LEDs on the board. Green LED pin PTE26 (aka LED_GREEN), Blue LED pin PTB21 (aka LED_BLUE)
  2. Modify the program to manage the Green and Blue LEDs in addition to the Red LED. solution 1.1
  3. Modify the flashing pattern to make use of all three LEDs. solution 1.1
  1. What value needs to be written to the pin in order to
    • turn the LED on?  0 
    • turn the LED off?  1 
  2. From the Schematic can you identify why the values are what they are?
    What is pin-2 of the LED package connected to?


Pin-2 of the LED package is connected to 3.3V (logic high/1).
If a 1 is output from the pin it is at 3.3V, there is no voltage difference across the LED so it does not light.
Output a 0 there is a voltage difference and so the LED turns on.

  1. Write a wrapper that provides functions for on(), off(), and/or set() that takes into account the way the LEDs are wired.

solution 1.1

Push Button input

Clone the repository s1.2.

This is the base level LED driver from s1.1 with the addition of a single push button (One of the two on the base board.)

#include <mbed.h>

#include <stdbool.h>

int main() {
    bool flashing = false;

    DigitalOut red(PTB22);
    DigitalIn  btn(PTC6);

    while(1) {
        if( btn.read() ) flashing = true;
            else         flashing = false;

        if(flashing){
            red.write(0);
            wait(0.5);
            red.write(1);
            wait(0.5);
        }else{
            red.write(1);
        }
    }
}
  1. Locate the buttons (switches SW2 and SW3) on the FRDM K64F Schematic.
  2. Using the schematic and observing the behaviour of the program what can be deduced about:
    • What value is read when the button is
      • pressed?  0 
      • not pressed?  1 
    • Why is this the case?

    The Pins are connected to 3.3V via a pull-up resistor, so the pin reads a logic 1 when the button in not pressed. Pressing the button creates a direct connection to ground (0V) so the pin reads a logic 0

  3. Add a wrapper function that evaluates as bool ispressed( /*button*/ ) that returns the correct state of the button.
    solution 1.2

Application Shield IO

The Application Shield has a second RGB-LED and a 5-way joystick like switch.

  1. Refering to the Application Shield Schematic,
    • Identify the pins that drive the shield RGB-LED
  2. Extend the capabilities of the LED wrapper functions to include the Shield’s LEDs. solution 1.3
  1. Find the 5-way switch on the schematic
    • Is it wired the same way with respect to the ground and 3.3V signals?
      No. The switches are wired the opposite way round.
    • What will the impact be on the implementation of the ispressed() function?
      Not nice, I need to invert some pin readings and not others. Solution look at the truth table for (a xor true)
  2. extend the capability of the ispressed() function to include the application shield.
    solution 1.4

exercises

extension

explore plain C bare-metal code.

  1. gate clock signals
  2. configure pin
  3. set gpio state
  4. set,clear,toggle

© 2017   Dr Alun Moon
alun.moon@northumbria.ac.uk