|
|
| Author |
Message |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 07 December 2005, 16:50 PM Post subject: |
|
|
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 |
|
|
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: |
|
|
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 |
|
 |
|