Go Down

Topic: Getting output highs when I should be getting lows (Read 15776 times) previous topic - next topic

substance

Hi peeps. I am am having a bit of trouble and wondering if it is a problem with my code. The problem is that I am getting highs on my outputs which is making my clocks count up, when they should be low. The code is for monitoring when 3 gases are flowing and 2 valves are open.  When any of the 3 gasses are flowing then I want a clock to monitor how long they are flowing for. If a gas is flowing then it is going to trigger the dep timer. Each of the gasses are high (5V ish) when they are not flowing and low when they are flowing. The problem is that I am getting a high output to the dep timer  even when none of the gasses are flowing. The same is happening with the 2 valves (BGA - BGB). These are high when shut and low when open. Even when they are shut, I am still getting a high on my outputs and my clocks are counting up.
Now is this a fault with my code which is included below or a wiring fault? I have tried using all 3 gnds on the uno but it is exactly the same. Any help or asdvice would be greatly appreciated

Dave

Code: [Select]
int PHOS_IN_A1 = 1; //Declares an integer of Phos input
int BOR_IN_A2 = 2;  //Declares an integer of Boron input
int ARS_IN_A3 = 3;  //Declares an integer of Arsine input
int BGA_IN_A4 = 4;  //Declares an integer of BGA input
int BGB_IN_A5 = 4;  //Declares an integer of BGB input
int DEP_TIME = 12;  //Declares an integer of Dep timer
int A_SIDE = 11;    //Declares an integer of BGA timer
int B_SIDE = 10;    //Declares an integer of BGB timer

long aRead = 0;  //Assumes voltage range from input


void setup()
{
Serial.begin(9600);  //Serial console for debugging

pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

void loop()
{

float voltage;    //Declares a floating number on voltage

for(int i=0; i <10; i++)   //Takes 10 readings
aRead += analogRead(PHOS_IN_A1);  //Reads phos in pin
aRead = aRead/10;        //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;   //Converts to digital
voltage = voltage*1000;           //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}


for(int i=0; i <10; i++)  //Takes 10 readings
aRead += analogRead(BOR_IN_A2);  //Reads boron in pin
aRead = aRead/10;        //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;  //Converts to millivolts

if( voltage <= 2000 )   //If voltage less than 2V
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}

aRead = 0;   //Assumes voltage range from input


for(int i=0; i <10; i++) //Takes 10 readings
aRead += analogRead(ARS_IN_A3); //Reads arsine in pin
aRead = aRead/10; //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;          //Converts to millivolts

if( voltage <= 2000 )          //If voltage less than 2V
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}

aRead = 0;   //Assumes voltage range from input


for(int i=0; i <10; i++)  //Takes 10 readings
aRead += analogRead(BGA_IN_A4);  //Reads BGA in pin
aRead = aRead/10; //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;          //Converts to millivolts

if( voltage <= 2000 )           //If voltage less than 2V
{
digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
}

aRead = 0;  //Assumes voltage range from input


for(int i=0; i <10; i++)   //Takes 10 readings
aRead += analogRead(BGB_IN_A5);  //Reads BGB in pin
aRead = aRead/10;   //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;  //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V

{
digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer

}

aRead = 0;  //Assumes voltage range from input
//Debug info to serial console
    Serial.print("Analog: "); 
    Serial.print(aRead);
    Serial.print(" Voltage:");
    Serial.println(voltage);

    delay(1000);  //1 sec delay between measurements
}

PaulS

What value is in voltage after each block that manipulate voltage? You have 5 blocks that check voltage, but only one output.

Once you have enabled the timer pin, is there a reason to test the other voltages?

Code: [Select]
aRead = 0;  //Assumes voltage range from input
//Debug info to serial console
    Serial.print("Analog: "); 
    Serial.print(aRead);

How useful is it to print 0 on every pass through loop?
The art of getting good answers lies in asking good questions.

substance

Paul, there are 3 outputs, Dep timer, A-Side and B-side. The dep timer is counting how long one of the 3 gasses are flowing for (boron, arsine and phosphorous). If any of these are flowing then I want a high on my output, which will give me 5v to power my clock. Each gas when not flowing is a high when I measure it is a high and then goes low when one of the flows. So when any of them are flowing I want the output to go high. The problem is that when none of them are flowing, I am still getting a high on my output. Only one gas can flow at a time as they go towards producing a plasma.
The machine is an implanter which is used to manufacture semi conductors. The machine has 2 end stations where the silicon wafers are implated with the plasma. On the end stations there is a valve which allows the plasma through to implant the wafers. I am also trying to monitor when these valves are open and closed. It is the same situatuion with the valves where upon I am getting a high on my outputs even though it should be low.
One thing that I have noticed is that I have not assigned the input voltage to either be compared to the default one or the internal. Would this automatically not go to the default one if I did not assign it to anything?

PaulS

Quote
The problem is that when none of them are flowing, I am still getting a high on my output.

Where do you ever set the pin LOW again?

If you've set the pin HIGH because the reading from PHOS_IN_A1 is low enough, is there really any reason to read the voltage of the other two gas pins?

When you have set the timer pin HIGH, what should set the timer pin LOW again? What causes the gasses to begin flowing? What prevents multiple gasses from flowing?

Quote
One thing that I have noticed is that I have not assigned the input voltage to either be compared to the default one or the internal. Would this automatically not go to the default one if I did not assign it to anything?

The default is to compare the input voltage to the reference voltage, which if one is not supplied is 5V.
The art of getting good answers lies in asking good questions.

substance


Quote
The problem is that when none of them are flowing, I am still getting a high on my output.

Where do you ever set the pin LOW again?

If you've set the pin HIGH because the reading from PHOS_IN_A1 is low enough, is there really any reason to read the voltage of the other two gas pins?

When you have set the timer pin HIGH, what should set the timer pin LOW again? What causes the gasses to begin flowing? What prevents multiple gasses from flowing?

Quote
One thing that I have noticed is that I have not assigned the input voltage to either be compared to the default one or the internal. Would this automatically not go to the default one if I did not assign it to anything?

The default is to compare the input voltage to the reference voltage, which if one is not supplied is 5V.




You select the gas from the control panel. There is a seperate switch for each gas and they are all in parrallel. When a switch is pressed is goes grom 5V to 0V. I have soldered onto the output of each switch and they are going into the inputs in my uno. I need to monitor all the gasses as at some point the operator will switch from one gas to the other. There is only one output for all these 3 inputs as I need to monitor the total time which all the gasses are flowing. Once the gasses have been flowing for 300 hours then it will be time to perform a maint on the machine

substance

Quote
Where do you ever set the pin LOW again?

When you have set the timer pin HIGH, what should set the timer pin LOW again? What causes the gasses to begin flowing? What prevents multiple gasses from flowing?



I have asked th uno to give me a high on the dep timer output if any of the gas inputs are less than 2 volts. Could I change my code from how I have got it to say IF any of the gas inputs are less than 2V, then give me a high on the dep timer output, else stay low all the time?




PaulS

Quote
I have asked th uno to give me a high on the dep timer output if any of the gas inputs are less than 2 volts.

Yes, you have. But, you have never asked it to set the pin LOW if no gas is flowing.
Quote

Could I change my code from how I have got it to say IF any of the gas inputs are less than 2V, then give me a high on the dep timer output, else stay low all the time?

The pin stays however you set it. It does not automatically revert to some setting (except at reset). So, yes, you need to change your code.
The art of getting good answers lies in asking good questions.

substance


Quote
I have asked th uno to give me a high on the dep timer output if any of the gas inputs are less than 2 volts.

Yes, you have. But, you have never asked it to set the pin LOW if no gas is flowing.
Quote

Could I change my code from how I have got it to say IF any of the gas inputs are less than 2V, then give me a high on the dep timer output, else stay low all the time?

The pin stays however you set it. It does not automatically revert to some setting (except at reset). So, yes, you need to change your code.



Cheers Paul. I need to put an else statement in don't I telling it to go low if none of the gasses are running? I have honestly been at this from 7am this morning ( it is now 5:30pm ) either soldering wires, setting everything up or trying to suss why it is not working. I am going to call it a day here now and carry on tomorrow.
Thanks for your help mate  :)

PaulS

Quote
I need to put an else statement in don't I

Yes, but be careful where you put this else. You do not want to turn the pin off if gas 2 is not flowing, after turning it on because gas 1 IS flowing.

You should probably add a boolean, gasIsFlowing, with an initial value of false. In each gas test, set the glat true if the gas is flowing.

Then, after all three tests, turn the pin on or off, based on the flag.
The art of getting good answers lies in asking good questions.

substance

Cheers Paul. i am going to give it a go today so will let you know how I get on. I can test it here at home so will play around with the code and see how I get on  :)

substance

Hi peeps. I have altered my code using the boolean for and. Can I do this so it measures the input of all 3 pins or do I have to seperate it into sections?? If anyone can take the time to have a look for me then i would appreciate it.

Code: [Select]
int PHOS_IN_A1 = 1; //Declares an integer of Phos input
int BOR_IN_A2 = 2;  //Declares an integer of Boron input
int ARS_IN_A3 = 3;  //Declares an integer of Arsine input
int BGA_IN_A4 = 4;  //Declares an integer of BGA input
int BGB_IN_A5 = 4;  //Declares an integer of BGB input
int DEP_TIME = 12;  //Declares an integer of Dep timer
int A_SIDE = 11;    //Declares an integer of BGA timer
int B_SIDE = 10;    //Declares an integer of BGB timer

long aRead = 0;  //Assumes voltage range from input


void setup()
{
Serial.begin(9600);  //Serial console for debugging

pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

void loop()
{

float voltage;    //Declares a floating number on voltage

for(int i=0; i <10; i++)   //Takes 10 readings
aRead += analogRead(PHOS_IN_A1 && BOR_IN_A2 && ARS_IN_A3);  //Reads phos, bor                        
                                                           //and ars in pin
aRead = aRead/10;        //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;   //Converts to digital
voltage = voltage*1000;           //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}
else if( voltage > 2000 )   //If voltage more than 2V
{
digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
}


aRead = 0;   //Assumes voltage range from input


for(int i=0; i <10; i++)  //Takes 10 readings
aRead += analogRead(BGA_IN_A4);  //Reads BGA in pin
aRead = aRead/10; //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;          //Converts to millivolts

if( voltage <= 2000 )           //If voltage less than 2V
{
digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
}
else if( voltage > 2000 )  //If voltage more than 2V
{
digitalWrite(A_SIDE, LOW);   //Give no output on a side
}


aRead = 0;  //Assumes voltage range from input


for(int i=0; i <10; i++)   //Takes 10 readings
aRead += analogRead(BGB_IN_A5);  //Reads BGB in pin
aRead = aRead/10;   //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;  //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V

{
digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer

}
else if( voltage > 2000 )  //If voltage more than 2V
{
digitalWrite(B_SIDE, LOW);   //Give no output on B side
}

aRead = 0;  //Assumes voltage range from input
//Debug info to serial console
   Serial.print("Analog: ");  
   Serial.print(aRead);
   Serial.print(" Voltage:");
   Serial.println(voltage);

   delay(1000);  //1 sec delay between measurements
}


PaulS

Quote
Can I do this so it measures the input of all 3 pins or do I have to seperate it into sections?

You can only read one pin at a time. You could read all three pins in a for loop, one at a time. I'm not really sure what you are asking here.
The art of getting good answers lies in asking good questions.

AWOL

if you find you're writing the same (or very nearly the same) code multiple time, like here
Code: [Select]
for(int i=0; i <10; i++)  //Takes 10 readings
aRead += analogRead(BGA_IN_A4);  //Reads BGA in pin
aRead = aRead/10; //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;          //Converts to millivolts

it is a sure sign that you need to be introduced to functions:
Code: [Select]
float readVoltage (int inputPin, int nReadings)
{
  unsigned long sum = nReadings / 2;  // pre-round the result
  for(int i=0; i < nReadings; i++) {
    sum += analogRead(inputPin);
  }
  sum /= nReadings;
  return (sum * 5.0)/1024.0;
}

wildbill

This doesn't do what you think it does:
Code: [Select]
aRead += analogRead(PHOS_IN_A1 && BOR_IN_A2 && ARS_IN_A3);
As you surmise, you need to do them one at a time.

Try adding more serial prints so you can see what readings your sensors are actually giving the Arduino - might flush out a wiring issue. Speaking of which, seeing the wiring diagram may well help too.

Also, it sounds like you're using an Arduino output pin to drive an external device (timer). Is this direct? In which case does this device draw more than 40ma? You may need a transistor or relay to drive it from another source.

substance

Cheers lads. I am having issues uploading any code to my unit again. I keep getting protocol issues. It will let me upload then if I reset and try to upload another code then it will not allow it. I am going to have a bite to eat and a bit of a break before i have another go at the code and resolving any issues.
Thanks for your help, will let you know how I get on this afternoon :-)

Go Up