Discussion forum for the BasicX family of microcontroller chips.
|
The BasicX System Library manual says that in order to use GetADC() you needn't configure the pin as an input. I did a quick experiment to verify that and the evidence suggests that the statement is untrue. With nothing connected to pin 20, I first ran this code: Call PutPin(20, bxOutputLow) i = GetADC(20) The variable 'i' had the value of 0. Then I ran this code: Call PutPin(20, bxOutputHigh) i = GetADC(20) This time 'i' had the value 1023. Next, I ran this code: Call PutPin(20, bxInputTristate) i = GetADC(20) The result varied over several iterations from around 200 to 500 or so suggesting that the input was indeed floating. Lastly I ran this code: Call PutPin(20, bxInputPullup) i = GetADC(20) In this case, 'i' always had the value 1023. My conclusion from this test is that you should always set the pin to Hi-Z input state before calling GetADC(). |
|
|
|
Did you have a sensor circuit attached to the pin? I've never declared the pin an input, and getADC() has always worked for me. On Jul 5, 2004, at 4:03 PM, Don Kinzer wrote: > The BasicX System Library manual says that in order to use GetADC() > you needn't configure the pin as an input. I did a quick experiment > to verify that and the evidence suggests that the statement is untrue. > > With nothing connected to pin 20, I first ran this code: > > Call PutPin(20, bxOutputLow) > i = GetADC(20) > > The variable 'i' had the value of 0. Then I ran this code: > > Call PutPin(20, bxOutputHigh) > i = GetADC(20) > > This time 'i' had the value 1023. Next, I ran this code: > > Call PutPin(20, bxInputTristate) > i = GetADC(20) > > The result varied over several iterations from around 200 to 500 or > so suggesting that the input was indeed floating. Lastly I ran this > code: > > Call PutPin(20, bxInputPullup) > i = GetADC(20) > > In this case, 'i' always had the value 1023. > > My conclusion from this test is that you should always set the pin to > Hi-Z input state before calling GetADC(). > > Yahoo! Groups Links > -- Tom Igoe |
|
|
|
Actually, a better terminology for GetADC would be: you needn't configure the pin as an input, unless it was configured otherwise. The default setting for the pin are (bxInputTristate) for pin 5-20 ,two LEDs, and OutputCapture "pins". Likely for the safety of the BX24... Unless, of course you change that in your program or download settings. I found another interesting note: For the "Select Case" statement, the program branches at the first matching expression - Language Reference page 15. The same occurs for "If Then" statements. For example: If A=1 Then B=1 ElseIf A<3 Then B=2 ElseIf A>2 Then B=3 End If Would give the following results: A=1 B=1 'Note that second statement is also true A=2 B=2 A=3 B=3 I am not sure if this is general knowledge, but it was new to me and saved me a headache. So I pass it along. Thad --- Tom Igoe <> wrote: > Did you have a sensor circuit attached to the pin? > I've never declared > the pin an input, and getADC() has always worked for > me. > On Jul 5, 2004, at 4:03 PM, Don Kinzer wrote: > > > The BasicX System Library manual says that in > order to use GetADC() > > you needn't configure the pin as an input. I did > a quick experiment > > to verify that and the evidence suggests that the > statement is untrue. > > > > With nothing connected to pin 20, I first ran this > code: > > > > Call PutPin(20, bxOutputLow) > > i = GetADC(20) > > > > The variable 'i' had the value of 0. Then I ran > this code: > > > > Call PutPin(20, bxOutputHigh) > > i = GetADC(20) > > > > This time 'i' had the value 1023. Next, I ran > this code: > > > > Call PutPin(20, bxInputTristate) > > i = GetADC(20) > > > > The result varied over several iterations from > around 200 to 500 or > > so suggesting that the input was indeed floating. > Lastly I ran this > > code: > > > > Call PutPin(20, bxInputPullup) > > i = GetADC(20) > > > > In this case, 'i' always had the value 1023. > > > > My conclusion from this test is that you should > always set the pin to > > Hi-Z input state before calling GetADC(). > > > > > > > > > > > > > > Yahoo! Groups Links > > > > > > > > > > > > > -- > Tom Igoe __________________________________ |
|
|
|
--- In , Thad Larson <highwayman_33402@y...> wrote: > > I found another interesting note: > For the "Select Case" statement, the program branches > at the first matching expression - Language Reference > page 15. Another interesting aspect of Select Case is that it allows the same case value to be specified multiple times. In this situation, the code related to the second and subsequent duplicate case labels can never be executed. Also, it is allowable to use an expression as the value of a case label, e.g. Select Case i Case j+3 ... code End Select In this circumstance, the case expression is evaluated each time that the case is analyzed. |