We have a new computer for the course for this year (spring 2016). The board is a low-priced (about $13 each) evaluation system made by Texas Instruments to introduce people to their TivaC series of microcontrollers based on the ARM Cortex-M4 processor core. These are the most powerful computers that I have used in this course for more than a decade. With more power comes more complexity, which makes systems harder for the beginner. This is why I have been using rather simple systems for the past decade or so, although they have severely limited the scope of the programs that could be written.
The change has been made possible by the Energia system. This is a freely available development system that mimics the extremely popular Arduino programming system that has gained worldwide popularity over the past 5 years or so.
We will start with a short introduction to the TM4C123G processor and the LaunchPad board before moving on to what Arduino and Energia have to offer.
The computer world in 2016 is dominated by two architectures, the Intel architecture with names like Atom, Celeron, and Core-i7, and the ARM architecture. At the moment Intel is dominant in the desktop, laptop, and server worlds while ARM is dominant in the mobile world of tablets and smartphones as well as showing up in lots of embedded systems such as cars and Internet of Things devices. Unlike Intel, ARM does not make computers. Instead it licenses its design to lots and lots of different manufacturers who combine an ARM CPU with some special sauce of their own to make a wide variety of different kinds of chip. Broadly, these fall into two classes; application processors and microcontrollers. Our TM4C123 is an ARM-based microcontroller.
These are CPUs designed to run at very high speeds and to address a ton of memory. They are intended for use in devices which more or less look like computers. Examples include tablets and smartphones as well as fancier car entertainment systems and GPS mapping devices. Many of these are 64-bit devices capable of addressing hundreds of GB of memory directly and running at GHz speeds. They try to be reasonably power efficient but favor performance over power. The ARM cores have names that begin with the letter A (for Application) and are found in Apple chips in iPads and iPhones, in Samsung chips in their tablets and smartphones, and in many other chips from a variety of manufacturer. Two hobbyist systems that you may have heard of are based on these kinds of chip, the Raspberry-Pi and the BeagleBone. They tend to run complete Linux operating systems and to be quite challenging to program.
These are CPUs that are designed to be hidden away in embedded systems. They are much more about controlling hardare in the outside world than about data processing. Microcontrollers often have ways to cut their power consumption drastically, reducing or altogether suspending their processing power. They also have rich sets of peripherals to connect to the outer world in a variety of different ways.
ARM makes several families of microcontrollers with names that begin with an M (for microcontroller). The most popular at the moment are the the ARM Cortex series that comes in several different families. The Cortex-M0 and M0+ are the simplest and most energy efficient. They tend to have rather small amounts of memory, low clock speeds, and relegate tasks as simple as multiplication and division to software rather than hardware. At the other end are Cortex-M4 CPUs, such as that found in the TM4C123. These not only have hardware multiplication and division for integers but even include support for floating point numbers (non-integral numbers). They tend to have more memory and use more power than the M-0s but much less than the application processors.
The TM4C123GH6PM chip on our LaunchPad boards boasts the following, among others,
-ARM Cortex-M4F core -80MHz clock speed executing at least one instruction per clock -256kB of FLASH program memory -32kB of RAM -built-in clock generator (uses 1 or 2 external crystals) -Eight serial ports -One USB port -Lots of timers (depends on how you count, but up to 28) -Two 12-bit analog-digital converters running at 1 million samples/second -A fancy debugging interface for getting programs into the chip -About 43 input/output pins
For us this means that we have a very flexible computer that can controll a large number of connections to the outside world and can run moderate sized programs at high speeds. The manufacturer lists a whole bunch of suggested applications, including
-Low power, hand-held smart devices -Gaming equipment -Home and commercial site monitoring and control -Motion control -Medical instrumentation -Test and measurement equipment -Factory automation -Fire and security -Smart Energy/Smart Grid solutions -Intelligent lighting control -Transportation
We will put them to work controlling LEDs and LCD displays, measuring voltages and light levels, controlling and navigating robots, and whatever final projects you can come up with.
We will be most concerned with the input/output (I/O) pins. These are organised into groups called ports. One port consists of eight pins that can be treated as the several bits of a single binary number or as completely independent single bits. Each bit can be individually set to be either an input or an output. It is even possible to use a single pin as an input some of the time and an output the rest of the time, though that takes care.
A single I/O pin use as an output can, possibly with some external circuitry, turn on and off an LED or lamp or might generate a series of pulses to control the speed of a motor. When used as a digital input it can allow the computer to read the state of a switch or a sensor in the outside world. When used as an analog input it can convert the voltage on the pin into a number for the computer to examine.
The TM4C123G has 6 of these ports so you might expect to have 48 (6 x 8) I/O pins. However, some of the bits are not connected to pins on the chip and a few of the pins that are connected have special functions that make them useless as regular I/O pins. The LaunchPad makes 37 pins available for us to use, including five that are shared with on-board functions.
The LaunchPad board is a cheap way to get to play with these computers. Here is a picture of the chip-side of the LaunchPad board.
The most prominent things are the two large square black packages. These are both TM4C123G chips. You can see one reason why we want to buy complete boards. Each of the chips has 64 very tiny pins, each of which has to be soldered down to the PC board. This is actually possible to do at Hamilton but it is quite fiddly and I am not sorry to not have to do it.
If you look carefully then you will see that the board is pretty much split into sections by a white line running across the board as the level of the left-hand USB plug.
The upper third of the board, above the white line, is home to the other, upright, TM4C123G chip, a green power LED, a switch, and the top micro-USB connector. This section is called an In-Circuit Debugger Interface (ICDI). It provides a way for Energia to put our programs into the lower computer and, later in the semester, to allow us to debug the programs as they run.
The larger, lower, section contains the diagonal chip and a whole bunch of connectors on it. This is the chip that you will actually be programming. The connectors are where you will attach wires to the pins of the computer. There are 40 pins in the connectors and they all have little names printed next to them so you know which pin does what. Alas, they are pretty well randomly organized. It would be nice if all the pins of one port were next to each other but this is not the case. Instead they are wired up according to some plan that escapes me. Even though it spans the white line, the left-hand micro-USB connector logically belongs to this part of the board.
In addition to the computer and the connectors, the lower part of the board hosts a pair of switches (down at the bottom left and right) and a rather snazzy three-colour LED. These are connected to the pins of Port F but do not usually interfere with other uses of those pins. They do mean that we can write some simple programs without having to wire anything up to the LaunchPad.
Microcomputers are nearly as old as I am. Over that time there have been a number of attempts to make them widely accessible. The Basic language and the LEGO mindstorms systems would be two examples as would the BBC microcomputer that is a very distant ancestor of today's ARM chips. About 10 years ago a university in Italy went in search of a cheap, accessible platfrom for teaching computing and making it accessible to non-technical users, especially artists. They based their work on a system called Processing that was developed at MITs famous Media Lab. They simplified Processing to a system called Wiring and then combined wiring with a cheap development board built round an Atmel chip and produced the first Arduino.
The Wiring library was carefully designed to hide most of the machine specific complexity that has made microcontrollers hard to work with. At the same time, a a complete development environment, also called Arduino, was developed to hide the rather messy process of turning a Wiring program into executable code. The complete software system was made freely available and the hardware designs were released so that anyone could make their own Arduino. There are basically three parts to Arduino.
Probably the single most important part of Arduino is the library. As mentioned, this is closely based on the Wiring library that was designed in part to make microcontrollers accessible to artists with little technical background. It provides simplified ways to access common pieces of hardware and does an excellent job of masking the differences between one hardware platform and another.
The Arduino library does not implement quite all of Wiring. In particular, it omits the port support, leaving only single-pin I/O in the basic system. It does provide a standard way to expand its capabilities and there are a large number of additional libraries available to expand Arduino. These include such things as libraries to interface to some of the less obvious bits of hardware such as synchronous serial ports as well as libraries to interface to common bits of hardware such as the cheap 1 to 4-line LCD displays available on the surplus market.
The basic design of the original Arduino board has become a standard. In particular, the size of the board and the layout of the connectors have spawned a lot of add-on boards called shields. These shields allow you to add hardware to any fully compatible Arduino and many kinds of shield are available form many manufacturers.
Our LaunchPad boards are NOT compatible with the Arduino board standard and so cannot connect directly to Arduino shields. I am considering providing an adapter board to make this possible.
The process of converting a program from the human readable source code (the sketch in Arduino parlance) into something inside an actual microcontroller is a rather complex one. If you have to do it by hand then it will involve a number of different programs to perform the various steps. You have to know a lot about those programs and about where various kinds of information are stored on your computer to make this work. Worse, if you make even a small change to the microcontroller you may have to relearn much of this stuff. Traditionally each microcontroller manufacturer has provided their own unique development environment and there have grown up two or three third-party environments that span several manufacturers. These are large, often very expensive (we are talking hundreds of dollars per seat) systems that are written by professional engineers for professional engineers.
One of the breakthroughs of Arduino was the simplified programming environment. This offers only a tiny fraction of the facilities of the the professional systems but it is extremely easy to learn and to use. The community has done a tremendous job of making a system that is trivial to install and that simply works, and works simply. There is an editor window that knows about the structure of an Arduino program and a couple of buttons to play with. The system takes care off all the details. You just push the Upload button and magic happens. The result is your program running on your hardware.
The cost to the Arduino environment is that it cannot do a lot of the fancier things that the manufacturers environments can do. In particular, it does not provide a way to debug a running program. Fancier systems allow the user to step through their programs while watching the values of the variables and pins change. This makes it much easier to find run-time errors.
There have been a lot of developments in the Arduino world since but the main point is that it has become the de-facto standard for hardware hobbyists all over the world. The original Arduino board has spawned troops of descendents, alternatives, and competitors, many based on other kinds of chip. The community has managed to keep the system from fracturing and so there are now all sorts of hardware and software that are compatible with the Arduino standard. I have been wanting to benefit from this universality of design for the computers in this course for a number of years. Last year I wrote my own Arduino-style library for the Freescale 9S08 computers that have been the center of the course for the past 8 years but wanted to move to a more powerful ARM based system. This year I found Energia and the TM4C123.
Energia is a port of much of Arduino to Texas Instruments microcontrollers. The project is a few years old and began with support for a different family of microcontrollers. It has recently been expanded to support the TM4C series and paired with very cheap hardware. The result is a system that seems ideal for teaching microcontroller programming.
Like the Arduino system upon which it is based, Energia does not support run-time debugging of programs. However, the LauchPad hardware does provide full support for debugging. Later in the semester we will add a second tool that will allow at least me to debug your programs. Hopefully, some of you will learn to use it too.
This is CodeComposer, Texas Instruments own professional development system. Like most such systems it is very expensive. But, like some other manufacturers systems, there are free licenses available with some limitations. In the case of CodeComposer the limitation is that it can only be used with the LaunchPad boards. But that is perfect for us as those are the only things we want to program!
Furthermore, TI has added support for Energia to CodeComposer so that it is trivial to import an Energia program into CodeComposer, do some some debugging, fix a problem in the code, and then switch back to Energia once it works. We will use this later in the semester.