DAC implementation

MD_Micro

New Member
I'm new to PICAXE. I'm looking for an implentaion to drive (2) 0-10VDC signals with a PICAXE.

8 bit resolution is good enough or possibly using an integrator with a PWM output and maybe PID back to one of the ADC inputs to trim it.

I'm sure the final output will have to be buffered and amplified.

Any suggestions?
 

BeanieBots

Moderator
The 28X supports two 10-bit background PWM signals.
Being logic levels, naturally, the voltage is close to whatever your PICAXE power supply is. Therefore, after integration, (or just simple RC), you will require further amplification to get 10v.

The resultant DC level after RC filtering of the PWM signal follows the duty cycle very well. You should not require any feedback to the PICAXE. Besides, the thing most likely to cause any discrepancy would be the power supply. The PICAXE ADC uses the power supply as it's reference so it would actually be very complex to use such feedback requiring a good reference voltage and several op-amps.

 

Jeremy Leach

Senior Member
Here's a little idea that doesn't need an amplifier:

<code><pre><font size=2 face='Courier'>
o-------------o 10V
|
.-.
o---------o5V | |R2
| |
'-'
___ |
In/Out ---&gt;--|___|--o---o-&gt; DC level
|
|
|
---
---
|
o----------------o-------------o
</font></pre></code>

It's using a Picaxe08M where the pin is configured either as an input or output.

When the pin is an input it's high impedence letting the cap charge to 10V. When it's an output and set 'low' it discharges the cap towards 0V.

So could have code that toggles the state of the pin, and maybe a feedback loop to read into an ADC (via a potential divider).

Edited by - jeremy leach on 11/01/2007 17:08:33
 

Dippy

Moderator
I dunno what value Rs you're considering there Jezzer but I wouldn't feel happy with that circuit. You could have &gt;&gt;5V on a pin, and I can't see it giving anywhere near 0-10V anyway.

Crude method would be, as suggested, pwm / smooth then level shift with op-amp + dual V supply (ie 5 &amp; 12 for headroom).
Or, better (though greater fiddleification) would be a genuine DAC ic.
 

piclt

Member
Are you limited to using only the picaxe, you could use a digital potentiometer controlled by serial pin or with 2 pins, one for up and other for down, and put 10 volt across the pot.
or,
you could use a doubler circuit using 2 diodes and 2 capacitor (clamping) and pulse out at a rate to keep the voltage up as required. Use feedback to control it

o----------+----------------------0 5 volt
|
|
_|__
\ / D1
\/ D2
Pin ===|=== |\ |
0---| |----+------| \|---+-----0 O/p
- C1 + |/ | |
|
------ +
C2 ------ -
|
|
|
-------+-------- Zero


PS I cannot draw the diagram, It looks OK in the editing window ????

Edited by - piclt on 11/01/2007 21:36:06
 

Jeremy Leach

Senior Member
Think of my circuit like this then ...

<code><pre><font size=2 face='Courier'>

o-------------o 10V
|
.-.
o---------o5V | |R2
| |
'-'
___ |
o---|___|--o---o-&gt; DC level
| |
\ o |
\ |
\. ---
o ---
| |
o-----o----------o-------------o
</font></pre></code>

The switch is either ground (Picaxe pin configured an output with the pin set 'low') or open circuit (Picaxe pin configured as an input).

If you alternate between these two states in code, you can change the capacitor voltage between 0 and 10V depending on the ratio of 'on' to 'off' ....ie Duty.

And the internal clamping diodes would stop the input going above 5V.

...oh sugar...they'd stop the capacitor voltage going to 10V too ....oh well, perhaps scrap this idea then !

Edited by - Jeremy Leach on 11/01/2007 21:42:44
 

BeanieBots

Moderator
Never mind Jeremy. It was a nice idea while it lasted. As you spotted, would never go much above 5v and probably would be a volt or two shy of 0v as well. Not too mention the code which would need to tri-state, drive high and drive low all in a time controlled manner.

I like piclt's idea of using a 'standard' voltage doubler. It would have a few diode drop issues that would prevent 8-bit accuracy without calibration and/or lookup curve but a cheap and simple solution.
 

premelec

Senior Member
Rather than fooling around with PWM i'd use a TLC5620 4 x 8 bit D/A with serial input and the multiply by 2 to a up amplifier with a 10+ volt supply... I've used PICAXE 08M to generate the serial code to set the TLC5620 [or TLC5628 for 8 x 8 bit D/A]. Then you can set the conversion and forget it rather than continuously udating PWM...
 

MD_Micro

New Member
Thanks for all of your input.

I've ordered a 28X starter kit. I'll probably go with BeanieBots suggestion since I have multiple voltage sources available in my application.
 

Jeremy Leach

Senior Member
Here's PicLit's suggestion (you just enclose the diag in 'code' ..see protocol tab):
<code><pre><font size=2 face='Courier'>
o----------+----------------------0 5 volt
|
|
_|__
\ / D1
\/ D2
Pin ===|=== |\ |
0---| |----+------| \|---+-----0 O/p
- C1 + |/ | |
|
------ +
C2 ------ -
|
|
|
-------+-------- Zero
</font></pre></code>

Apart from needing some current limiting resistors and a discharge resistor for C2, I don't think this will work anyway unfortunately, because D1 and D2 are always keeping C2 charged to at least 5V.

You could use another output instead of the +5V rail and take this low when &lt;5V output required, but it all gets messy.

Unless I've missed something....
 

BeanieBots

Moderator
Well spotted Jeremy. It won't work to generate the 0-10v.
It's just a voltage doubler. A 5v square wave at the input will generate 10v DC at the output cap.
 

moxhamj

New Member
I wonder if there is an 08M solution to this?

Consider a low pass RC network. If the picaxe sends a 1 into this the cap charges up and if a 0 is sent the cap discharges. But pin1 and 2 can also be adc inputs. So charge up the cap a bit, then test the voltage using the same pin, then charge or discharge as necessary.

To get the 10V add a couple of op amps. With a 12V supply to a 324 it will swing 1.25 to 10.75V. A 3140 or similar will go rail to rail.

I'm thinking that an 08M and a 324 is going to be cheaper than a 28X...
 

BeanieBots

Moderator
Interesting idea Dr_Acula.
I'm sure it would work and quite well.
Only issue I can see would be response time but that could be made reasonable by adjusting the charge/discharge time as a function of measured error.

With an 08, there is the PWM command (as apposed to the background PWMout command). PWM (which tri-states at the end of the frame) can be fed into a large cap and buffered with op-amps in a similar manner.
This would give close to 8-bit accuracy without the need for feedback assuming a stable power supply.
 

Jeremy Leach

Senior Member
I think Dippy's suggestion is good - although I think you could get away with just one transistor, and I don't think we need feedback:

<code><pre><font size=2 face='Courier'>


+10V ----------o---------
|
'-'
| | R1
| |
'-'
|
o------.
| |
| '-'
T1 | | | R2
PWM in ______|/ | |
(0 to 5V) |\ '-'
&gt; |
| o------ 'DC' Out (0 to 10V)
| |
| ----- C
| -----
| |
| |
GND ----------o------o-----

</font></pre></code>

When transistor is 'on' C discharges through R2
When transistor is 'off' C charges through R1 and R2.

So would need to account for the uneven charge/discharge rates.

According to my maths, to get equal charge/discharge for the 'on' and 'off states (giving 5V output), requires:
Pon/R1 = Poff/(R1 + R2) where Pon is the 'on' period and Poff (!) the off period.

So if R1 = R2, the 'on' period needs to be half the off period, ie a duty of 33%.


The maths is hurting my head to get the relationship between DC out voltage and Duty ....perhaps someone else can work it out ! although probably best just to graph it by experimentation and hopefully there will be a nice straight line somewhere ;-)

Perhaps push-pull would be better to make it all linear....

Edited by - Jeremy Leach on 12/01/2007 13:24:53
 

BeanieBots

Moderator
You mean something like a full H-bridge (L293D maybe) driven from 10v supply?
Should work, give or take the odd tranny/diode loss.
I think the maths for your single tranny version would be too horrific but I might be wrong.
 

wilf_nv

Senior Member
This is an adaptation of an earlier 0-5V circuit discussed in the thread &quot;Driving low impedance with pwmout&quot;

Since the circuit acts like an analog memory it requires a low refresh rate.

<A href='http://www.user.dccnet.com/wrigter/picaxe/d2a.gif' Target=_Blank>External Web Link</a>

<code><pre><font size=2 face='Courier'>
;1 ch 0-10V D/A routine for 08M - Jan 2007 - wilf rigter
;http://www.user.dccnet.com/wrigter/picaxe/d2a.gif


symbol Vadjust=w1 ;required output
symbol Vout=w2
symbol loop_counter=w3

setfreq m8 ;double clock speed

main:

;-------
;-------
Vadjust = Vadjust min 3 max 4092
gosub D2A
;-------
;-------
goto main



D2A:

adjust:
readadc10 1,Vout ;read output voltage (Vout)

if Vadjust&lt;Vout then decrease
if Vadjust&gt;Vout then increase
return


decrease:
high 2 ;set pin2 high to decrease Vout
input 2 ;tri-state pin2 and hold Vout
next loop_counter



increase:
low 2 ;set pin2 high to decrease Vout
input 2 ;tri-state pin2 and hold Vout
next loop_counter
</font></pre></code>



Vout of 0-10V with 10 bit resolution is expressed as binary 0-1023.

The code shown limits the min and max value of Vadjust to 3 and 1020 (nearly 0-10V) to match the actual value of Vout that can be achieved with a 10V single ended supply.

The D2A subroutine may require an escape route to avoid lock up if Vout cannot be made equal to Vadjust.



Edited by - wilf_nv on 13/01/2007 05:03:43
 
Top