Vous êtes sur la page 1sur 109

Outline

Analog to Digital Conversion


Coding ADC

Using ADC on Firebird-V Robot

E-Yantra Team
Embedded Real-Time Systems Lab
Indian Institute of Technology-Bombay

IIT Bombay
September 26, 2012

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 1/19


Outline
Analog to Digital Conversion
Coding ADC

Agenda for Discussion

1 Analog to Digital Conversion


Need for ADC
ADC of ATmega2560
ADC Channels

2 Coding ADC
ADC Initilization
ADCSRA
ADCSRB
ADMUX
ACSR
Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 2/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

Need for ADC

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

Need for ADC

X IR Proximity sensors

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

Need for ADC

X IR Proximity sensors
X Sharp IR Range sensors

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

Need for ADC

X IR Proximity sensors
X Sharp IR Range sensors
X white line sensors

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

Need for ADC

X IR Proximity sensors
X Sharp IR Range sensors
X white line sensors
X battery voltage sensing

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

Need for ADC

X IR Proximity sensors
X Sharp IR Range sensors
X white line sensors
X battery voltage sensing
X etc..

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels
X 14 Differential input channels

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels
X 14 Differential input channels
X Optional Left Adjustment for ADC Result Readout

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels
X 14 Differential input channels
X Optional Left Adjustment for ADC Result Readout
X 0 - VCC ADC Input Voltage Range

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels
X 14 Differential input channels
X Optional Left Adjustment for ADC Result Readout
X 0 - VCC ADC Input Voltage Range
X 2.7 - VCC Differential ADC Voltage Range

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels
X 14 Differential input channels
X Optional Left Adjustment for ADC Result Readout
X 0 - VCC ADC Input Voltage Range
X 2.7 - VCC Differential ADC Voltage Range
X Selectable 2.56V or 1.1V ADC Reference Voltage

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels
X 14 Differential input channels
X Optional Left Adjustment for ADC Result Readout
X 0 - VCC ADC Input Voltage Range
X 2.7 - VCC Differential ADC Voltage Range
X Selectable 2.56V or 1.1V ADC Reference Voltage
X Free Running or Single Conversion Mode

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

In-Built ADC of ATmega2560

X 10-bit Resolution
X 13 - 260 s Conversion Time
X 16 Multiplexed Single Ended Input Channels
X 14 Differential input channels
X Optional Left Adjustment for ADC Result Readout
X 0 - VCC ADC Input Voltage Range
X 2.7 - VCC Differential ADC Voltage Range
X Selectable 2.56V or 1.1V ADC Reference Voltage
X Free Running or Single Conversion Mode
X Interrupt on ADC Conversion Complete

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

ADC Channels

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

ADC Channels
Pin No. Pin Name Description
97 PF0/ADC0 ADC input for Battery Voltage Monitoring
96 PF1/ADC1 ADC input for White Line Sensor 3(Right)
95 PF2/ADC2 ADC input for White Line Sensor 2(Center)
94 PF3/ADC3 ADC input for White Line Sensor 1(Left)
93 PF4/ADC4 ADC input for IR proximity analog sensor 1
92 PF5/ADC5 ADC input for IR proximity analog sensor 2
91 PF6/ADC6 ADC input for IR proximity analog sensor 3
90 PF7/ADC7 ADC input for IR proximity analog sensor 4
89 PK0/ADC8 ADC input for IR proximity analog sensor 5
88 PK1/ADC9 ADC input for Sharp IR range sensor 1
87 PK2/ADC10 ADC input for Sharp IR range sensor 2
86 PK3/ADC11 ADC input for Sharp IR range sensor 3
85 PK4/ADC12 ADC input for Sharp IR range sensor 4
84 PK5/ADC13 ADC input for Sharp IR range sensor 5
83 PK6/ADC14 ADC input for Servo Pod 1
82 PK7/ADC15 ADC input for Servo Pod 2

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/19


Outline Need for ADC
Analog to Digital Conversion ADC of ATmega2560
Coding ADC ADC Channels

ADC Channels
Pin No. Pin Name Description
97 PF0/ADC0 ADC input for Battery Voltage Monitoring
96 PF1/ADC1 ADC input for White Line Sensor 3(Right)
95 PF2/ADC2 ADC input for White Line Sensor 2(Center)
94 PF3/ADC3 ADC input for White Line Sensor 1(Left)
93 PF4/ADC4 ADC input for IR proximity analog sensor 1
92 PF5/ADC5 ADC input for IR proximity analog sensor 2
91 PF6/ADC6 ADC input for IR proximity analog sensor 3
90 PF7/ADC7 ADC input for IR proximity analog sensor 4
89 PK0/ADC8 ADC input for IR proximity analog sensor 5
88 PK1/ADC9 ADC input for Sharp IR range sensor 1
87 PK2/ADC10 ADC input for Sharp IR range sensor 2
86 PK3/ADC11 ADC input for Sharp IR range sensor 3
85 PK4/ADC12 ADC input for Sharp IR range sensor 4
84 PK5/ADC13 ADC input for Sharp IR range sensor 5
83 PK6/ADC14 ADC input for Servo Pod 1
82 PK7/ADC15 ADC input for Servo Pod 2

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Steps for Using ADC in AVR

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Steps for Using ADC in AVR

1 Enabling ADC :
Set the ADEN bit of the ADC Control and Status Register ADCSRA
to logic 1.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Steps for Using ADC in AVR

1 Enabling ADC :
Set the ADEN bit of the ADC Control and Status Register ADCSRA
to logic 1.
2 ADC Prescaler Division Ratio :
Set the bits ADPS 2:0 of the Register ADCSRA. ADC needs clock
frequency between 50KHz to 200KHz

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Steps for Using ADC in AVR

1 Enabling ADC :
Set the ADEN bit of the ADC Control and Status Register ADCSRA
to logic 1.
2 ADC Prescaler Division Ratio :
Set the bits ADPS 2:0 of the Register ADCSRA. ADC needs clock
frequency between 50KHz to 200KHz
3 Selecting reference voltage source for the ADC :
Select the reference voltage for ADC as AREF by making
REFS1:REFS0 as 00 (5 V)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Steps for Using ADC in AVR

1 Enabling ADC :
Set the ADEN bit of the ADC Control and Status Register ADCSRA
to logic 1.
2 ADC Prescaler Division Ratio :
Set the bits ADPS 2:0 of the Register ADCSRA. ADC needs clock
frequency between 50KHz to 200KHz
3 Selecting reference voltage source for the ADC :
Select the reference voltage for ADC as AREF by making
REFS1:REFS0 as 00 (5 V)
4 Left/Right Adjustment :
ADCH contains the two most significant bits and ADCL contains
the remaining eight bits. We left shift this data so that ADCH will
contain the eight bits including the MSB and ADCL will contain
remaining two LSBs

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

X To Program ADC, we have to initialize some register before use it.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

X To Program ADC, we have to initialize some register before use it.

These registers are:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

X To Program ADC, we have to initialize some register before use it.

These registers are:


1 ADCSRA - ADC Control and Status Register A

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

X To Program ADC, we have to initialize some register before use it.

These registers are:


1 ADCSRA - ADC Control and Status Register A
2 ADCSRB - ADC Control and Status Register B

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

X To Program ADC, we have to initialize some register before use it.

These registers are:


1 ADCSRA - ADC Control and Status Register A
2 ADCSRB - ADC Control and Status Register B
3 ADMUX - ADC Multiplexer Selection Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

X To Program ADC, we have to initialize some register before use it.

These registers are:


1 ADCSRA - ADC Control and Status Register A
2 ADCSRB - ADC Control and Status Register B
3 ADMUX - ADC Multiplexer Selection Register
4 ACSR - Analog Comparator Control and Status Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Initilization

X To Program ADC, we have to initialize some register before use it.

These registers are:


1 ADCSRA - ADC Control and Status Register A
2 ADCSRB - ADC Control and Status Register B
3 ADMUX - ADC Multiplexer Selection Register
4 ACSR - Analog Comparator Control and Status Register

X All these Registers are 8 Bit.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits 1
1 ADPS1 ADC Prescaler Select Bits

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits 1
1 ADPS1 ADC Prescaler Select Bits 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits 1
1 ADPS1 ADC Prescaler Select Bits 1
0 ADPS0 ADC Prescaler Select Bits

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits 1
1 ADPS1 ADC Prescaler Select Bits 1
0 ADPS0 ADC Prescaler Select Bits 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits 1
1 ADPS1 ADC Prescaler Select Bits 1
0 ADPS0 ADC Prescaler Select Bits 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRA- ADC Control and Status Register A


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 ADEN ADC Enable 1
6 ADSC ADC Start Conversion 0
5 ADATE ADC Auto Trigger Enable 0
4 ADIF ADC Interrupt Flag 0
3 ADIE ADC Interrupt Enable 0
2 ADPS2 ADC Prescaler Select Bits 1
1 ADPS1 ADC Prescaler Select Bits 1
0 ADPS0 ADC Prescaler Select Bits 0

ADCSRA = 0x86

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Prescaler Selection Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Prescaler Selection Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable 0
5 - Reserved Bit -
4 - Reserved Bit -

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable 0
5 - Reserved Bit -
4 - Reserved Bit -
3 MUX5 ADC Channel selection bit-5

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable 0
5 - Reserved Bit -
4 - Reserved Bit -
3 MUX5 ADC Channel selection bit-5 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable 0
5 - Reserved Bit -
4 - Reserved Bit -
3 MUX5 ADC Channel selection bit-5 0
2 ADTS2 ADC Auto Trigger Source Bits 0
1 ADTS1 ADC Auto Trigger Source Bits 0
0 ADTS0 ADC Auto Trigger Source Bits 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable 0
5 - Reserved Bit -
4 - Reserved Bit -
3 MUX5 ADC Channel selection bit-5 0
2 ADTS2 ADC Auto Trigger Source Bits 0
1 ADTS1 ADC Auto Trigger Source Bits 0
0 ADTS0 ADC Auto Trigger Source Bits 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADCSRB- ADC Control and Status Register B


This register is Used to control ADC operation

Bit Symbol Description Bit Value


7 - Reserved Bit -
6 ACME Analog Comparator Multiplexer Enable 0
5 - Reserved Bit -
4 - Reserved Bit -
3 MUX5 ADC Channel selection bit-5 0
2 ADTS2 ADC Auto Trigger Source Bits 0
1 ADTS1 ADC Auto Trigger Source Bits 0
0 ADTS0 ADC Auto Trigger Source Bits 0

ADCSRB = 0x00

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit 0
6 REFS2 Reference Selection Bit 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit 0
6 REFS2 Reference Selection Bit 0
5 ADLAR ADC Left Adjust Result

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit 0
6 REFS2 Reference Selection Bit 0
5 ADLAR ADC Left Adjust Result 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit 0
6 REFS2 Reference Selection Bit 0
5 ADLAR ADC Left Adjust Result 1
4 MUX4 ADC Channel selection bit-4

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit 0
6 REFS2 Reference Selection Bit 0
5 ADLAR ADC Left Adjust Result 1
4 MUX4 ADC Channel selection bit-4 0
3 MUX3 ADC Channel selection bit-3 0
2 MUX2 ADC Channel selection bit-2 0
1 MUX1 ADC Channel selection bit-1 0
0 MUX0 ADC Channel selection bit-0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit 0
6 REFS2 Reference Selection Bit 0
5 ADLAR ADC Left Adjust Result 1
4 MUX4 ADC Channel selection bit-4 0
3 MUX3 ADC Channel selection bit-3 0
2 MUX2 ADC Channel selection bit-2 0
1 MUX1 ADC Channel selection bit-1 0
0 MUX0 ADC Channel selection bit-0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX - ADC Multiplexer Selection Register


This register is Used to select ADC channel

Bit Symbol Description Bit Value


7 REFS1 Reference Selection Bit 0
6 REFS2 Reference Selection Bit 0
5 ADLAR ADC Left Adjust Result 1
4 MUX4 ADC Channel selection bit-4 0
3 MUX3 ADC Channel selection bit-3 0
2 MUX2 ADC Channel selection bit-2 0
1 MUX1 ADC Channel selection bit-1 0
0 MUX0 ADC Channel selection bit-0 0

ADMUX = 0x20

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Reference Voltage Selection Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Reference Voltage Selection Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Left Adjustment Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADC Left Adjustment Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX5:0 Channel Selection

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX5:0 Channel Selection

MUX5:0 ADC Channel


00000 ADC0
00001 ADC1
00010 ADC2
00011 ADC3
00100 ADC4
00101 ADC5
00110 ADC6
00111 ADC7

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX5:0 Channel Selection

MUX5:0 ADC Channel


00000 ADC0
00001 ADC1
00010 ADC2
00011 ADC3
00100 ADC4
00101 ADC5
00110 ADC6
00111 ADC7

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ADMUX5:0 Channel Selection

MUX5:0 ADC Channel MUX5:0 ADC Channel


00000 ADC0 10000 ADC8
00001 ADC1 10001 ADC9
00010 ADC2 10010 ADC10
00011 ADC3 10011 ADC11
00100 ADC4 10100 ADC12
00101 ADC5 10101 ADC13
00110 ADC6 10110 ADC14
00111 ADC7 10111 ADC15

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ACSR - Analog Comparator Control and Status Register


This register is Used for Analog Comparator

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ACSR - Analog Comparator Control and Status Register


This register is Used for Analog Comparator

Bit Symbol Description Bit Value

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ACSR - Analog Comparator Control and Status Register


This register is Used for Analog Comparator

Bit Symbol Description Bit Value


7 ACD Analog Comparator Disable

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ACSR - Analog Comparator Control and Status Register


This register is Used for Analog Comparator

Bit Symbol Description Bit Value


7 ACD Analog Comparator Disable 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ACSR - Analog Comparator Control and Status Register


This register is Used for Analog Comparator

Bit Symbol Description Bit Value


7 ACD Analog Comparator Disable 1
6 ACBG Analog Comparator Bandgap Select 0
5 ACO Analog Comparator Output 0
4 ACI Analog Comparator Interrupt Flag 0
3 ACIE Analog Comparator Interrupt Enable 0
2 ACIC Analog Comparator Input Capture Enable 0
1 ACIS1 Analog Comparator Interrupt Mode Select 0
0 ACIS0 Analog Comparator Interrupt Mode Select 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ACSR - Analog Comparator Control and Status Register


This register is Used for Analog Comparator

Bit Symbol Description Bit Value


7 ACD Analog Comparator Disable 1
6 ACBG Analog Comparator Bandgap Select 0
5 ACO Analog Comparator Output 0
4 ACI Analog Comparator Interrupt Flag 0
3 ACIE Analog Comparator Interrupt Enable 0
2 ACIC Analog Comparator Input Capture Enable 0
1 ACIS1 Analog Comparator Interrupt Mode Select 0
0 ACIS0 Analog Comparator Interrupt Mode Select 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

ACSR - Analog Comparator Control and Status Register


This register is Used for Analog Comparator

Bit Symbol Description Bit Value


7 ACD Analog Comparator Disable 1
6 ACBG Analog Comparator Bandgap Select 0
5 ACO Analog Comparator Output 0
4 ACI Analog Comparator Interrupt Flag 0
3 ACIE Analog Comparator Interrupt Enable 0
2 ACIC Analog Comparator Input Capture Enable 0
1 ACIS1 Analog Comparator Interrupt Mode Select 0
0 ACIS0 Analog Comparator Interrupt Mode Select 0

ACSR = 0x80

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


ADC Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


ADC Initialization

ADC Port Pin Config

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


ADC Initialization

ADC Port Pin Config


void adc_pin_config (void) //Configure ADC Ports
{

Port K and Port F must be defined Input

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


ADC Initialization

ADC Port Pin Config


void adc_pin_config (void) //Configure ADC Ports
{

Port K and Port F must be defined Input

ADC Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


ADC Initialization

ADC Port Pin Config


void adc_pin_config (void) //Configure ADC Ports
{

Port K and Port F must be defined Input

ADC Initialization
void adc_init() //Set Register Values for starting ADC
{

ADCSRA =
ADCSRB =
ADMUX =
ADCSRA =
ACSR =
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


ADC Initialization

ADC Port Pin Config


void adc_pin_config (void) //Configure ADC Ports
{

Port K and Port F must be defined Input

ADC Initialization
void adc_init() //Set Register Values for starting ADC
{

ADCSRA =
ADCSRB =
ADMUX =
ADCSRA =
ACSR =
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

Main Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

Main Program
int main(void)
{
init_devices();
lcd_init();
while(1)
{
print_sensor(1,1,0);
print_sensor(1,4,1);
print_sensor(1,8,2);
}
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

Main Program
int main(void)
{
init_devices();
lcd_init();
while(1)
{
print_sensor(1,1,0);
print_sensor(1,4,1);
print_sensor(1,8,2);
}
}

Print ADC Value on LCD

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

Main Program
int main(void)
{
init_devices();
lcd_init();
while(1)
{
print_sensor(1,1,0);
print_sensor(1,4,1);
print_sensor(1,8,2);
}
}

Print ADC Value on LCD


void print_sensor(char row, char column, unsigned char channel)
{

ADC_Value = ADC_Conversion(channel);
lcd_print(row, column, ADC_Value, 3);

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 18/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

ADC Conversion Function

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 18/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Syntax for C-Program


Program

ADC Conversion Function


unsigned char ADC_Conversion(unsigned char Ch)
{
unsigned char a;
if(Ch>7)
{
ADCSRB = 0x08;
}
Ch = Ch & 0x07;
ADMUX= 0x20 | Ch;
ADCSRA = ADCSRA | 0x40; //Set start conversion bit
while((ADCSRA&0x10)==0); //Wait for ADC conversion to complete
a=ADCH;
ADCSRA = ADCSRA|0x10; //clear ADIF (ADC Interrupt Flag) by writing 1 to it
ADCSRB = 0x00;
return a;

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 18/19


ADC Initilization
ADCSRA
Outline
ADCSRB
Analog to Digital Conversion
ADMUX
Coding ADC
ACSR
Program

Thank You!
Post your queries on: http://qa.e-yantra.org/

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 19/19