EmbeddedRelated.com
Forums

Converting digital to analog

Started by chryssie0312 August 2, 2007
Oliver Betz wrote:

[that he uses a microscope to do his soldering]

Oh, you *cheat*. $$$

> Ack. But with a bit of flux and the appropriate tip, it's acceptable.
>
> And a QFP100 with 0,5mm pitch is so neat compared to PLCC.

Well, I guess gull-wings look a little more classy.

> Really evil are those packages with hidden solder pads like QFN or
> BGAs. Gladly I could avoid them.

I guess the home experimenter would have to use a toaster oven
or sth to do a ball grid array.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
chryssie0312 wrote:
> Hi,i'm having problems writing my code to convert digital to analog
> values. I am dealing with assembly programming with the 68HC11. I am

And I gave you a large slice of my time writing some advice. It's
considered impolite not to respond. At least by me.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
Mayhap you confused the poor man.

----- Original Message -----
From: Mike McCarty
To: m...
Sent: Friday, August 03, 2007 4:57 PM
Subject: Re: [m68HC11] Converting digital to analog
chryssie0312 wrote:
> Hi,i'm having problems writing my code to convert digital to analog
> values. I am dealing with assembly programming with the 68HC11. I am

And I gave you a large slice of my time writing some advice. It's
considered impolite not to respond. At least by me.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
chryssie0312 wrote:

[snip]

> Using VS = 6V

I missed that. Do you mean Vr for the A/D? If so, then the conversion
factor I gave you is wrong, because I referenced it to 5V.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
Mike McCarty wrote:

> chryssie0312 wrote:
> > Hi,i'm having problems writing my code to convert digital to analog
> > values. I am dealing with assembly programming with the 68HC11. I am
>
> And I gave you a large slice of my time writing some advice. It's
> considered impolite not to respond. At least by me.

Ack.

Times changed, list members changed...

Oliver
--
Oliver Betz, Muenchen
On Thu, 02 Aug 2007 20:34:51 +1000, chryssie0312
wrote:

> Hi,i'm having problems writing my code to convert digital to analog
> values. I am dealing with assembly programming with the 68HC11. I am
> trying to read from the output of the temperature sensor (LM34) and
> not from the amplifier. the program is written to display the range
> of temp. from 0 to 210 degrees fahrenheit and not 0 - FFF on the
> segment display. I am getting the 0-FFF range but not the 0-210. I
> know it has something to do with the idiv and mul instruction but i
> can't seem to get it right Please help me! I'd like a response
> before friday. The calculations are as follows:

grab my fractional_multiply routine from
http://hc11-ide.funkmunch.net/newbrain/kernel/k_battery.s

I have the battery voltage connected to a divide by four then into the
adc, so it multiplies by 78.4296875 to convert the 0-255 adc reading to
millivolts. (255 * 78.4296875 = 19 999.5703)

There's also a lcd print_int routine in
http://hc11-ide.funkmunch.net/newbrain/kernel/k_lcd.s if you need one.
--- In m..., "Oliver Betz" wrote:
>
> Mike McCarty wrote:
>
> > chryssie0312 wrote:
> > > Hi,i'm having problems writing my code to convert digital to
analog
> > > values. I am dealing with assembly programming with the
68HC11. I am
> >
> > And I gave you a large slice of my time writing some advice. It's
> > considered impolite not to respond. At least by me.
>
> Ack.
>
> Times changed, list members changed...
>
> Oliver
> --
> Oliver Betz, Muenchen

> Thanks for the effort to those who helped me. I am very grateful.

Chryssie
----
>
--- In m..., "tj" wrote:
>
> What an extremely cool and detailed answer Mike - kudos to you. :)
>
> I'm just observing by the way, the answer doesn't interest me.
>
> ----- Original Message -----
> From: "Mike McCarty"
> To:
> Sent: Thursday, August 02, 2007 7:16 PM
> Subject: Re: [m68HC11] Converting digital to analog
> > chryssie0312 wrote:
> >> Hi,i'm having problems writing my code to convert digital to
analog
> >
> > Actually, it looks like you are trying to display the output
> > of the A/D converter on the chip, not a D/A conversion.
> >
> >> values. I am dealing with assembly programming with the 68HC11.
I am
> >> trying to read from the output of the temperature sensor (LM34)
and
> >
> > I am familiar with that chip. It puts out 10 mV / degree F. I've
used
> > it myself.
> >
> >> not from the amplifier. the program is written to display the
range
> >> of temp. from 0 to 210 degrees fahrenheit and not 0 - FFF on the
> >> segment display. I am getting the 0-FFF range but not the 0-210.
I
> >
> > Do you mean that you are getting accurate readings? At 210
degrees F
> > that chip puts out 2.1 VDC. This converts to a reading of $6C. The
> > A/D puts out a one-byte reading. $FFF is not possible. Are you
> > multiplying after you read or something?
> >
> >> know it has something to do with the idiv and mul instruction
but i
> >> can't seem to get it right Please help me! I'd like a response
> >> before friday. The calculations are as follows:
> >>
> >> Using VS = 6V
> >> I wanted to convert the output voltage of the op-amp to have a
range
> >> from 0 5V. In order to do this, I chose appropriate values for
Rf
> >> and R1.
> >> The formulae used are as follows:
> >> Vo = 1 + Rf / R1 x Vx
> >> AV = Rf / R1 + 1
> >
> > This sounds like a standard non-inverting op amp signal
conditioner.
> >
> >> Because I want the highest i.e 210oF, 2100mV was used since,
> >> according to the LM34 temperature sensor specifications, 300oF is
> >> equivalent to 3000mV.
> >>
> >> 5V = AV x 2100mV
> >> AV = 5V/2100mV = 2.38
> >>
> >> With the gain, I calculated the Rf and R1 to be 3kohm and 2.2kohm
> >> respectively.
> >
> > Ok, lessee. What accuracy resistors did you use? Anyway,
supposing you
> > use accurate resistors, your gain is 2.3636363... so 2.1V in gives
> > 4.964 volts out. You should get 254 out of the A/D converter,
which
> > is $FF, not $FFF as you stated.
> >
> >> Is it possible you can write the code for that for me. I don't
want
> >
> > Yes, it is possible. No, I will not do it. You paid good money
> > to go to school, and you should derive benefit from that. I will,
> > however, point out where you seem to be making mistakes, and help
> > you figure it out on your own.
> >
> > Besides, I'm sure your prof. is reading this.
> >
> > Where you are having difficulty seems to be conversion of the
> > internal number into an external numeral.
> >
> >> the remainder, just the integer part alone. I tried everything, i
> >
> > Obviously, you have not tried everything, because you haven't
> > tried what works. Thinking like this is going to lead to
defeatism.
> > There is something you haven't tried, you just need to figure
> > out what it is.
> >
> >> also have to use the formula in the code: Vx = Vlref + (range
*x) /
> >> (2 power n - 1)
> >>
> >> Here's the code:
> >>
> >> Project: To design a digital thermometer so that it can measure
> >> temperature
> >> * in the range from 0oF to 210oF
> >>
> >> org $7021
> >
> > I take it you have RAM here.
> >
> >> seven_segment rmb 4
> >> base equ $1000
> >> portb equ $04
> >> ddrd equ $09
> >> portd equ $08
> >> porte equ $0A
> >> option equ $39
> >> adctl equ $30
> >> adr2 equ $32
> >>
> >>
> >> F equ $F1 ; bit pattern to display
> >> ;the character degrees fahrenheit
> >
> > I don't understand the reason for this equate,
> > and the comment isn't adequate for me to figure
> > it out. Is this a "pretend sample" of 241? If so,
> > then it represents a voltage of 1.99V which you'd
> > get at a temperature of 199 degrees F. So, this
> > needs to be displayed as 199.
> >
> >> temp rmb 3
> >>
> >> org $F000
> >
> > I hope you have some RAM here, too.
> >
> >> lds #$FF
> >
> > Good idea to set up your stack.
> >
> >> ; to enable the seven_segment display
> >>
> >> start ldaa #$FF
> >> ldx #base
> >> staa ddrd,x
> >
> > Ok, so PORTA is being used as output. I hope this is
> > an F series chip, or the like. Some of those chips
> > have fixed direction port bits on PORTA.
> >
> > [snipped]
> >
> >> ; wait for ccf
> >>
> >> repeat ldaa adctl,x ; check the CCF bit
> >> bpl repeat ;wait until CCF is 1
> >> ldaa adr2,x ; get the first result
> >> anda #$0F
> >> staa temp ; save it
> >
> > Ok, low nybble.
> >
> >> ; display number in the second segment display
> >> jsr seven_segment
> >
> > Not going to work, even if the subroutine is
> > correct. You want a decimal numeral, not a
> > hexadecimal numeral.
> >
> >> staa portb,x
> >> ldaa #$F7
> >> staa portd,x
> >
> > What does this do?
> >
> >> jsr delaya
> >> ; get the result
> >> ldaa adr2,x
> >> lsra
> >> lsra
> >> lsra
> >> lsra
> >>
> >> anda #$0F
> >> staa temp +1
> >> ; display the result in the third seven segment
> >> jsr seven_segment
> >> staa portb,x
> >> ldaa #$EF
> >> staa portd,x
> >> jsr delaya
> >
> > I can't figure this code out. Anyway, I'm going
> > to guess that you are able to display three digits
> > using this code, but that you are getting hex numerals,
> > not decimal. So, I've snipped it.
> >
> > This code gives the appearance that it does a correct
> > conversion from an internal format integer to an external
> > format hexadecimal numeral. Consider what your code does
> > carefully. When you mask the low order bits, and retain
> > them, you are taking the remainder after division by 16.
> > Then, later in your code, you shift the value right by
> > four bits. This is the same as division by 16. This forms
> > the core to your system to convert numbers to numerals.
> >
> > If you want DECIMAL numerals, you must use remainders
> > after division by 10, not 16. FDIV divides fractional
> > fixed point numbers by integers. IDIV divides integral
> > fixed point numbers by integers. So, IDIV is the one you
> > want.
> >
> > That's the first problem you've got. The other one is
> > that you are displaying internal codes, not temperatures.
> > IOW, you have an internal value of 241. This should be
> > displayed as 199.
> >
> > So, here are the steps your code needs to perform.
> >
> > (1) Convert the internal code into a number representing
> > the actual temperature by rescaling.
> >
> > (2) convert the numerical temperature into an external
> > numeral by dividing by 10 repeatedly, and displaying
> > the remainders, using IDIV.
> >
> > For example, you need to display 199 = $C7. Divide
> > $C7 by $0A to get $13 as the quotient and remainder
> > of $09. Display a digit '9' as the least significant
> > digit. Then divide $13 by $0A to get a quotient of $01
> > and a remainder of 9. Display the digit '9' as the
> > next more significant digit. Then display the quotient
> > $01 (which is also the remainder after the next division)
> > as the most significant digit '1'.
> >
> > Now, how to rescale? You multiply your voltage by
> > 2.363636..., divide by 5.000V, then multiply by 256,
> > and round to the nearest integer. That's what we get
> > out of the A/D. We need to reverse this. So, we
> > divide by 256, multiply by 5, and divide by 2.3636...
> > This gives us the original voltage.
> >
> > But, we need to multiply this number by 100 in order
> > to get temperature, to account for the 10 mV/oF relation.
> > Net result: We need to multiply by 0.826322115...
> > That makes a reading of 241 from the A/D come out as 199.14
> > as we want, since it corresponds to 199 degrees F.
> >
> > So, how do we multiply by 0.826322115...? We can do this
> > with reasonable accuracy by multiplying by 212 and dividing
> > by 256, because 212/256 = 0.828125. The error is 0.2%, and
> > we've already committed greater error (0.5% roughly) by
> > A/D conversion.
> >
> > So, take your A/D result, multiply by 212, round off by
> > adding $0080 (1/2 of 256) and divide by 256 by using only the
> > upper 8 bits (in A). Then convert to decimal digits by
> > repeated division by 10 using IDIV and the remainders.
> > These are what you display.
> >
> > Mike
> > --
> > p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
> > Oppose globalization and One World Governments like the UN.
> > This message made from 100% recycled bits.
> > You have found the bank of Larn.
> > I can explain it for you, but I can't understand it for you.
> > I speak only for myself, and I am unanimous in that!
> >
> >----------
> > From: Chryssie
> > Thank You, this helped a great bit,TJ although it was a bit
confusing i got thru!!
--- Chryssie
> > Yahoo! Groups Links
> >
> >
>
Chryssie,

I'm pleased to hear it - but it wasn't my answer. ;).

D/A is a great deal more involved than A/D - or used to be - with custom silicon though it's fairly straightforward.

For microprocessor applications I would look at microchips application notes, they really are extremely imaginative over there, and can make software do all sorts of things that you'd think you needed special hardware for.

www.microchip.com

Converting from their micro's to 68HC11 shouldn't be too difficult, it's the method that's important.

I've seen them produce some fantastic results with a few resistors and a few output pins. :)

TJ

From: Chryssie
> > Thank You, this helped a great bit,TJ although it was a bit
confusing i got thru!!
--- Chryssie