Adc With tm4c123
Adc With tm4c123
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.
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).
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.
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
The TM4C123 microcontroller includes a built-in ADC module with the following
features:
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:
#include "tm4c123gh6pm.h"
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();
LCD_command(0x80);
LCD_data(buffer[i]);
void LCD_init(void) {
LCD_command(0x28);
LCD_command(0x06);
LCD_command(0x0F);
GPIO_PORTB_DATA_R |= 0x02;
delayMs(1);
4
GPIO_PORTB_DATA_R &= ~0x01;
GPIO_PORTB_DATA_R |= 0x02;
delayMs(1);
delayMs(2);
GPIO_PORTB_DATA_R |= 0x01;
GPIO_PORTB_DATA_R |= 0x02;
delayMs(1);
GPIO_PORTB_DATA_R |= 0x01;
GPIO_PORTB_DATA_R |= 0x02;
delayMs(1);
delayMs(2);
void ADC_init(void) {
SYSCTL_RCGCADC_R |= 1;
SYSCTL_RCGCGPIO_R |= 0x10;
GPIO_PORTE_AFSEL_R |= 8;
GPIO_PORTE_AMSEL_R |= 8;
ADC0_SSMUX3_R = 0;
ADC0_SSCTL3_R = 6;
5
ADC0_ACTSS_R |= 8;
uint16_t ADC_read(void) {
ADC0_PSSI_R = 8;
ADC0_ISC_R = 8;
return result;
void delayMs(int n) {
int i, j;
Simulation:
Fig 3: Simulation
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.