Welcome to IDI Electronica!!!



Welcome!!! IDI Electronica is a blog for my personal projects and articles to help electronics enthusiasts like me.

Bienvenidos!!! IDI Electronica es un blog con mis proyectos personales y artículos con el fin de ayudar a entusiastas de la electrónica como yo.

Saturday, January 9, 2016

Driving Single Digit 7-Segment Display with the Tiva C Series Launchpad

In this guide, I will explain how a basic 7-segment LED display works and then I we will write some code to create a finite state machine to test our display using the Tiva C Series Launchpad and Keil µVision 4.

Also, if you are not very familiar with LEDs, you can read my LED Circuit Design tutorial.


1. SEVEN-SEGMENT LED DISPLAYS

7-segment displays are simply 7 LEDs placed in one same package.  To change the displayed value, we simply turn on or off different combinations of LEDs.


Fig 1. Seven-segment LED displays


There are two types of single-digit 7-segment displays: common anode and common cathode.  In common anode displays, the anode of the LEDs are connected to one pin (usually connected to a power source).  In common cathode displays, the cathodes are connected to one pin (usually connected to ground).



Fig 2. Diagram representation of LED


Fig 3. Diagram representation of LEDs in 7-segment display


For this tutorial, we will be using the LSD3221-11, a common anode 7-segment display.  This component and its datasheet can be found at Jameco's website.

To turn on a LED, the voltage across it must be higher than its forward voltage (Vs - Vc > Vf).  Since  common anode configurations usually have the anode pin tied to the power rail (Vs), we need to use the cathode pin (Vc) to turn it on or off.

Fig 4. Simple LED circuit diagram

If the voltage at the cathode (Vc) is equal to the anode (high), the voltage across the LED (Vs - Vc) would be zero.  Therefore, the voltage across the LED would be lower than its forward voltage and the LED will be turned off.  If the voltage at the cathode (Vc) is low or equal to zero, the voltage across the LED would higher than the forward voltage and the LED will turn on.

This can be easily accomplished using a microcontroller by tying one of its output pins to the resistor connected to the cathode of the LED (Vc).  If the output is high, our LED will turn off.  If the output is low, the LED will turn on.


2. TESTING THE DISPLAY WITH THE TIVA C LAUNCHPAD

2.1  MATERIALS

- 7 x 47Ω resistors (use 120Ω if using 5V source)
- 1 x breadboard
- Tiva C Launchpad
- Common-anode single-digit 7-segment display (e.g. LSD3221-11)


2.2  HARDWARE

The design of this project is very simple, we will be using the +3.3V rail of the Launchpad to power the 7-segment display and we will connect each of its cathode pins to the outputs pins of the microcontroller.  Since we are dealing with LEDs, we will also need to connect series resistors to control the amount of current flowing through each LED.

To calculate the value of the resistors we had to find the forward voltage (Vf) and current (If) of the LEDs in the datasheet (figure 5).


Fig 5. LSD3221 datasheet power ratings


R = (Vs - Vf) / If = (3.3 - 2.1) / 2.5 = 48 Ohm (closest standard value is 47Ω).


Next, we use the datasheet again to see how to connect the display to the Launchpad. Because of pin availability in the Tiva C Launchpad, we will be using pins B0 to B6 (port B) in the microcontroller. Also,we won't be using the Left Dot (LDP) and Right Dot (RDP) LEDs for this tutorial out of convenience.


Fig 6. LSD3221 datasheet device pinout


Fig 7. Circuit diagram for our project



2.3  PROGRAMMING

1. Open Keil µVision and create a new project. Select the TM4C123GH6PM microcontroller and accept the Startup project file when prompted.

NOTE: You can find the steps to create a new project in more detail in my Blinking an LED Using the Tiva C Launchpad tutorial.


2. Go to the Keil installation folder, find the file system_TM4C123.c and copy it to your project folder.  Next, add that file to your new project.

3. Visit my Github repository at https://github.com/sphanlung/TivaC/blob/master/SevenSegment1.c to download the file SevenSegment.c and add the file to your project.

NOTE: The code contains comments explaining how the program works. Feel free to contact me or write in the comments section if you have any questions.

4. Next, go to Project and click Build Target to compile the code.

5. If you get no errors, go to Project again and click Options for Target 'Target 1'.  Find the Utilities tab and under Configure Flash Menu Command, uncheck the Use Debug Driver box.  Then, under Use Target Driver for Flash Programming select the Stellaris ICDI driver and hit OK.

6. Finally, click on Flash and then Download.  This will load the compiled code to the microcontroller.




No comments:

Post a Comment