View unanswered posts | View active topics It is currently Fri Oct 24, 2014 5:22 pm






Reply to topic  [ 11 posts ] 
Bug? Analog port SensorValue returns 15 for lowest value 
Author Message
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Bug? Analog port SensorValue returns 15 for lowest value
Using analog pin A0 to read in value from a potentiometer. Value range returned was 15 - 1023 not 0 - 1023.

Thought Pot was bad so grounded the line going into A0. Still 15.

Checked with multimeter on the Pot and it returned 0 - 5 volts.

Thought my code was whacked so used RobotC sample code "Read Analog Input.c" and range is still 15 - 1023.

Changed to pin A1 and still 15 - 1023.

Then I ran sample using analogRead() using Arduino IDE and it returns 0 - 1023.

Here's the RobotC code (it's just the sample)

Code:
#pragma config(CircuitBoardType, typeCktBoardUNO)
#pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0)
#pragma config(Sensor, anlg0,  ,               sensorPotentiometer)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main(){
  int sensorRead=0;

  while(true){
    sensorRead = SensorValue[anlg0];
    wait1Msec(20);
  }
}


Wed May 16, 2012 10:11 am
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
It could be that the internal pullup is enabled for that IO pin, and/or that the POT wiper isn't going all the way to GND. Try disabling the pullup and/or jumping the analog input to GND to see if you get a lower number.

_________________
Matt


Wed May 16, 2012 1:27 pm
Profile WWW
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
mattallen37 wrote:
It could be that the internal pullup is enabled for that IO pin, and/or that the POT wiper isn't going all the way to GND. Try disabling the pullup and/or jumping the analog input to GND to see if you get a lower number.


Matt, in my post I said the POT was ok. I hooked it up to a multimeter and it went from 0 - 5v. I also stated that I grounded out A0 and the sensor value still returned a value of 15.

If the internal pull up was enabled I would always see a sensor value of 1023 (5V). You stated I should disable the pullup but in RobotC that would be setting the sensor type to "Digital High Impedance" but that only works for digital ports and I am working with an analog port (I know Arduino analogs pins can be digital A14-A19 but that isn't supported yet in RobotC).

Without changing the wiring or anything I loaded the Arduino IDE 1.0 version of the same code and it returns 0 - 1023 as expected.

I also tried ports A0, A1 and A5. All return 15 when grounded.


Wed May 16, 2012 2:27 pm
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
Did you try taking the voltage up slightly (from 0v)? What happens at the normal level it would read 15 (based on 5v reference and a 10-bit ADC, that would be 0.0732421875v)? And what about at twice that voltage?

_________________
Matt


Wed May 16, 2012 4:17 pm
Profile WWW
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
mattallen37 wrote:
Did you try taking the voltage up slightly (from 0v)? What happens at the normal level it would read 15 (based on 5v reference and a 10-bit ADC, that would be 0.0732421875v)? And what about at twice that voltage?


Yes I took it up slightly and the sensor value did go up slightly but I didn't bother to start mapping voltage output to the sensor value.

I am wondering has anyone been reading analog pins? Are they reading properly? Will connecting the analog pin to ground produce a 0 sensor value?

I did try both the old and the newly posted firmware.

As I said earlier I did ran the following Arduino code with exact same hardware and it works perfectly. I get 0-1023 for my sensor value off A0:

Code:
int sensorPin = A0;   
int sensorValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(sensorPin);   
  Serial.println(sensorValue);
  delay(1000);
}


Wed May 16, 2012 5:41 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
I tried this, and the same is happening with me. 15-1023 on RobotC, 0-1023 on Arduino software. I'm not using a analouge sensor, per se, but a button, which should take it to both extremes, right? Anyway, I'm seeing exactly what your seeing, Dennis.

And now I've tried it with a phototransistor and confirmed it again: RobotC goes no lower than 15 (actually, I think I might've seen 14 flash by, but not sure).

EDIT: Oops. I used a phototransistor, not a photeresistor.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Last edited by NeXT-Generation on Fri May 18, 2012 11:54 pm, edited 1 time in total.



Wed May 16, 2012 6:18 pm
Profile WWW
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
NeXT-Generation wrote:
I'm not using a analouge sensor, per se, but a button, which should take it to both extremes, right?


Can you try just running a wire from the analog pin you are using to a GND pin. If that doesn't say 0 then nothing will.

Thanks for trying by the way.


Wed May 16, 2012 6:48 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
I tried that. Same result. Although, as I mentioned before, I think I might've seen 14 flash a couple times.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Wed May 16, 2012 7:10 pm
Profile WWW
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
NeXT-Generation wrote:
I tried that. Same result. Although, as I mentioned before, I think I might've seen 14 flash a couple times.


If I just let it run in continuous refresh in the debugger I sometimes see it hit 14 as well but it is mostly solid at 15.

Ok well this looks like a bug unless someone can say otherwise. Thanks for confirming this. I will soon be able to run Robotc on a mega as well so I'll see if it happens there too.


Wed May 16, 2012 8:32 pm
Profile
Rookie

Joined: Wed Aug 22, 2012 6:38 pm
Posts: 1
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
I'have a UNO and the same happens where connecting directly to gnd the analogue ports read 15 not 0.
On Arduino software reads 0.
BUG.?!


Wed Aug 22, 2012 7:46 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Bug? Analog port SensorValue returns 15 for lowest valu
spsantossilva wrote:
I'have a UNO and the same happens where connecting directly to gnd the analogue ports read 15 not 0.
On Arduino software reads 0.
BUG.?!
Why have you revived a 4-month old topic? It's already been established that it's a bug, and the support team knows of it.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Wed Aug 22, 2012 7:53 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.