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
AD Converter

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
dkinzer
Site Admin


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

Posted: 07 December 2005, 16:50 PM    Post subject: Reply with quote

The standard routine, GetADC(), performs single-ended conversions. The mega32 chip is capable of doing differential conversions and you can implement them by direct programming. The code below shows how this can be done using ADC1 and ADC0 as the differential inputs with a 1x gain factor. You should be able to modify it to meet your needs but you'll have to read the mega32 datasheet to get the information about the register values. Look at pp. 199-216.

If you have questions about the code, please ask.

Code:
Public Sub Main()
   Do
      Debug.Print CStr(readADC())
      Call Delay(0.5)
   Loop
End Sub

Private Function readADC() As Integer
   Dim lowByte as Byte, highByte as Byte

   ' select ADC0/ADC1 as the positive/negative inputs, gain = 1
   Register.ADMUX = &H50

   ' Start the conversion using the 128x prescaler.
   ' Note that bit 4 is also written as a 1 to reset the ADIF bit.
   Register.ADCSRA = &HD7

   ' wait for the conversion to complete
   Do Until (CBool(Register.ADCSRA And &H10))
   Loop
   
   ' read the ADC value
   lowByte = Register.ADCL
   highByte = Register.ADCH

   ' turn off the ADC
   Register.ADCSRA = &H00

   ' perform sign-extension of the high byte value
   If (CBool(highByte And &H02)) Then
      highByte = highByte Or &HFC
   End If

   ' combine the low and high bytes
   readADC = CInt(MakeWord(lowByte, highByte))
End Function
Back to top
kensmith



Joined: 11 Dec 2005
Posts: 2

Posted: 12 December 2005, 15:21 PM    Post subject: AD Converter Reply with quote

Are there a command to make Differential voltage measurements on the X24.
I have used the Basic 2 for this using an external converter.
The Basic X has no means of doing this either.
I design electronic equipment and use a resistor to measure the current that goes to the Lna.

Thanks
Ken Smith
Back to top
kensmith



Joined: 11 Dec 2005
Posts: 2

Posted: 13 December 2005, 16:59 PM    Post subject: Reply with quote

Thanks Don
I downloaded the data sheet and it looks pretty simple.
I gues now I will have to order a couple of them to try out in
my next design.

Ken Smith
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language 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