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
ADC measurments - How To

 
Post new topic   Reply to topic    Forum Index -> General
Author Message
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 08 June 2010, 11:36 AM    Post subject: ADC measurments - How To Reply with quote

I am using a SparkFun Triple Axis Accelerometer Breakout - MMA7260Q:

www.sparkfun.com/commerce/product_info.php?products_id=252

with VCC = 3.3V
I am directing the output (X, Y, Z) to three pins on a ZX-24. How do I handle the computation of the actual acceleration in the software? The function form of GetADC says that the value returned is a function of Vref
which I assume is 5V. Can I multiply the return value by 0.660 (3.3/5) to properly scale it? Should I use the subroutine form and set the fullScale parameter to 3.3? What is the 'best' way to handle the conversion?

I am using the board as a tilt meter.

Any enlightenment will be appreciated.

Vi
Back to top
dkinzer
Site Admin


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

Posted: 08 June 2010, 13:16 PM    Post subject: Re: ADC measurments - How To Reply with quote

victorf wrote:
The function form of GetADC says that the value returned is a function of Vref which I assume is 5V. Can I multiply the return value by 0.660 (3.3/5) to properly scale it?
The value returned by the function form needs to be multiplied by the reference voltage (typically 5.0V) and divided by 1024 to arrive at the approximate voltage value. The fact that the accelerometer is operating at 3.3V is irrelevant for the purposes of this calculation but it may be relevant for the conversion to acceleration.
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 08 June 2010, 13:16 PM    Post subject: Reply with quote

Code:

function GetMEMS(byval RAW_ADC as integer, byval Sensitivity as single) as single
GetMEMS = (cSng(RAW_ADC) / 1024.0 ) * Vcc / Sensitivity
end function


That will give you g's.

Sensitivity in your case would depend on which range g you are using. but would be 0.74, 0.55, 0.277 or 0.185

you may want to take an offset from that, i.e the output when sensor is dead level.

hope that helps!

As a side note: i tend to run my zx at 3.3v when using 3.3v accels and gyros, so i dont loose any resolution. I know many will advise against using them at this voltage as its outside bounds, but if your purpose is non mission critical there shouldnt be any problem. I have hundreds of hours logged with zx24n at 3.3v with no issues.

Ben
Back to top
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 08 June 2010, 18:07 PM    Post subject: Reply with quote

Ben,

I am not sure I understand what your code is saying:
What is being referred to in the variable RAW_ADC; the value returned from GetADC? I am using 1.5g range. Is it correct to assume that your Vcc refers to 5V.

What am I missing from here? I'm thinking the the 7260 can never return a value greater that 3.3V.

Any further enlightenment will be appreciated

Vic
Back to top
dkinzer
Site Admin


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

Posted: 08 June 2010, 18:45 PM    Post subject: Reply with quote

victorf wrote:
What is being referred to in the variable RAW_ADC; the value returned from GetADC?
I believe so; that makes sense to me.

victorf wrote:
I'm thinking the the 7260 can never return a value greater that 3.3V.
While that is certainly true, it is irrelevant with respect to the value returned by GetADC(). The ADC conversion value always has units of Vref/1024 and that doesn't change just because the range of the measured value happens to be less than Vref. Since you're using a ZX-24, we're assuming that Vref is 5.0 volts.

The situation is really no different that if you had a potentiometer connected to 3.3V and ground and were feeding the wiper signal to an ADC input. The highest value that could possibly ever be returned when using a 5 volt reference is 1024 / 5.0 * 3.3 = 675. Essentially, you're wasting about a third of the dynamic range of the ADC. You could use the full range, and get finer resolution, if you used a 3.3V reference for the ADC. Unfortunately, the Vref pin is not accessible on the 24-pin ZX devices so you're stuck with the ADC reference of Vcc of the ZX (usually 5.0 volts).
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 08 June 2010, 19:14 PM    Post subject: Reply with quote

Heres some full code that should work for you

Code:


PUBLIC CONST Vcc as Single = 5.0
PUBLIC CONST PIN_accelY as Byte = 13
PUBLIC CONST accelSensitivity as Single = 0.74
PUBLIC accelY_g as Single

Sub Main()

do

accelY_g = GetMEMS(GetADC(PIN_accelY), accelSensitivity)
debug.print accelY_g

Call Sleep(0.1)
loop

End Sub


function GetMEMS(byval RAW_ADC as integer, byval Sensitivity as single) as single
GetMEMS = (cSng(RAW_ADC) / 1024.0) * Vcc / Sensitivity
end function



Now, if you were running at 5.0v and your accel sensor was 5.0v the above code would output the g's

All you need to do then is scale for you 3.3 vs 5.0 and possibly get rid of the offset.

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