Analog To Digital Converter With Two-Digit Seven Segment Display

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

A

Project Report
on

Analog to Digital Converter


with two-digit
Seven Segment Display

Designed and fabricated


as part of the
winter training program 2002

Submitted to : Dhananjay V. Gadre


Lecturer
Dept. of Electronics and Communications
Netaji Subhas Institute of Technology
New Delhi

Submitted by : Group - 49
Joy Sharma (46/ECE/2000)
Sameer Singh (83/ECE/2000)
VI Semester
Electronics and communication

February 2003
C ONTENTS

1. Certificate………………………………………………………… 1
2. Acknowledgements……………………………………………… 2
3. Introduction………………………………………………………. 3
4. Block Diagram and Working……………………………………. 4
5. Components……………………………………………………… 6
6. Calculations………………………………………………………. 10
7. Schematic………………………………………………………… 11
8. PCB Layout………………………………………………………. 12
9. Component Layout………………………………………………. 13
10. Flow Chart………………………………………………………… 14
11. Code………………………………………………………………. 15
12. Problems Faced…………………………………………………. 21
13. Photograph……………………………………………………….. 22
14. References……………………………………………………….. 23
1

CERTIFICATE

This is to certify that Joy Sharma (46/ECE/2000) and Sameer Singh (83/ECE/2000),
students of Netaji Subhas Institute of Technology, have designed and fabricated this project
under my guidance, as part of their winter training program of B.E. (3 rd Year). They have
designed and fabricated a Voltage Analog to Digital Converter with a two digit seven
segment display using the Atmel® AVR AT90S2313 microcontroller.

Date - 24th February 2003

(Dhananjay V. Gadre)
Lecturer
Dept. of Electronics and Communications
Netaji Subhas Institute of Technology
New Delhi
2

A CKNOWLEDGEMENTS

We would like to thank Dr. Dhananjay V. Gadre for his support and uncompromising help
during both the design and fabrication of the AVR project for the winter training. We would
also like to thank him for the tips that he kept giving us throughout the process that in effect
let us make use of his experience in the field.
3

INTRODUCTION

As part of the winter training program in our college for the winter of 2002, we were taught
the architecture of the AVR group of microcontrollers, and how to program them. A project
was also assigned to us for hands-on experience and better understanding of the AVR
microcontroller and PCB design and fabrication.

The project that has been assigned to us is to design an ADC with a two-digit seven-
segment display. The range of the input voltage is from 0V to 3.0V and the output
(consisting of two seven segment LED display units) has a least count of 0.1V. To do this
we have used the AVR AT90S2313 microcontroller along with other components such as a
capacitor to sample the voltage, resistors, switching transistors etc and also a 10-pin box
header so as to make in -system reprogramming feasible.

The block diagram for the seven segment display ADC and it’s working is discussed in the
next section.
4

BLOCK DIAGRAM A ND WORKING

As is clear from the above Block Diagram, we are using a constant current source to charge
the capacitor (voltage sampling) and the value of this charged capacitor is going into the
analog comparator inside the microcontroller. The other value of the comparator input is the
voltage that has to be converted to digital (Vin ). As the value of the constant current is
known, we know how much time the capacitor will take to charge to the maximum voltage.

We thus run a counter in our program which reaches a maximum value of $FF (255) in
exactly that much time, unless the output of the analog comparator changes (which we
keep polling while incrementing the counter). If the output of the comparator changes, then
it means, at that instant the voltage of the capacitor is equal to the input voltage Vin. The
value of the counter at this instant can thus be used to calculate the input voltage as shown
below :

Vin = (Reading of counter) x Vmax


255

The value of Vmax already known ( = 3 volts) we can easily calculate the value of Vin . Thus
in the program we have made a simple mapping from, the value of the counter to the
voltage value to be displayed. This voltage is then displayed on the seven segment LED
5

displays by time multiplexing the seven segment displays as shown by the time flow chart
below :

Sample value Display Higher Digit Sample value Display Lower Digit

Initially the value of voltage is sampled and the higher digit is calculated and displayed
while discharging the capacitor rapidly by making its pin low. Next time around the value of
the lower digit is calculated and displayed instead of the higher one and discharging is done
as before.

The flow chart clearly shows that the times of output being shown on both the displays will
be equal only if the voltage doesn’t change too often, which causes both the digits to glow
with equal brightness. Thus we need to put a limit on the input voltage – it should not
change drastically within one cycle that will be a maximum of 10ms for a full-scale input
voltage. This however is a very reasonable limit because even if an ADC follows the input
which changes faster than that and displays the result, the human eye is not capable of
registering any value which doesn’t stay same for atleast 1/24 th of a second, thus we won’t
be able to read the output anyways. If however we intend to use this ADC to feed a system
that requires the value of the input voltage to be updated more frequently, we can take the
following steps :

- We can increase the va lue of the constant current causing the capacitor to charge
faster thus the output response will toggle faster.
- However for this we will need a better current source, a capacitor with lesser internal
leakage and we might want to isolate the current source electrically from the
microcontroller.
- At even higher speeds the discharging rate of the capacitor will also become a
problem in which case we will need to sink current to ground instead of to the
microcontroller by using a switch controlled by the micro controller.

The next section describes in detail all the components used in the making of the ADC,
including the Atmel® AT90S2313 microcontroller.
6

COMPONENTS U SED

ATMEL ® AVR AT90S2313 M ICROCONTROLLER

For our project, the following was required from the microcontroller.
- An Analog Comparator
- 7 port pins for displays
- 2 port pins for multiplexing
- 3 port pins for charging/discharging the capacitor
- Program Memory
- SRAM

After considering the available microcontrollers from Atmel®, the AT90S2313


microcontroller was found to be appropriate for our use. Its specifications are :
- 2K Bytes of In-System Programmable Flash
- 128 Bytes of SRAM
- 15 Programmable I/O Lines (two ports of 8 pins and 7 pins)
- On-chip Analog Comparator

The pin configuration and description for the Atmel® AT90S2313 microcontroller from the
datasheet have been given below along with the descriptions of the Analog Comparator,
the crystal pins etc.

Pin Descriptions

o VCC Supply voltage pin.

o GND Ground pin.


7

o Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port. Port pins can provide
internal pull-up resistors (selected for each bit). PB0 and PB1
also serve as the positive input (AIN0) and the negative input
(AIN1), respectively, of the on-chip analog comparator. The Port
B output buffers can sink 20 mA and can drive LED displays
directly. When pins PB0 to PB7 are used as inputs and are
externally pulled low, they will source current if the internal
pullup resistors are activated. The Port B pins are tri-stated
when a reset condition becomes active, even if the clock is not
active.

o Port D (PD6..PD0) Port D has seven bi-directional I/O ports with internal pull-up
resistors, PD6..PD0. The Port D output buffers can sink 20 mA.
As inputs, Port D pins that are externally pulled low will source
current if the pull -up resistors are activated. The Port D pins are
tri-stated when a reset condition becomes active, even if the
clock is not active.

o Reset A low level on this pin for more than 50 ns will generate a reset,
even if the clock is not running. Shorter pulses are not
guaranteed to generate a reset.

o XTAL1 Input to the inverting oscillator amplifier and input to the internal
clock operating circuit.

o XTAL2 Output from the inverting oscillator amplifie r.

The Analog Comparator

The Analog Comparator compares the input values on the positive input AIN0 (PB0) and
the negative input PB1(AIN1). When the voltage on the positive input PB0 (AIN0) is higher
than the voltage on the negative input PB1 (AIN1), the Analog Comparator Output, ACO is
set (one). A block diagram of the comparator is shown in the figure below.
8

The Crystal Oscillator

XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier that can be
config ured for use as an on-chip oscillator. Either a quartz crystal or a ceramic resonator
may be used. We have used a 4Mhz quartz crystal to drive the clock of the microcontroller
and it has been connected as shown in the figure below :

BOX HEADER

A 10-pin box header has been used to facilitate In -system programming. The pin
configuration of the header is given below along with the connections to be made to the
microcontroller pins.
Pin 1 – PB5 Pin 2 – Vcc
Pin 3 – Open Pin 4 – GND
Pin 5 – Reset Pin 6 – GND
Pin 7 – PB7 Pin 8 – GND
Pin 9 – PB6 Pin 10 – GND

Pin configuration Pin Connections

SEVEN S EGMENT D ISPLAY U NITS


Two HDSP-5501 were used in our project because they matched our required size and
power requirements. They use LEDs that have a voltage drop of 1.9V and require current
no greater than 20mA. The pin configuration is given as below.

Component Side Solder Side


9

T RANSISTORS
The transistors used are PNP bipolar junction transistors. Due to capacitor charging and
LED driving current requirements, we have used BC-557.

PRINTED CIRCUIT BOARD


The PCB used is single sided and is 3” x 5” in size.

RESISTORS & CAPACITORS


The resistors used are wire wound resistors and the capacitors used are ceramic
capacitors.
10

CALCULATIONS

We know that V CC = 5.0 V


The maximum range of input voltage Vin is (VC(max) ) = 3.0 V
We are keeping V CE of the current source capacitor = 1.0 V
∴VB = 5.0 – 1.0 – 0.7 = 3.3 V
⇒ Rb = 3.3
Ra 1.7
Hence, keeping available values of resistors in mind, we have chosen
Rb = 33k?
Ra = 18k? .

We have the equation I = C dV/dt


⇒ I/C = V/T

The value of Capacitor (C) = 0.1µF


And the charging time required for the capacitor is 5 ms. Putting these values in the above
equation, we get –
I = (3 x 1 x 10-6)
5 x 10-3
⇒ I = 0.6 mA

Thus the value of R can be calculated as follows:


R = (5.0 – 4.0)
0.6mA
⇒ R = 1.67k?
From the available values the value chosen was R = 1.5 k?

Now the value of the discharging resistor can be calculated as:


VC(max) / RC ≤ 20mA
⇒ RC ≥ 150?

Thus the value chosen was a safe Rc = 220?

For the LEDs the limiting current is 20mA and the drop across them is 1.9 volts thus the
calculations yield:
Rd ≥ (5.0 – 1.9)
20 x 10-3
⇒ Rd ≥ 155?

Thus we again chose the value Rd = 220?


11
12
12
13
14

FLOW CHART

Initialize Ports, Analog


Comparator, Variables

Calculate Higher &


Lower digits

Display higher digit. Y N Display lower digit.


tog = 0 Tog=1 tog = 1

Delay

Counter = 0

Charge

Y
ACO = 1

Counter ++

Delay

Y Counter N
Overflow?
15

CODE
;*******************************************************************************************************
; ADC with 7 segment display |
;*******************************************************************************************************

;Joy Sharma - 46/ECE/2000


;Sameer Singh - 83/ECE/2000

;This is the AVR code for the AVR microcontroller. The code executes in the following
;fashion.

;1. Initialization
;2. Displaying Higher/Lower Nibble
;3. Long Delay (for displaying the digit)
;4. Discharging (with delay)
;5. Start Charging and set counter to zero
;6. If analog comparator = 1, goto Step 2.
;7. Increment Counter and small delay
;8. Check for overflow, if yes goto step 2
;9. goto Step 6.

;*******************************************************************************************************
; AVR Interface Specifications
;*******************************************************************************************************
;The AVR microcontroller used is AT90S2313, which has two ports, B and D. Port D has
;seven pins which have been connected to the two seven segment displays. Port B has 8
;pins. PB1 pin is connected to the input voltage. PB0 pin is connected to the emitter of the
;BJT through a resistor. PB2 pin is used to ground or unground the BJT. PB3 and PB4 pins
;are used for multiplexing between the two display units, each pin directly controlling on
;display unit.

;The analog comparator in AVR 2313 is connected to PB0 (+) and PB1 (-). The oscillator
;used is of 4Mhz frequency.

.include "2313def.inc"

;*******************************************************************************************************
;Definitions
;*******************************************************************************************************
;Includes .def and .equ statements for the variables
;used.

.def tog =r25 ; toggle variable, to decide which digit to show


16

.def count=r24 ; the counter

; The following variables store the value for DDRB and the PortB using charging and
; discharging.
.equ charDD =$1c ;0001 1100
.equ disDD =$1d ;0001 1101
.equ charPB =$1c ;0001 1100
.equ disPB =$18 ;0001 1000

reset:
;*******************************************************************************************************
;|Initialization|
;*******************************************************************************************************
;Initialising Stack Pointer
ldi r16,low(RAMEND)
out SPL,r16

;I/O Configuration of Ports


;Initial config of portB is that of discharging
ldi r16, disDD
out DDRB, r16
ldi r16, $ff
out DDRD, r16

;Analog Comparator Initialisation


;Interrupts are disabled. Polling Technique has been used
ldi r16, $00 ;acd=0,acs1=0,acs0=0,aco=0
out ACSR, r16

;Initialising Data for Display


;In the program, the bit patterns for all the digits
;are stored in the data segment of the RAM, with the
;base address of 0x0060.
clr r27 ; init X pointer with 0x0060
ldi r26,$60 ; start of data segment
ldi r16,0b01000000 ;bit pattern for 0
st x+,r16
ldi r16,0b01110011 ;bit pattern for 1
st x+,r16
ldi r16,0b00100100 ;bit pattern for 2
st x+,r16
ldi r16,0b00100001 ;bit pattern for 3
st x+,r16
ldi r16,0b00010011 ;bit pattern for 4
st x+,r16
ldi r16,0b00001001 ;bit pattern for 5
17

st x+,r16
ldi r16,0b00001000 ;bit pattern for 6
st x+,r16
ldi r16,0b01100011 ;bit pattern for 7
st x+,r16
ldi r16,0b00000000 ;bit pattern for 8
st x+,r16
ldi r16,0b00000001 ;bit pattern for 9
st x+,r16
ldi r26, $60 ;Restore X pointer to 0x0060

;*******************************************************************************************************
;|Main Loop|
;*******************************************************************************************************
;This is the main loop of the program

loop:

;Call the Display subroutine, followed by a long delay


rjmp disp
back: rcall delaylong

;Discharge the capacitor


ldi r16, $18
out PORTB, r16
ldi r16, disDD
out DDRB, r16
rcall delayd
ldi count,$00 ; Counter=zero
;Start charging
ldi r16, charDD
ldi r17, charPB
out DDRB, r16
out PORTB, r17
charging:
sbic ACSR, 5 ; Check ACO for 1
rjmp loop ; loops if it is
inc count
rcall delayc
cpi count, $ff ; Check for overflow
brne charging ; continue if its not
rjmp loop ; loop again if it is
18

;*******************************************************************************************************
;* Sub-Routines *
;*******************************************************************************************************

;*******************************************************************************************************
; Display Sub-routine
;*******************************************************************************************************
disp:

;First we move the higher and lower nibbles of the counter to r17 and r16 respectively.
;Lower nibble is seperated by AND-ing count with 0x0F. Higher nibble is seperated by
;Logical Shifting Right counter four times.
mov r16, count
mov r17, count
andi r16, $0F
LSR r17
LSR r17
LSR r17
LSR r17

;get the digits into r16 & r17


rcall getdigit

;Checks toggle - If zero, displays higher digit


; If one, displays lower digit
cpi tog, $00
brne disp2

disp1:
ldi r18, $f8 ;switch displays off
out portb, r18
add r26,r16 ;Adds required digit to X pointer to find
ld r16,x ;the address of the corresponding bit pattern
out portd, r16
andi r18, $f0 ;switch display 1 on
out portb, r18
ldi tog, $ff ;Set toggle to non-zero
ldi r26,$60 ;reset X pointer
rjmp back

disp2:
ldi r18, $f8 ;switch displays off
out portb, r18
add r26,r17
ld r17,x
out portd, r17
19

ldi r18, $08 ;switch display 2 on


out portb, r18
ldi tog, $00
ldi r26,$60
rjmp back
;*******************************************************************************************************
;Delay Sub-Routines
;*******************************************************************************************************
;all these delay routines either use a single or a double decreasing loop to delay the
;processor.

;Charging delay
;for the delay in each charging loop
;very crucial since 256 cycles of the counter increments
;should corespond to 5ms (max voltage input chargin time)
;Time = 5000 / 256 = 19.50 us (approx)
delayc:
nop
ldi r16, $10
loopc: dec r16
cpi r16, $00
brne loopc
ret

;Discharging Delay
;discharging time was calculated to be 22us, but just to be sure, since there is no harm, the
;delay is aprroximately 35us.
delayd: ;20us delay (approx)
ldi r16, $20
rjmp loopc

;Display Delay
;This delay uses a double loop to display the required the digit for appropriate time.
;too less delay causes less intensity and higher delay causes flickering. The time was
;arrived at by trial and error.
delaylong:
ldi r16 , $1f
lloop1: ldi r17, $ff
lloop2: dec r17
cpi r17,$00
brne lloop2
dec r16
cpi r16,$00
brne lloop1
ret
20

;*******************************************************************************************************
;GetDigit Sub-Routine
;*******************************************************************************************************
;This sub-routine, according to the nibbles in r16 and r17, calculates in decimal the required
;digits.This does not use any multiplication/division routines, instead does basic calculations
;to arrive at the required digits(stored in r21(higher) and r22(lower))

;first r17 is checked


;for 0-4 r21=0
;for 5-9 r21=1
;for a-e r21=2
;for f r21=3
;then appropriate value(i.e.0,5,a,etc.) is deleted
;from r17 to get {r17}%5. The result is stored in
;r17 itself

;This value in r17 is used to calulate lower digit too. It is multiplied by 2 to get the lower
;digit(r22). This is because we are dividing each higher digit into 5 parts. Therefore, each
;value in higher nibble of the counter can define voltage to 0.2V. Since the least count of the
;ADC is 0.1V, the lower nibble is checked.If it is higher than 0x08, then 22 is incremented.

getdigit:
clr r21
clr r22
ldi r23,$05
jhigher:
cpi r17,$05
brlo jlower
inc r21
subi r17,$05
rjmp jhigher
jlower: ldi r23, $02
jmp2: cpi r17,$00
breq jmp
add r22, r23
dec r17
rjmp jmp2
jmp: cpi r16, $08
brlo jend
inc r22
jend: mov r16,r22
mov r17,r21
ret
21

PROBLEMS FACED

- Layout and Design

o The correct size of the box header was not considered, and thus, in the first
design, box header was too close to the IC socket.
o A dilemma was faced when deciding whether a track can be passed between
two adjacent pins of an IC. In the final design, only one track passed between
two pins. Thus we eliminated all jumpers from the design.

- PCB fabrication

o The paint that came of the tracks after etching colored the board and then had
to be removed with a lot of thinner and rubbing.
o During drilling the bit was too long so it wobbled a lot, making the initial holes
mis aligned and bigger than needed.
o The board was not soldered for a long time after etching so the copper was
oxidized and a lot of flux had to be used to produce good contacts.
o Also the pins of the box header and the IC socket became loose when they
were being soldered due to the heat and later they had to be desoldered and
fixed into position.

- Software

o The biggest problem faced was obviously the timing of the delays in the
program such that the counter gave a maximum count of 255 for the full scale
input of 3.0 V. For this the software was burned and the output checked
manually and again, till the correct calibration was achieved.
o Another very big problem to be dealt was to time the displays just right so that
we do not see a flicker while having a brightly lit display.
22

PHOTOGRAPHS

Component Side

Solder Side
23

REFERENCES

o Programming and customizing the AVR RISC microcontrollers – Dhananjay V.


Gadre – Mc Graw Hill Publications,1999

o Datasheet of AT90S2313 AVR Microcontroller

o Software from website Avrfreaks.net (http://www.avrfreraks.net)

o General information and datasheets from Atmel® (www.atmel.com)

You might also like