Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
PutDAC accuracy

 
Post new topic   Reply to topic    Forum Index -> ZX-1281
Author Message
pjc30943



Joined: 02 Dec 2005
Posts: 220

Posted: 28 September 2007, 21:19 PM    Post subject: PutDAC accuracy Reply with quote

Anyone able to obtain relatively accurate voltages using putDAC?

On the 1281ae, accuracy degrades (and is lower than commanded) as the commanded voltage nears 5V--indicating that the caps can't charge.
There are no other tasks running.

At a 0.8 (4V) desired output, for example, I get 3.7V. With 0.5 (2.5V) I get 2.37V. This obviously is a very large deviation.
At 0.2 (1V) it is okay.

I have 1uF and 220 Ohms, leading to a x2 multiplier for a 0..10V range--thus a proper buffer exists. I'm measuring with a nice Fluke directly after the filter, so the meter is high impedance as well.

Taking down to the purest level, even the following snippet in Main() is not accurate:

Code:


public DACacc as single
DACVout = 0.5
do
  putDAC DACpin, DACVout, DACacc, 10
  sleep 0.0
loop


10 PWM outputs should be way more than enough, and the (almost) fastest refresh means it should be stable.

Anyone have thoughts on what I might be doing wrong?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 28 September 2007, 22:34 PM    Post subject: Re: PutDAC accuracy Reply with quote

pjc30943 wrote:
Anyone able to obtain relatively accurate voltages using putDAC?
We use test code similar to the code below. My recollection is that we see voltages within a few tenths of a volt of the intended output as measured with a DVM with no other load.

The code cycles through a series of output voltages (0, 1.25, 2.5, 3.75 and 5.0), changing to the next output when a character is received on Com1.

Code:
' This module tests DacPin() and PutDac().  Connect a 1K
' resistor from the output pin to a 4.7uF cap to ground.
' Measure the voltage at the R-C junction.

#if Option.TargetDevice = "ZX128e"
Private Const pin as Byte = 36
#elseif Option.TargetDevice = "ZX1281" Or Option.TargetDevice = "ZX1280"
Private Const pin as Byte = E.6
#else
Private Const pin as Byte = 14
#endif
Dim data as ByteVectorData({0, 63, 127, 192, 255})

'#define USE_PUTDAC

Sub Main()
   Dim idx as Byte, lastIdx as Byte
   Dim acc as Byte
   idx = 255
   lastIdx = 255
   Do
      ' see if a character has been received, move to the next voltage if so
      If (GetQueueCount(CByteArray(Register.RxQueue)) > 0) Then
         Dim b as Byte
         Call GetQueue(CByteArray(Register.RxQueue), b, 1)
         idx = idx + 1
      End If
      If (idx > CByte(UBound(data))) Then
         idx = 1
      End If

      ' if the index has changed, display the new output voltage
      If (idx <> lastIdx) Then
         Debug.Print "idx = "; CStr(idx); ", Output = "; Fmt(CSng(data(idx)) * 5.0 / 255.0, 1)
         lastIdx = idx
      End If

      ' generate the pseudo-PWM signal
#ifdef USE_PUTDAC
      Call PutDac(pin, data(idx), acc, 3)
#else
      Call DacPin(pin, data(idx), acc)
#endif

      Call Delay(0.01)
   Loop
End Sub
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 29 September 2007, 1:46 AM    Post subject: Reply with quote

I performed some measurements with Don's testcase using a 1K resistor and 4.7uF cap. I tried both on a ZX-24 and a ZX-128e with similar results.

You need some kind of high impedance buffer to get the correct output voltage because any load will reduce the expected output voltage.


Last edited by mikep on 05 October 2007, 6:05 AM; edited 1 time in total
Back to top
pjc30943



Joined: 02 Dec 2005
Posts: 220

Posted: 30 September 2007, 22:35 PM    Post subject: Reply with quote

Thanks Mike and Don.

Too bad--apparently a separate DAC is in order for this app.
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 01 October 2007, 2:16 AM    Post subject: Reply with quote

PutDAC is a poor man's solution and relies on pumping out sufficient pulses to provide an average voltage over time.

A PWM channel can achieve the same result without constant monitoring by the ZBasic application.

If you have 4 or 8 I/O bits free then a R-2R ladder can be used. An I2C "port expander" may be useful here if you don't have enough I/O pins.

Last but not least a separate DAC may be the best overall solution.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 03 October 2007, 11:32 AM    Post subject: Reply with quote

I think we discussed it here before, but....

One can use an ADC pin on the output to sample the DAC voltage and adjust the parameters to get the desired voltage.

Also, if you need really fast response, you could develop a table of settings for the DAC, that get changed rapidly as the output cap initially charges. Essentially you drive the DAC at a high voltage setting briefly, then progressively decrease the setting as the cap charges. Maybe only 2 or 3 changes need to be made....

Also, you might develop a table of setttings that give a more accurate output voltage in the steady state. These exact settings will depend on the circuitry hooked to the DAC output.

-Tony
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 04 October 2007, 0:25 AM    Post subject: Re: PutDAC accuracy Reply with quote

pjc30943 wrote:
Anyone able to obtain relatively accurate voltages using putDAC?

I re-ran the test on a ZX-24 using a 1K resistor and 4.7uF cap. With Vcc at 5.03 volts, the result using PutDAC() with a count of 3 and using DACPin() was as shown in the table below. The voltage was measured at the R/C junction using a DVM with no other load. These results are similar to results that we've obtained over various VM versions.
TargetPutDAC, count=3DACPin
0.000.010.1
1.251.231.24
2.52.492.50
3.753.743.76
5.04.974.99

Even with these results, this method of generating an analog voltage suffers from the obvious limitation of requiring frequent service by the processor. Using the hardware-based PWM functions is a better option although that does require using certain pins. Beyond that, using a dedicated DAC chip, R-2R ladder or other mechanism might be considered. I've used the LTC1451 12-bit serial-input DAC with good results.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 04 October 2007, 21:27 PM    Post subject: Reply with quote

Just to be clear, I've attached an image of a schematic showing the proper R-C configuration to use for filtering the DAC output. This is a common low pass filter configuration.


dac.jpg
 Description:
 Filesize:  9.32 KB
 Viewed:  6214 Time(s)

dac.jpg


Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 05 October 2007, 6:00 AM    Post subject: Re: PutDAC accuracy Reply with quote

dkinzer wrote:
I re-ran the test on a ZX-24 using a 1K resistor and 4.7uF cap. With Vcc at 5.03 volts, the result using PutDAC() with a count of 3 and using DACPin() was as shown in the table below. The voltage was measured at the R/C junction using a DVM with no other load. These results are similar to results that we've obtained over various VM versions.

I can now reproduce your results. I left a ULN2803 load on the output pin. I guess no load means NO LOAD.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 05 October 2007, 14:38 PM    Post subject: Re: PutDAC accuracy Reply with quote

mikep wrote:
I can now reproduce your results.
Thanks for confirming the result.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 05 October 2007, 23:58 PM    Post subject: Re: PutDAC accuracy Reply with quote

mikep wrote:
I can now reproduce your results. I left a ULN2803 load on the output pin. I guess no load means NO LOAD.
Hmmm, if the output is that dependent on load, then it might be necessary to have a voltage follower op-amp for many DAC purposes.

And/Or feedback to ADC might be helpful.

-Tony
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 06 October 2007, 1:01 AM    Post subject: Re: PutDAC accuracy Reply with quote

spamiam wrote:
[I]f the output is that dependent on load, then it might be necessary to have a voltage follower op-amp for many DAC purposes.
You are correct. The filter capacitor is charged during the generation process to the average voltage of the pulse stream (q = C * V). Any current drawn from the capacitor will necessarily drain off charge from the capacitor's plates resulting in a lower voltage.

When the PutDAC() routine is not being executed, the voltage on the capacitor will decay depending on the load (including the internal leakage of the capacitor). The lower the load, the longer the period can be between PutDAC() calls while maintaining the voltage within a given range.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-1281 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group