ROBOTC.net forums
http://robotc.net/forums/

Bug? Analog port SensorValue returns 15 for lowest value
http://robotc.net/forums/viewtopic.php?f=62&t=4546
Page 1 of 1

Author:  Dennis Mabrey [ Wed May 16, 2012 10:11 am ]
Post subject:  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);
  }
}

Author:  mattallen37 [ Wed May 16, 2012 1:27 pm ]
Post subject:  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.

Author:  Dennis Mabrey [ Wed May 16, 2012 2:27 pm ]
Post subject:  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.

Author:  mattallen37 [ Wed May 16, 2012 4:17 pm ]
Post subject:  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?

Author:  Dennis Mabrey [ Wed May 16, 2012 5:41 pm ]
Post subject:  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);
}

Author:  NeXT-Generation [ Wed May 16, 2012 6:18 pm ]
Post subject:  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.

Author:  Dennis Mabrey [ Wed May 16, 2012 6:48 pm ]
Post subject:  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.

Author:  NeXT-Generation [ Wed May 16, 2012 7:10 pm ]
Post subject:  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.

Author:  Dennis Mabrey [ Wed May 16, 2012 8:32 pm ]
Post subject:  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.

Author:  spsantossilva [ Wed Aug 22, 2012 7:46 pm ]
Post subject:  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.?!

Author:  NeXT-Generation [ Wed Aug 22, 2012 7:53 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/