MSP430 State machine hardware overview image

MSP430 State Machine Project Pt/1

MSP430 state machine project tutorial demonstrates a simple state machine, with a human interface consisting of 4 buttons, an LCD and some interfacing electronics.

A video demonstrating the state machine code can be seen below.

This project write up uses a state machine based in the C language, the state machine model is based on some code discussed in a three part state machine tutorial I have already written.  The first part of this tutorial can be found here and all the state machine tutorial parts can be found in the C Programming category of this website.

The project itself is a good learning tool as it not only suing the concept of a state machine, but also incorporates the ADC and Timer on the MSP430 Launchpad.

The Initial Concept

The project was undertaken as part of a course and was designed to teach the basic concept of a state machine, as well as designing a human interface with control switches and and LCD.

As a proof of concept the idea of system would be to control the brightness of 2 lights, one via a manual adjust, which would have preset values for brightness, and the other would be adjusted automatically dependant on the ambient light.  The lights in this case would be LED’s not ideal but serve the purpose for the demonstration, their brightness would be adjusted via PWM (Pulse Width Modulation).  An LDR (Light Dependant Resistor) would be used to detect the ambient light, and interfaced to the ADC (Analog to Digital Converter) on MSP430.  There would also be a 16×2 LCD interfaced in parallel mode to the MSP430 launchpad.  A basic block diagram of the system can be seen below.

MSP430 State Machine Project Tutorial C Code

Hardware

I will start by over viewing the connections to the MSP430.  The MSP430G2231 was originally used but as the project went on, memory became an issue as did the number of available GPIO ports, so the MSP430G2432 was an obvious choice as the memory is extended from 2kb to 8kb and an extra 6 GPIO.  The image below illustrates the pinout configuration for the launchpad.

MSP430 State Machine Project Tutorial C Code

16×2 LCD

As can be seen in the pinout configuration the LCD uses 6 pins, the pins for the LCD are based around an external tutorial which includes all the necessary C code.  This tutorial can be found by following this link.

This is a 16*2 dot matrix character display, using the Hitachi HD44780U controller. This controller has been around for many years, which means there is a wealth of information. There are several websites with API’s aiding in the interfacing of the LCD to a MSP430, along with the one previously mentioned.
The LCD uses an 8 bit parallel interface, but fortunately can also be used in 4 bit mode which still requires 6 pins.
It was also necessary to provide the LCD with a 5V supply and a potentiometer to adjust the contrast on the display, this was a very simple circuit and was constructed on a piece of vero board.

The C code for the LCD has been placed into a library in the final state machine code, all the code can be downloaded as a zip file at the end of this article.

Tack Switch Board

The tack switch boarded consisted of 3 tack switches and some debounce components constructed on a piece of vero board.  When a switch is depressed, the connected GPIO pin on the launchpad will be pulled low.  The 4th button used was S2 on the launchpad board, this served as an on/off button.  An image of the tack switch circuit and also the finished vero board can be seen below.

MSP430 State Machine Project Tutorial C Code

MSP430 State Machine Project Tutorial C Code

LDR and Interface Circuit

The LDR are non linear devices which makes them less than ideal for detecting small changes in light and then interfacing to the ADC of a microcontroller.  They are found in many devices, a common use is in garden solar lights that switch on when a preset lux level is reached, in this case the LDR is being used as a simple switch.  For the purpose of this project the output from the LDR would need to be converted to suit ADC on MSP430 launchpad.  The ADC has an input range from 0V to 3V.  The circuit was first simulated in OrCad, it incorporates 3 opamps and 2 adjustable potentiometers so fine adjustments can be made depending on the ambient light conditions.  There was also a small amount of linearisation added to the LDR as a result of this circuit design.  The final interface circuit schematic can be seen below.

MSP430 State Machine Project Tutorial C Code

LDR Circuit final construction on vero board can be seen in the next image.

MSP430 State Machine Project Tutorial C Code

LED Demo Board

The LED board is a very simply construction, using a pair of transistors acting as switches to drive the LED’s.  The circuit schematic and final board construction can be seen in the following 2 images.

MSP430 State Machine Project Tutorial C Code

MSP430 State Machine Project Tutorial C Code

So the final system looks like this, a bit ‘Heath Robinson’ but proof of concept remember!

MSP430 State Machine Project Tutorial C Code

I had intended this to be a one page article but the images have extended it more than I anticipated, so in part 2 I will cover the state machine structure and C programming code.

Leave a Reply