Analog To Digital Converter With Two-Digit Seven Segment Display
Analog To Digital Converter With Two-Digit Seven Segment Display
Analog To Digital Converter With Two-Digit Seven Segment Display
Project Report
on
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.
(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
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 :
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
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
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 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.
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
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
T RANSISTORS
The transistors used are PNP bipolar junction transistors. Due to capacitor charging and
LED driving current requirements, we have used BC-557.
CALCULATIONS
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?
FLOW CHART
Delay
Counter = 0
Charge
Y
ACO = 1
Counter ++
Delay
Y Counter N
Overflow?
15
CODE
;*******************************************************************************************************
; ADC with 7 segment display |
;*******************************************************************************************************
;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.
; 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
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:
;*******************************************************************************************************
;* 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
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
;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))
;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
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