1 © unitec new zealand digital to analogue converter

31
1 © Unitec New Zealand Digital to Analogue Converter

Upload: rebecca-parsons

Post on 30-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 © Unitec New Zealand Digital to Analogue Converter

1© Unitec New Zealand

Digital to Analogue Converter

Page 2: 1 © Unitec New Zealand Digital to Analogue Converter

ADC Characteristics

• All real world quantities are analog in nature. We need to convert that analog quantities to digital as computer understand the world of 1’s and 0’s. Then we are able to display an analog quantity.

2© Unitec New Zealand

Page 3: 1 © Unitec New Zealand Digital to Analogue Converter

Temperature sensor

3© Unitec New Zealand

Page 4: 1 © Unitec New Zealand Digital to Analogue Converter

ADC resolution

• ADC has n-bit resolution, where n can be 8, 10, 12, 16 or 24 bits.

• The higher resolution provides a smaller step size, where step size is the smallest change that can be discerned by an ADC.

• Although the resolution of ADC chip is decided at the time of its design and cannot be changed, but we can control the step size with the help of what is called vref.

4© Unitec New Zealand

Page 5: 1 © Unitec New Zealand Digital to Analogue Converter

Resolution of ADC

• Resolution vs step size for ADC (vref=5V)

5© Unitec New Zealand

N-bit Number of steps Step size (mV)

8 256 5/19.53=19.53

10 1024 5/1024=4.88

12 4096 5/4096=1.2

16 65536 5/65536=0.076

Page 6: 1 © Unitec New Zealand Digital to Analogue Converter

Conversion time

• Conversion time is defined as the time, it takes to convert the analog input to a digital (binary ) number.

• The conversion time is dictated by the clock source connected to the ADC in addition to the method used for data conversion and technology used in the fabrication of ADC chip such as MOS or TTL technology

6© Unitec New Zealand

Page 7: 1 © Unitec New Zealand Digital to Analogue Converter

V reference

• Vref is input voltage used for the reference voltage.

• The voltage connected to this pin, along with the resolution of the ADC chip, dictate the step size.

• For an 8-bit ADC, the step size is Vref/256.

7© Unitec New Zealand

Page 8: 1 © Unitec New Zealand Digital to Analogue Converter

Vref relation to Vin range for an 8bit ADC

Vref (V) Vin (V) Step size (mV)

5 0 to 5 5/256=19.53

4 0 to 4 4/256=15.62

3 0 to 3 3/256=11.71

2 0 to 2 2/256=7.81

1 0 to 1 1/256=3.9

8© Unitec New Zealand

Page 9: 1 © Unitec New Zealand Digital to Analogue Converter

Vref relation to Vin range for an 10bit ADC

Vref (V) Vin (V) Step size (mV)

5 0 to 5 5/1024=4.88

4.096 0 to 4.096 4.096/1024=4

3 0 to 3 3/1024=2.93

2.048 0 to 2.048 2.048/1024=2

1.024 0 to 1.024 1.024/1024=1

9© Unitec New Zealand

In some applications, we need the differential reference voltage where Vref=Vref(+) – Vref(-).

Page 10: 1 © Unitec New Zealand Digital to Analogue Converter

Digital data output

• In an 8 bit ADC, we have an 8 bit digital data output of D0-D7 while in the 10 bit ADC the data output is D0-D9.

• To calculate the output voltage, the formula used is

Dout= Vin/ step size

Where Dout =digital data output (in decimal), Vin=analog input voltage and step size (resolution) is the smallest change, which is Vref/256 for an 8 bit ADC.

10© Unitec New Zealand

Page 11: 1 © Unitec New Zealand Digital to Analogue Converter

Example

• For an 8 bit ADC, we have Vref=2.56 V. calculate the D0-D7 output if analog input is a) 1.7 V

b) 2.1 V

Solution:-A)Step size is 2.56/256= 10 mv,

Dout= 1.7/10mv =170 in decimal

Binary 170=10101011

Find out solution for b.

11© Unitec New Zealand

Page 12: 1 © Unitec New Zealand Digital to Analogue Converter

Analog input channels

• Normally, many data acquisition systems have more than one ADC channels.

• PIC16F877a have 11 Analog channels and it can accept 11 analog sources to be digitized but only one input channel can be digitized at a time.

12© Unitec New Zealand

Page 13: 1 © Unitec New Zealand Digital to Analogue Converter

Start conversion and end of conversion signals

• In case of multiple analog input channels and a single digital output register makes it necessary for start conversion (SC) and end of conversion (EOC) signals.

• When SC activated, the ADC starts converting the analog input value of Vin to an n-bit digital number.

• The amount of time it takes to convert varies depending on the conversion method.

• When the data conversion is complete, the end EOC signal notifies the CPU that the converted data is ready to be picked up.

13© Unitec New Zealand

Page 14: 1 © Unitec New Zealand Digital to Analogue Converter

Steps to follow for ADC Chip

1. Select a channel

2. Activate the start of conversion (SC) signal to start the analog input.

3. Keep monitoring the end of conversion signal

4. After the EOC has been activated, read the data out from ADC chip

14© Unitec New Zealand

Page 15: 1 © Unitec New Zealand Digital to Analogue Converter

ADC in PIC

• Following registers control the functionality of ADC in PIC 16f877a.– ADCON0, ADCON1– ADRESH, ADRESL– ADSELH, ADSEL– INTCON, PIE1, PIR1– PORTA, B, C– TRISA, B, C

15© Unitec New Zealand

Page 16: 1 © Unitec New Zealand Digital to Analogue Converter

ADC in PIC microcontroller.

• PIC has 10 bit resolution Analog-to-Digital Converter.

• This device uses analog inputs, which are multiplexed into a single sample and hold circuit. The output of the sample and hold is connected to the input of the converter.

• The converter generates a 10-bit binary result via successive approximation and stores the conversion result into the ADC result registers (ADRESL and ADRESH).

• The ADC voltage reference is software selectable to either VDD or a voltage applied to the external reference pins.

• The ADC can generate an interrupt upon completion of a conversion. This interrupt can be used to wake-up the device from Sleep.

16© Unitec New Zealand

Page 17: 1 © Unitec New Zealand Digital to Analogue Converter

ADC Block diagram

17© Unitec New Zealand

Page 18: 1 © Unitec New Zealand Digital to Analogue Converter

ADC Configuration

• When configuring and using the ADC the following functions must be considered:– Port configuration– Channel selection– ADC voltage reference selection– ADC conversion clock source– Interrupt control– Results formatting

18© Unitec New Zealand

Page 19: 1 © Unitec New Zealand Digital to Analogue Converter

PORT CONFIGURATION and channel selection

• The ADC can be used to convert both analog and digital signals. When converting analog signals, the I/O pin should be configured for analog by setting the associated TRIS and ADCON1 bits.

• The CHS bits of the ADCON0 register determine which channel is connected to the sample and hold circuit. When changing channels, a delay is required before starting the next conversion.

• The required delay is basically the time allowed to discharge the capacitor

19© Unitec New Zealand

Page 20: 1 © Unitec New Zealand Digital to Analogue Converter

• The ADC conversion clock is the time that will be used to convert the analog voltage present on the pin to a 10-bit value in the ADRESH:ADRESL registers.

• It takes 11 of these conversion clock cycles to perform a complete ADC. If the conversion clock period is insufficient, an incomplete ADC result will occur.

• The electrical specifications for the PIC16F877a state that the conversion clock must have a period of at least 1.5 μSeconds or a frequency of approximately 667 kHz.

20© Unitec New Zealand

CONVERSION CLOCK

Page 21: 1 © Unitec New Zealand Digital to Analogue Converter

CONVERSION CLOCK

• The source of the conversion clock is software selectable via the ADCS bits of the ADCON0 AND ADCON1 register.

• There are seven possible clock options:– FOSC/2– FOSC/4– FOSC/8– FOSC/16– FOSC/32– FOSC/64– FRC (dedicated internal oscillator)

• The time to complete one bit conversion is defined as TAD. One full 10-bit conversion requires 11 TAD periods

21© Unitec New Zealand

Page 22: 1 © Unitec New Zealand Digital to Analogue Converter

Acquisition time

• When an specific channel is selected the voltage from that input channel is stored in an internal holding capacitor. It takes some time for the capacitor to get fully charged and become equal to the applied voltage. This time is called acquisition time.  Once acquisition time is over the input channel is disconnected from the source and the conversion begin. The acquisition times depends on several factor like the source impedance, Vdd of the system and temperature.

22© Unitec New Zealand

Page 23: 1 © Unitec New Zealand Digital to Analogue Converter

INTERRUPTS

• The ADC module allows for the ability to generate an interrupt upon completion of an Analog-to-Digital conversion. The ADC interrupt flag is the ADIF bit in the PIR1 register. The ADC interrupt enable is the ADIE bit in the PIE1 register. The ADIF bit must be cleared in software.

• This interrupt can be generated while the device is operating or while in Sleep. If the device is in Sleep, the interrupt will wake-up the device. Upon waking from Sleep, the next instruction following the SLEEP instruction is always executed. If the user is attempting to wake-up from Sleep and resume in-line code execution, the global interrupt must be disabled. If the global interrupt is enabled, execution will switch to the interrupt service routine.

23© Unitec New Zealand

Page 24: 1 © Unitec New Zealand Digital to Analogue Converter

Result formating

• The 10-bit A/D conversion result can be supplied in two formats, left justified or right justified. The ADFM bit of the ADCON0 register controls the output format.

24© Unitec New Zealand

Page 25: 1 © Unitec New Zealand Digital to Analogue Converter

25© Unitec New Zealand

Page 26: 1 © Unitec New Zealand Digital to Analogue Converter

26© Unitec New Zealand

Page 27: 1 © Unitec New Zealand Digital to Analogue Converter

ADC Result register high for ADFM=0

27© Unitec New Zealand

Page 28: 1 © Unitec New Zealand Digital to Analogue Converter

ADC result register high ADFM=1

28© Unitec New Zealand

Page 29: 1 © Unitec New Zealand Digital to Analogue Converter

A/D CONVERSION PROCEDURE

29© Unitec New Zealand

• This is an example procedure for using the ADC to perform an Analog-to-Digital conversion:

1. Configure Port:– Disable pin output driver (See TRIS register)– Configure pin as analog

2. Configure the ADC module:– Select ADC conversion clock– Configure voltage reference– Select ADC input channel– Select result format– Turn on ADC module

Page 30: 1 © Unitec New Zealand Digital to Analogue Converter

3.Configure ADC interrupt (optional):– Clear ADC interrupt flag– Enable ADC interrupt– Enable peripheral interrupt– Enable global interrupt(1)

4. Wait the required acquisition time

5. Start conversion by setting the GO/DONE bit.

6. Wait for ADC conversion to complete by one of the following:– Polling the GO/DONE bit– Waiting for the ADC interrupt (interrupts enabled)

7. Read ADC Result

8. Clear the ADC interrupt flag (required if interrupt is enabled).

30© Unitec New Zealand

Page 31: 1 © Unitec New Zealand Digital to Analogue Converter

Steps in programming the A/D converter using polling

1. Make the pin for the selected ADC an input channel.

2. Select voltage reference and A/C input channel.

3. Select the conversion clock.

4. Wait for the required acquisition time.

5. Turn on the ADC module .

6. Activate the start conversion bit of Go/Done.

7. Wait for the conversion to be completed by polling the end of conversion bit.

8. After the GO/DONE bit has gone LOW, read the ADRESL and ADRESH register

9. Go to step 5.

31© Unitec New Zealand