# Interfacing a DAC with 8051 and using a ADC to set the reference voltage of DAC

Discussion in 'Homework Help' started by isurunix, Feb 4, 2015.

1. ### isurunix Thread Starter New Member

Feb 3, 2015
21
0
I'm going through my university assignment and got stuck here. Help needed asap as due date is near.

Draw a block diagram to interface an 8 bit ADC with 8051. Clearly show your calculations
and assumptions to use above DAC to set the ADC reference voltage 10 V and display the
result in three seven segment displays.

DAC discussed here is from the following question,
"The nbit R/2R digitaltoanalog converter (DAC) has a reference of 16 V and the analog
output for the input code 1 is 15.625 mV. Find the digital input value for the output
9.140625 V."
So far I have done following calculations and answers

Block Diagram

Calculations

Output = 10V
Input = 10/15.625*10^-3 = 640
Input digital signal = 1010000000

I can understand that I have to send the input signal to the DAC discussed here using the 8051 and I can use Vout of the DAC as the reference for ADC

What I cannot understand is what is meant by displaying the value in 7 segment displays ( What do I have to display ? ) and what are the required calculations and assumptions.​

2. ### ericgibbs AAC Fanatic!

Jan 29, 2010
2,589
389
hi,
A display digit is comprised of 7 segments, the segments are switch ON to produce the numbers from 0 thru 9 . See image
I order to display bigger value numbers a series of 7 segment displays are required.

As you may know an 8 bit ADC will give 0 thru 0xFF counts, which you have to convert to ASCII decimal, then display the value using 3, 7seg displays.

File size:
12.7 KB
Views:
96
3. ### isurunix Thread Starter New Member

Feb 3, 2015
21
0
Can you please elaborate on converting to a ASCII decimal? So far I have understood I can get binary out puts from the ADC in the range 00000000 to 11111111.
For the DAC discussed here it will give 00000001 at 39mV, 00000010 at 2*39mV and so on in 39mV steps. What is the way to display the relevant voltage in the 7segs. For a example when DAC is giving 00000010 as the output 7segs should be displaying 0.07 or 0.08.

Am I understanding this correct? If anything is wrong please tell me.

4. ### isurunix Thread Starter New Member

Feb 3, 2015
21
0
@ericgibbs Can you please tell me how ascii conversion can be displayed on 7seg?

5. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
A 7-segment display doesn't use ASCII (now, if you were using a display module with an interface protocol, that might be a different story).

You have a microcontroller. You have an input. You need to produce an output. You need to write a program to get the input and produce that output. The first step is understanding what your input means and what you want the output to be.

If the input from the ADC is 0x3A, what is the voltage? What value do you want displayed? How did you do that by hand? If you came up with the voltage being 2.27451V, then with three displays available, what digits do you want displayed on each one? How can you come up with those digits using a step-by-step algorithm?

6. ### isurunix Thread Starter New Member

Feb 3, 2015
21
0
.o.

For the input 0x3A I can calculate the value as followes,
0x3A = 58 in decimal
voltage to be displayed : 58*o.039 =2.262

Assuming 2.26 to be displayed on the 3, 7segs.

One approach I thought of is to read in the hex value from the ADC and set the 7segs to the relevant value. But this produces a lengthy code and I have to calculate all the values for 255 ADC outputs to be displayed on the 7segs. I'm thinking there have to be a better algorithm. Can you give me a hint?

7. ### isurunix Thread Starter New Member

Feb 3, 2015
21
0
@WBahn Hi, can you please help me with this. I'm in a rush and this is my first time learning about microcontrollers. I can think of many ways to do this in some high level language. But they get very complex when trying to implement using 8051. So please can you give me hint.

8. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
Often the best way to tackle an assembly language problem is to first develop and test the algorithm in a high level language and then translate it to assembly. If nothing else, this separates the development of the algorithm from the implementation of the code.

If you have the memory, one option is to precompute the values to be displayed for every possible ADC output value -- this is called a LUT (look-up table). Since it is only 8-bit, this is quite easy to do and doesn't take much memory. You can use two bytes for each value (leaving 4-bits unused) so you only need 512 bytes of memory (generally stored as part of the program code) to implement the table depending on how you have to implement the LUT in the 8051 (I've never worked with that particular processor, so I'm not sure).

Another way is to calculate it the same way you would do it by hand, namely multiply the input value by a scaling factor and then pick off the individual digits.

9. ### crutschow Expert

Mar 14, 2008
13,477
3,362
Here's a search result for binary-to-decimal algorithms as an alternate to using a look-up table.