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
Differential ADC

 
Post new topic   Reply to topic    Forum Index -> Files
Author Message
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 12 December 2007, 3:44 AM    Post subject: Differential ADC Reply with quote

Here is a little program demonstrating how to do differential ADC. It was written for the ZX24, but the technique is good for all processors

-Tony



Test_diff_adc.zip
 Description:

Download
 Filename:  Test_diff_adc.zip
 Filesize:  2.77 KB
 Downloaded:  3084 Time(s)

Back to top
dkinzer
Site Admin


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

Posted: 13 December 2007, 4:46 AM    Post subject: Reply with quote

In differential mode, it is convenient to use the ADLAR bit to force the result into bits 15-6. The advantage of doing this is that the result can be directly used as a 16-bit signed value. Obviously, an adjustment needs to be made in the ADC-to-voltage conversion equation to compensate for the fact that the value is 64 times what it should be.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 13 December 2007, 13:43 PM    Post subject: Reply with quote

dkinzer wrote:
In differential mode, it is convenient to use the ADLAR bit to force the result into bits 15-6. The advantage of doing this is that the result can be directly used as a 16-bit signed value. Obviously, an adjustment needs to be made in the ADC-to-voltage conversion equation to compensate for the fact that the value is 64 times what it should be.


Good point. I was wondering about doing something with the ADLAR bit. It is an easy mod to make. I had to do a little extra math to check if the value is greater than 511, then subtract 1024 from the value to get the correct signed value.

The problem with having a result that is 64 times larger is that some people might think that there is 64 times greater resolution!

I suppose it would be simple enough to right shift the ADC reading by 6 bits to restore the correct magnitude. (Right shifting will preserve the sign of a signed integer, right?) I am reasonably sure that always doing a quick right shift will be faster than deciding when to sometimes subtract 1024.

Code:
dim ADC_Reading as Integer

'NOTE: ADLAR bit is set

ADC_Reading = ShR(CInt(Register.ADC) ,6)


I will make this modification to the code and post a new version. Thanks for the input!

-Tony
Back to top
dkinzer
Site Admin


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

Posted: 13 December 2007, 14:31 PM    Post subject: Reply with quote

spamiam wrote:
I am reasonably sure that always doing a quick right shift will be faster than deciding when to sometimes subtract 1024.
If the value will ultimately be converted to some other units (e.g. voltage, pressure, etc.) the scaling can be combined into that conversion, often at no additional cost since those conversions generally involve multiplication and division anyway.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 13 December 2007, 16:30 PM    Post subject: Reply with quote

dkinzer wrote:
If the value will ultimately be converted to some other units (e.g. voltage, pressure, etc.) the scaling can be combined into that conversion, often at no additional cost since those conversions generally involve multiplication and division anyway.


Right. But for the little demo program, I wanted it to be as general-purpose as possible. I was thnking that some users might transplant the code directly into their progran as-is, then further translate the data as needed.

-Tony
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> Files 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