You are on page 1of 29

Outline

• Introduction to Analog-to-Digital Convertor (ADC)


• AVR ADC Programming
• Example of device with analog interface
• MCP9700A: Low-Power Linear Active Thermistor Ics
• TMP36: Low Voltage Temperature Sensors
• 16x2 Alphanumeric LCD Interfacing

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Introduction to Analog to Digital
Converter (ADC)

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Digital vs Analog Signal
• Analog signals are continuous and have an infinite number of possible
values within some range e.g. temperature, humidity etc.
• Digital signals have a limited set of possible values that they can be e.g.
HIGH/LOW, 000-111 etc.

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Analog to Digital Converter (ADC)
• ADC is a device used to convert an analog signal into a digital signal that
can be processed by a microcontroller and/or other digital devices
• ADC differs by its resolution, conversion time, voltage range, interface
type, hardware implementation and number of channel

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Some ADC Characteristics
• Resolution
• 8, 10, 12, 16 or 24 bits are common in embedded system design
• Higher-resolution provide a smaller step size (smallest voltage change that can be
distinguished by an ADC)
• Conversion time
• Reference voltage
• Interface (Parallel/Serial)
• Number of ADC channels

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Example: Linear Active Thermistor ICs

Source: https://ww1.microchip.com/downloads/en/DeviceDoc/20001942G.pdf
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT
MCP9700/1(A) Applications Information

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


AVR Analog-to-Digital Convertor

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Recall AVR Architecture

Today’s Topic

Simplified AVR Architecture

ATMega328P Architecture
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT
AVR* ADC: Features
• 10-bit resolution, 8 multiplexed single ended input channels
• Up to 76.9kSPS (15kSPS at Maximum Resolution), 13 – 260us
Conversion Time
• 0 - VCC ADC input voltage range (selectable 1.1V ADC reference voltage)
• Free running or single conversion mode
• Interrupt on ADC conversion complete

* The information in this slide are based on ATmega328P. However, they are mostly applied to other AVR microcontrollers
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT
AVR ADC: Block Diagram
• 4 control/data registers:
ADMUX, ADCSRA, ADCH/L
• 8-10 I/O pins: AVCC, AREF,
ADC0-ADC7

ADC0-5

AREF, AVCC

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


AVR ADC: ADMUX
• Analog input channel can be
selected by writing to the
MUX[3:0] bits in ADMUX

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


AVR ADC: ADMUX
• Voltage reference can be
selected by writing to the
REFS[1:0] bits in ADMUX
• Changes during conversion will
not go in effect until this
conversion is complete

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


AVR ADC: ADMUX, ADCH/L
• ADC conversion result will be stored
in ADC Data Registers, ADCH and
ADCL
• The result is left adjusted when
ADLAR = 1 and right adjusted when
ADLAR = 0
• ADC data registers will be updated
after ADCH is read (we may retrieve
8-bits value by reading ADCH and
disregard ADCL when ADLAR = 1)

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


AVR ADC: ADMUX, ADCH/L
• ADC conversion result will be stored
in ADC Data Registers, ADCH and
ADCL
• The result is left adjusted when
ADLAR = 1 and right adjusted when
ADLAR = 0
• ADC data registers will be updated
after ADCH is read (we may retrieve
8-bits value by reading ADCH and
disregard ADCL when ADLAR = 1)
Visit https://stackoverflow.com/questions/57534519/atmega328p-convert-analog-value-to-voltage to learn why we multiply by 1024 instead of 1023
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT
AVR ADC: ADCSRA (Clock Source)
• The ADC requires an input clock
frequency between 50kHz and
200kHz to get maximum resolution
• ADC module contains a prescaler to
generate ADC clock frequency from
any CPU frequency. The prescaling is
set by the ADPS[2:0] bits in ADCSRA

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


AVR ADC: ADCSRA/B (Starting a conversion)
1. Single Conversion
• set ADSC (ADC Start Conversion bit) to 1
to start each conversion
• ADSC will stay 1 while a conversion is in
progress and will be cleared by hardware
when it is completed
2. Auto Trigger
• set ADATE (ADC Auto Trigger Enable bit)
to 1 to enable auto triggering mode
• ADTS (ADC Trigger Select bits) in ADCSRB
can be used to select a trigger source
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT
AVR ADC: Timing

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


AVR ADC: Timing

New conversion will not be started if the trigger signal is still set after the conversion
complete or if another positive edge occurs during conversion.
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT
AVR ADC: Power Saving Consideration

Write PRADC to 1 to shutdown the ADC. The ADC must be disabled


before shut down. The analog comparator cannot use the ADC input
MUX when the ADC is shut down.

Write these bit to logic 1 to disable the digital input buffer on the
corresponding ADC pin when the digital input from this pin is not needed

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Pre-Lab 3: HD44780 LCD Interfacing

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


LCD Pinout

RS
0 – Command Register
1 – Data Register

R/W
0 - Write
1 - Read

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Connection Diagram

LCD connections for 8-bit mode LCD connections for 4-bit mode

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Basic LCD Programming
1. Initialize the LCD by sending command to the LCD
• 0x38, 0x0E, 0x01 for 8-bit mode
• 0x33, 0x32, 0x28, 0x0E, 0x01 for 4-bit mode
2. Send additional commands to setup the LCD
3. Send the character to be shown on the LCD

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Timing Diagram for 4-bit Write
• Set RS = 0 to write a command and
RS = 1 to write a data
• We should wait at least 100us after
issue each command (except Clear
LCD and Return Home which need
2ms to execute)
• R/W can be tied to GND if we only
need to write to the LCD

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


List of LCD Commands

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Lab 3: AVR ADC Programming
Connect a circuit with an ATMega328P and MCP9700A (analog
temperature sensor) and write a program to display the current ambient
temperature on the 16x2 alphanumeric LCD display

CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT


Arduino UNO Pinout (ATMega328P)

Source: https://store-usa.arduino.cc/products/arduino-uno-rev3/
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT
TMP36: Applications Information

Source: https://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf
CPE328: Embedded System (2/2021) Computer Engineering Department, KMUTT

You might also like