Forum Index
ADC 0-7 inaccessible?

 
Author Message
pjc30943



Joined: 02 Dec 2005

Posted: 14 July 2008, 22:31 PM    Post subject: ADC 0-7 inaccessible?

I'm unable to access ADC0-7.
On the surface it appears that for a 1280n device, using an ADC lower than ADC8 causes some sort of wrap-around, where only port K is used at all times.

As an example, if I read the ADC of F.0 (ADC0), it is the pin K.0 whos value is returned. Voltages applied to F.0 have no effect on the reading.

Do all the ADCs need to be enabled in any special way in native-mode devices?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 14 July 2008, 23:35 PM    Post subject: Re: ADC 0-7 inaccessible?

pjc30943 wrote:
Do all the ADCs need to be enabled in any special way in native-mode devices?
No, just refer to the pin numbers as usual.

Here is some test code that I used:
Code:
Dim f1 as Single, f2 as Single
Sub Main()
#if 1
  Debug.Print GetADC(F.0)
  Debug.Print GetADC(K.0)
#else
  Call GetADC(F.0, f1)
  Call GetADC(K.0, f2)
  Debug.Print Fmt(f1 * 1023.0, 0)
  Debug.Print Fmt(f2 * 1023.0, 0)
#endif
End Sub

With F.0 connected to ground and K.0 connected through a resistor to +5, the output is 0 and 1023 as expected. If you change the #if 1 to #if 0 (to use the form returning a Single value) the result is 0 and 1022.

Do you get something different there? If so, what version of the ZX Library are you using? It is reported in the sign-on message or you can get it from the SerialNumber() call.
Back to top
pjc30943



Joined: 02 Dec 2005

Posted: 15 July 2008, 0:04 AM    Post subject:

SerialNumber() result: 246, 2, 5

I define

Code:
public const ADC0input   as byte = F.0


and then call

Code:
getADC ADC0input, result


Test voltages are inputted to pin1 of J6 (F.0, ADC 0) on the 1280n dev board.
When I apply voltages to pin 1 of J11 (K.0, ADC 8 ), the voltages are displayed as though I had defined ADC0input to be K.0

Or, when doing
Code:
getADC ADC0input(90)
, which should be port F per the docs (pg.91 in system library), I see voltages that are applied to K.1 instead.


EDIT:
Code:
getadc(F.n)

with n=0..7 and the intent of reading voltages on J6, returns the corresponding voltages placed onto K.n, J11.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 15 July 2008, 0:52 AM    Post subject:

pjc30943 wrote:
SerialNumber() result: 246, 2, 5
The second two numbers look like they are part of v2.5.x. The 246 looks completely out of place. If you haven't turned off the sign-on message it should appear immediately after each reset.

There is something going on that I don't yet understand. What is the output of the test program that I proposed with F.0 grounded and K.0 tied high? Alternately, can you provide a complete program that demonstrates the incorrect voltages being read with a similar setup that I can duplicate here?
Back to top
pjc30943



Joined: 02 Dec 2005

Posted: 15 July 2008, 18:02 PM    Post subject:

The signon has v2.5.2

I ran the program you asked, and it does indeed give the results you found.
I'm not sure why it works there, but not in the other program; I'll look into it further.

EDIT: How come debug.print does not require cstr(getADC(...)), but only getADC?
Back to top
pjc30943



Joined: 02 Dec 2005

Posted: 15 July 2008, 18:23 PM    Post subject:

The code you had works once; if it's in a loop, it seems to no longer function. Consecutive calls yield readings from only K.0:

Code:

0
1023

1023
1023

1023
1023
...


and

Code:

0
1022

1022
1022

1022
1022
...



It's possible that I'm still doing something silly...
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 15 July 2008, 21:23 PM    Post subject:

pjc30943 wrote:
How come debug.print does not require cstr(getADC(...)), but only getADC?
Automatic value-to-string conversion for Debug.Print and the string concatenation operator (&) was added in v2.4.1. This item has been listed in the compiler change history since the release of that version. The automatic conversion is also mentioned in the description of Debug.Print.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 15 July 2008, 21:34 PM    Post subject:

pjc30943 wrote:
Consecutive calls yield readings from only K.0
Right you are. The same effect can be shown by reversing the order of the two GetADC() calls in my original example.

I've tracked down the source of the problem and I know how to fix it. You can work around the problem by adding the line of code below just before each GetADC() call or, if you prefer, after each GetADC() call that uses ADC channels 9-15.
Code:
  Register.ADCSRB = 0
Back to top
pjc30943



Joined: 02 Dec 2005

Posted: 15 July 2008, 21:49 PM    Post subject:

Thanks Don. I'll use your prelim fix.
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008 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