0% found this document useful (0 votes)
109 views7 pages

Adc With tm4c123

micro processor lab

Uploaded by

Akmal Arslan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views7 pages

Adc With tm4c123

micro processor lab

Uploaded by

Akmal Arslan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment 13

Objective:
“To demonstrate analog to digital conversion using lcd and TM4C123”

Apparatus required:
 TM4C123 TIVA LaunchPad
 16x2 LCD
 Resistors (1kΩ) for contrast adjustment
 Breadboard
 Jumper wires
 TM4C123 micro-controller

Theory:
TM4C123 microcontroller:
The TM4C123 microcontroller, part of the Texas Instruments Tiva C Series, is a versatile
and widely used microcontroller for embedded systems. It is based on the ARM Cortex-M4
architecture, making it a powerful yet energy-efficient choice for a wide range of applications
including robotics, IoT, industrial control systems, and automotive applications. This
microcontroller features a 32-bit processor capable of running at speeds up to 80 MHz and
incorporates a floating-point unit (FPU) for efficient mathematical computations. It is
equipped with a variety of peripherals, making it versatile for various embedded applications.

Fig 1: TM4C123 microcontroller

The interfacing process involves connecting the display to the TIVA board's GPIO
(General Purpose Input/Output) pins and writing code to control which segments light up
based on the desired output. Each segment of the SSD corresponds to a specific GPIO pin on
the TIVA board, when programming, a binary representation is used where each bit
corresponds to a segment being on (1) or off (0).

The Tiva C Series TM4C123G LaunchPad (EK-TM4C123GXL) serves as a low-cost


evaluation platform for the TM4C123GH6PM microcontroller. It provides an accessible
entry point for developers and students looking to explore ARM-based microcontroller.

1
16x2 LCD:
A Liquid Crystal Display (LCD) is a flat-panel display technology commonly used in
embedded systems to visually represent alphanumeric characters and symbols. It operates by
controlling the alignment of liquid crystals using electrical signals to modulate light.

A 16x2 LCD can display:

 16 characters per row across 2 rows, totaling 32 characters.


 Each character is displayed in a 5x8 dot matrix format.
It operates using the HD44780 controller, which can be interfaced in either 4-bit or 8-
bit modes. In this project, the 4-bit mode is preferred due to its efficiency in pin usage,
requiring only 6 GPIO pins compared to 10 in 8-bit mode.The essential control pins for the
LCD include:

 Register select (RS):


Determines whether the data being sent is a command or character

 Enable (E):
Triggers the LCD to read the data

 Read/Write (R/W):
Indicates whether data is being read from or written to the LCD

Fig 2: 16x2 LCD

By connecting and programming an LCD with a microcontroller, it becomes a powerful


tool for visualizing data in real time.

Analog-to-digital conversion (ADC):


ADC is the process of converting continuous analog signals into discrete digital values
that a microcontroller can process.

The TM4C123 microcontroller includes a built-in ADC module with the following
features:

 12-bit resolution (output values range from 0 to 4095).


 Up to 12 input channels for sampling analog signals.
 Configurable sample rates.

2
The ADC process involves two main steps:.

 Sampling:
This step involves measuring the amplitude of an analog signal at discrete intervals.
According to the Nyquist theorem, to accurately reconstruct the original signal, the sampling
rate must be at least twice the highest frequency present in the signal35.

 Quantization:
After sampling, each sampled value is assigned a digital value. This introduces
quantization error, which is the difference between the actual analog value and its quantized
digital representation45. The resolution of an ADC is determined by the number of bits used
in the digital representation; for example, a 10-bit ADC can represent values from 0 to 1023.

Procedure:
Circuit connections:

1. Connect the VREF pin of the TM4C123 to a stable reference voltage (3.3V).
2. Connect an analog signal source (e.g., potentiometer) to AIN0 (ADC channel 0,
corresponding to pin PE3).
3. Connect the LCD to the microcontroller in 4-bit mode:
4. RS, RW, EN, and data pins (D4-D7) connected to GPIO pins.
5. Adjust contrast using a potentiometer connected to the VO pin.
TM4C123 configuration:

1. Enable the clock for ADC0 and GPIO Port E (for ADC input).
2. Configure PE3 as an analog input pin.
3. Configure ADC0 to sample from channel 0 (AIN0) and perform conversions.
LCD configuration:

1. Initialize the LCD with commands for 4-bit mode operation.


2. Define functions to send commands and display data on the LCD.
3. Display the digital value on the LCD.
Code:
#include <stdint.h>

#include "tm4c123gh6pm.h"

void delayMs(int n);

void LCD_command(unsigned char command);

void LCD_data(unsigned char data);

void LCD_init(void);

3
void ADC_init(void);

uint16_t ADC_read(void);

int main(void) {

uint16_t adcValue;

char buffer[5];

LCD_init();

ADC_init();

while (1) {

adcValue = ADC_read();

sprintf(buffer, "%4d", adcValue);

LCD_command(0x80);

for (int i = 0; i < 4; i++) {

LCD_data(buffer[i]);

delayMs(500); // Wait for 500ms

void LCD_init(void) {

LCD_command(0x28);

LCD_command(0x06);

LCD_command(0x0F);

void LCD_command(unsigned char command) {

GPIO_PORTB_DATA_R = (command & 0xF0);

GPIO_PORTB_DATA_R &= ~0x01;

GPIO_PORTB_DATA_R |= 0x02;

delayMs(1);

GPIO_PORTB_DATA_R &= ~0x02;

GPIO_PORTB_DATA_R = (command << 4);

4
GPIO_PORTB_DATA_R &= ~0x01;

GPIO_PORTB_DATA_R |= 0x02;

delayMs(1);

GPIO_PORTB_DATA_R &= ~0x02;

delayMs(2);

void LCD_data(unsigned char data) {

GPIO_PORTB_DATA_R = (data & 0xF0);

GPIO_PORTB_DATA_R |= 0x01;

GPIO_PORTB_DATA_R |= 0x02;

delayMs(1);

GPIO_PORTB_DATA_R &= ~0x02;

GPIO_PORTB_DATA_R = (data << 4);

GPIO_PORTB_DATA_R |= 0x01;

GPIO_PORTB_DATA_R |= 0x02;

delayMs(1);

GPIO_PORTB_DATA_R &= ~0x02;

delayMs(2);

void ADC_init(void) {

SYSCTL_RCGCADC_R |= 1;

SYSCTL_RCGCGPIO_R |= 0x10;

GPIO_PORTE_AFSEL_R |= 8;

GPIO_PORTE_DEN_R &= ~8;

GPIO_PORTE_AMSEL_R |= 8;

ADC0_ACTSS_R &= ~8;

ADC0_EMUX_R &= ~0xF000;

ADC0_SSMUX3_R = 0;

ADC0_SSCTL3_R = 6;

5
ADC0_ACTSS_R |= 8;

uint16_t ADC_read(void) {

ADC0_PSSI_R = 8;

while ((ADC0_RIS_R & 8) == 0);

uint16_t result = ADC0_SSFIFO3_R;

ADC0_ISC_R = 8;

return result;

void delayMs(int n) {

int i, j;

for (i = 0; i < n; i++)

for (j = 0; j < 3180; j++);

Simulation:

Fig 3: Simulation

Practical implementation:

Fig 4: Practical implementation

6
Code explanation:

1. #include <stdint.h>
 Includes the standard library for fixed-width integer types, such as uint8_t and
int32_t.
 Used to ensure portable and efficient code.
2. #include "tm4c123gh6pm.h"
 Includes the header file specific to the TM4C123 microcontroller.
 This file contains definitions for all registers and macros related to the
microcontroller.
3. Function prototypes:
 delayMs: Generates delays in milliseconds.
 LCD_command: Sends a command to the LCD.
 LCD_data: Sends data (characters) to the LCD.
 LCD_init: Initializes the LCD for 4-bit communication.
 ADC_init: Configures the ADC module.
 ADC_read: Reads the converted value from the ADC.
4. LCD_init:
 Configures the LCD by sending commands:
 0x28: 4-bit mode, 2-line display.
 0x06: Cursor moves to the right after writing a character.
 0x0F: Turns on the display with a blinking cursor.
5. delayMs(1000);
 Creates a delay of 1000 milliseconds (1 second) between each digit.
 This allows each digit to be visible for a second before switching to the next.

Summary:
The code initializes the ADC on the TM4C123 microcontroller to convert an analog
signal into a 12-bit digital value. It configures the LCD in 4-bit mode for displaying the
converted ADC values. The ADC reads input from pin PE3, while the LCD is controlled via
GPIO Port B using separate functions for commands and data. The program loops
continuously, reading ADC values, formatting them as strings, and displaying them on the
LCD.

Conclusion:
This experiment demonstrated how to configure and use the ADC module of the
TM4C123 microcontroller to convert an analog signal into a digital value. The output was
successfully displayed on a 16x2 LCD, validating the ADC functionality and LCD
interfacing. This exercise highlighted key concepts in ADC processes, including sampling
and quantization, as well as practical applications of microcontrollers in interfacing with real-
world. The ability to visualize analog signals in digital form is crucial for embedded systems
design, enabling further processing and control based on real-time data inputs.

You might also like