Go Down

Topic: Analog inputs linked somehow? (Read 2294 times) previous topic - next topic

Bebbetufs

have two functions reading the analogue pins on my mega 1280
The input pins are different, the variables are different, the functions are different. Still both
functions will take input from either input pin.
I.E input on pin 0 is read by both functions, and input on pin 2 is read by both functions.
What's causing this??

Code: [Select]
 
 int boostPin = A0;   // input pin for the MPX4250
 int af_Pin = A2;   //


Code: [Select]

 int boostRead = 0; //Stores value read from MPX4250
 int af_Read = 0; //Stores value read from UEGO


The reading itself is done in the looop by:
Code: [Select]

void loop(){  
   boostRead = analogRead(boostPin);
   af_Read = analogRead(af_Pin);
   }


Code: [Select]

function boost(){
caluculate input from boostRead;
lcd.print (bCalculation);
}

function afr(){
caluculate input from af_Read;
lcd.print (afCalculation);}

Graynomad

Firstly that's not compilable code.

Secondly where do you call the two functions?

Thirdly, unless it's huge just show us the entire code, as it is anything could be happening between the snippets.


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Bebbetufs

#2
Mar 01, 2011, 01:35 pm Last Edit: Mar 01, 2011, 01:38 pm by Bebbetufs Reason: 1
The code is too long for the forum.

http://pastebin.com/AYFtVZ82

Could this bit be the culprit?
Code: [Select]

//_____________Defining Encoder Inputs_________________________________________
 #define button 22
 #define ENC_A 20  //MUST be pin 0 i pinD range
 #define ENC_B 21  //MUST be pin 1 i pinD range
 #define ENC_PORT PIND  //Create a port wich low-level reads all pinD pins simultaneously (=pin0-pin7)=low level read


scjurgen


How did you connect the sensors to the inputs? are they floating right now? That can lead to weird results.
Juergen

Bebbetufs

The sensors are not really there. I'm using a pot for testing. it is connected to the analog input, ground is from the board and 5v is from my power supply, the one that powers the board. Currently running @ 5.2 volts.

I also tried feeding the pot 5v from the Arduino board. Same results.
Could it be that the voltage is too low for the board?

weirdo557


WillR

If what you are saying is that: You can read the input (with no lead) next to the pin that you actually do have wired... then the answer is yes. I can confirm this.

If I am only using say three Analog inputs, I GROUND the inputs on either side of the three (sequential) leads that I am using... At least then I spot my stooopid typoes eh?

So I think I can confirm your question...

Just another Hacker

Bebbetufs

Quote
If what you are saying is that: You can read the input (with no lead) next to the pin that you actually do have wired... then the answer is yes. I can confirm this.

If I am only using say three Analog inputs, I GROUND the inputs on either side of the three (sequential) leads that I am using...

Is this how it is supposed to be?
I'm only using one pot for testing and shifting this from port A0 to A2. I also tried A0 and A8 just to be sure.
When i adjust the pot which is now only connected to input A8 the analog read function reads the exact same values from the presently unconnected A0.


Artem_F

as far as I remember, the inputs in Arduino are multiplexed and the system
switches between them to digitize the signal.
If your input is hanging in the air, I suspect that the charge sitting
at the "collecting plate" at the moment of measuring the
previous signal has no sink and the second pin appears to be at the
same potential. What happens if you ground the second pin?
I think you'll measure zero in this case.

Basically, what is your question? Why does the floating pin measure
the same voltage as a connected one? Even if it is so why should
one worry about any data from floating inputs? :)


Bebbetufs

I tried grounding the second pin.
No difference.
The two bars on my LCD which are supposed to measure different inputs both move in perfect sync no matter if I ground pin A0 and connect the pot to pin A2, or vice versa. The value input to one pin is duplicated to the other.

Magician

Your code is HUGE.
have you ever try split it ? debug one piece at a time?
as they say, you can't swallow an ellefant.
 

Artem_F

OK, then do a simple test:
write a routine that reads the inputs
one after another and sends the results to
the serial output (to eliminate possible messing with overlapped
pin numbers).
Just several lines: read the input, print the data, 1 sec delay.

If this routine will return similar values for each pin no matter what
you do with the pot then it's the problem of the board and this might mean
that the digitizer or the multiplexor has been fried.

Bebbetufs

Did the test and was able to sort it out. Thanks for the tip.
I had set the PSU to 5v which seems to make the board unstable somehow. I also had to sort out my wiring a bit.
It's working now so thanks to everyone for their help.

Go Up