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.

Sunday, January 24, 2016

Control de Pantalla de Siete Segmentos con el Tiva C Launchpad

En esta guía vamos a explicar cómo funciona una pantalla de 7 segmentos de LED.  Luego, vamos a programar una máquina de estados para probar la pantalla de 7 segmentos usando Keil μVision 4 y la placa Tiva C Launchpad.


Si quieres aprender o repasar cómo funcionan los LED (diodos luminosos), puedes visitar mi guía para diseño de circuitos con LEDs.


1. PANTALLA DE SIETE SEGMENTOS

Las pantallas de 7 segmentos son simplemente 7 luces LED contenidas en el mismo componente. Para controlar la pantalla simplemente tenemos que activar cada uno de los LEDs en diferentes combinaciones.


Fig 1. Pantalla de siete segmentos de LED


Para ahorrar espacio, los LEDs en las pantallas de 7 segmentos comparten uno de sus pines (ánodo o cátodo) ya que simplemente tenemos cortar la corriente en un lado para apagar el LED. Debido a eso, existen dos tipos de pantallas: De ánodo común (common-anode) o cátodo común (common-cathode). En pantallas de ánodo común, los ánodos de los LEDs en la pantalla están conectados a un sólo pin (normalmente a la fuente de poder). En pantallas de cátodo común, los cátodos de los LEDs están conectados (normalmente a tierra).



Fig 2. Diagrama mostrando ánodo y cátodo de LED


Fig 3. Diagrama representando los LEDs en pantalla de siete segmentos


En esta guía vamos a utilizar el componente LSD3221-11, una pantalla de siete segmentos con ánodo común.  Esta parte y su datasheet pueden ser encontradas en la página web de Jameco.

Primero haremos un corto repaso sobre el funcionamiento de LEDs.  Para encender un LED, el voltaje que aplicamos sobre el LED (Vs-Vc) debe de ser mayor al voltaje de adelanto (Vf) o forward voltage en inglés. Para eso podemos usar la ecuación Vs - Vc > Vf.  El voltaje de adelanto (Vf) puede encontrarse en la datasheet del LED.

En pantallas de ánodo común, todos los ánodos de los LED están conectados a un sólo pin que a su vez está conectado a la fuente de voltaje (Vs). Debido a eso, la única forma de controlar cada uno de los LEDs es subiendo el voltaje de los cátodos de cada LED para apagarlos.

Para probar esto simplemente usamos la ecuación Vs - Vc > Vf.  Si el voltaje Vc es igual a la fuente Vs, la diferencia entre Vs y Vf es cero y por lo tanto no sería mayor al voltaje Vf.  Por lo tanto, el LED se encenderá si el voltaje de Vc es alto (igual a Vs) y se apagará si el voltaje es bajo (igual a tierra).


Fig 4. Diagrama de circuito de LED


Para controlar el voltaje del pin Vc con el microcontrolador, simplemente conectamos el cátodo del LED (usando una resistencia en serie) a uno de sus pines de salida.



2. PROBANDO LA PANTALLA CON EL TIVA C LAUNCHPAD

2.1  MATERIALES

- 7 resistencias de 47Ω (usar 120Ω si tu fuente de poder es de 5V)
- 1 breadboard
- Tiva C Launchpad
- Pantalla de 7 segmentos de ánodo común (LSD3221-11)


2.2  HARDWARE

El diseño de este proyecto es bien simple.  Vamos a usar el riel de +3.3V del Launchpad como fuente de poder para la pantalla y resistencias en serie con los cátodos de cada LED para ser conectadas a los pines de salida del microcontrolador.

Para calcular el valor de cada resistencia, buscamos el voltaje de adelanto (Forward voltage, Vf) y la corriente de adelanto (forward current, If) en el datasheet del LED (figura 5) y simplemente aplicamos la ley de Ohm.


Fig 5. LSD3221 datasheet power ratings


R = (Vs - Vf) / If = (3.3 - 2.1) / 2.5 = 48 Ohm (el valor estándar más cercano es 47Ω).


Luego, utilizamos el datasheet de nuevo para identificar los pines de la pantalla y ver cómo conectarla al Tiva C.  Debido al número de pines disponibles en el Launchpad, vamos a usar el Puerto B (pines B0 a B6) del Launchpad para nuestro diseño.  Además, omitiremos los LEDs utilizados para los puntos a la izquierda y a la derecha de la pantalla (LD y RD) por conveniencia.




Fig 6. Datashhet del LSD3221 definiendo los pines


Fig 7. Diagrama eléctrico de nuestro circuito



2.3  PROGRAMACION

1. Abrir Keil µVision 4 y crear un proyecto nuevo. Seleccionar el microcontrolador TM4C123GH6PM y aceptar el archivo de inicio (Startup project file) cuando el programa lo ofrezca.

NOTA: Para instrucciones más detalladas para crear proyectos, visita mi guía Parpadear un LED Usando el Tiva C Launchpad.


2. Usando el explorador de Windows, entra a la carpeta donde está instalado Keil, busca el archivo system_TM4C123.c y cópialo a la carpeta donde tienes guardado tu proyecto.  En seguida, agrega el archivo a tu proyecto usando Keil.

3. Visita mi repositorio en Github en https://github.com/sphanlung/TivaC/blob/master/SevenSegment1.c y descarga el archivo SevenSegment.c (o copia el texto a un archivo nuevo en Keil).  Agrega el archivo a tu proyecto.

NOTA: El código contiene comentarios en inglés explicando cómo funciona.  Si tienes preguntas, usa la secciones de los comentarios y te responderé apenas me sea posible.

4. En Keil, haz click en Project y luego Build Target para compilar el código.

5. Si el código compila sin errores, haz click en Project otra vez y luego en Options for Target 'Target 1'.  Cuando se abra la ventana, busca la pestaña de Utilities y bajo la opción Configure Flash Menu Command, desmarca la casilla Use Debug Driver box.  Luego, selecciona Stellaris ICDI bajo Use Target Driver for Flash Programming y presiona OK.

6. Finalmente, haz click en Flash y luego Download.  Esto cargará el código al microcontrolador.



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.