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.
The seminar sessions form the core of the practical work in this module. We will be using the FRDM-K64F ARM based platform. The practical work will have two themes, one based on the MBED libraries and abstractions, the other based on a pure C clean room implementation.
The MBED libraries are written in C++ and are a generic set of functions that abstract out the behaviour of supported devices. The device vendor provides an implementation of the routines on their device.
The seminar sessions are numbered 01, 02,… this is roughly aligned with the weeks in the semester, but it isn’t a fixed mapping.
Within each seminar exercises are numbered 1, 1,… the associated Githib repository is called s1.1 etc. Question parts an solutions are tagged as releases,
You should study the Getting started notes to see the workflow that is recommended for the practical work.
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.
Handling events, button interrupts and timer interrupts. We want to be able to respond to external events, as they occur. Or to create a precisely timed series of events.
Analogue IO.
Take the opportunity to make sure you are up to date with the exercises.
Managing timings, threads, and events.
In this seminar we’ll look at simple networked communications using UDP sockets.
Control of systems
These exercises introduce you to using the LCD display on the applications board. This is a simple black-and-white display of 128 x 32 pixels. The top left corner of the display is at (0,0) and the bottom right corner of the display is at (127,31). At the end of these exercises you should be able to
Obtain a copy of the repository LCD in
your usual way. Open the folder in Atom. Build, download and run the code.
Check that you can see some output on the LCD display. Now open the
file main.cpp
. Notice the lines
#include <C12832.h>
// Using Arduino pin notation
C12832 lcd(D11, D13, D12, D7, D10);
This shows you how to include the library header for the display and
how to declare a variable (lcd
) of the appropriate type (C12832
) to
access it. C12832
is a class that provides the methods that we can use to
work with the display. Have a look at the description of the
methods of the C12832 class to see what methods
are available and how to use them. The rest of these exercises will require
you to study this page carefully. Check your understanding by answering the
following questions.
display
that you could
use to interact with the LCD? What are the advantages and disadvantages
of declaring this as a global variable? If it was declared as a local
variable, e.g. in main()
, how would it be possible to write to the
display from any other function?lcd
variable in the example in the repository,
identify what sort of communication bus is used by the microcontroller
to interact with the LCD display.The mbed
library provides macros called MBED_MAJOR_VERSION
,
MBED_MINOR_VERSION
and MBED_PATCH_VERSION
. The macros all evaluate
to integers. It’s sometimes helpful to look at these values to see what
version of the library has been used to build your program. Write a program
to display a string on the LCD that shows the value of each of these macros,
separated by .
characters, e.g. 5.7.1
Write a program that allows you to work out what is the maximum number of lines of text that you can display at the same time on the LCD, using the current font. Write a similar program to work out the maximum number of characters per line. Experiment to find out what happens if you try to exceed these limits.
Write a program to display the current values of the potentiometers. When the board is held the right way up to read the LCD, Pot 1 should be on the left and Pot 2 on the right. Display their values to 2 decimal places, like this:
L: 0.34
R: 0.68
Your program should execute in a loop with a short time delay and should repeatedly update the display. Experiment with the delay needed to keep your system responsive. Note: You may need to refer to repository s3.1 to remind yourself how to read the value of the potentiometers.
Write some simple programs to become familiar with the graphics methods, e.g.
Experiment with these, and similar, programs until you are confident that you understand the main graphics methods.
Now write a program that uses both text and graphics to show the status of the potentiometers. You should distinguish between the potentiometers using L and R, as in the earlier exercise, but instead of displaying the value of each potentiometer in a text field, show its value using a combination of an open and filled rectangle. The proportions of the open and filled parts should be determined by the potentiometer value, e.g. if the value of the potentiometer is 0.75, then the rectangle should be 75% filled and 25% unfilled.