Proportional valve project with current feedback (Help)

Hey guys. I have to warn you that I'm a real beginner at programming but I'm in desperate need of help.

I'm trying to control a 12V proportional pressure relief valve for a hydraulic project that i'm working on.
I've attached the datasheet and it's the 35C valve i've got.

I'm trying to control this with an arduino uno and the arduino motor shield rev 3.
This valve needs to be controlled by current (cause of the changing resistans with temperature in the solenoid).
i'm controlling the output pwm with a pot and reading the current value from the shield (A0).
But i can't wrap my head around how to program this so it will work together with the current feedback.
I appreciates any tips you can give me.

Pressure relief.pdf (53.5 KB)

The PDF contains to little info to see the details except that it is controlled by PWM

In Arduino lingua you need to check the examples of AnalogWrite(n) where n = [0..255] .

The PWM output of the Arduino (5V) should control a transistor (12V) that controls the valve.

similar to - PWM Signal to 10v - #9 by graynomad - Interfacing - Arduino Forum -

Note the signal is inverted

found a googlewhack !

google: AP04G2YP schema -> only 1 hit

What else do you need to know? maybe I can get some more info from the manufacturer.
I can already control the valve with my pot using analogWrite. Maybe I was unclear but the problem i am having is how to intergrate the current feedback so the output is adjusted to the current feedback.
I'm using the motor driver shield to drive the valve so that is not a problem.

I found some more PDF's but no electric schema, or clear picture of the connector or current it draws or so.

The current draw can be read from the "Pressure vs Input current" graph in the pdf file. Max current is 1.2A according to the graph.

But to adjust the output pwm to the current feedback do i have to use some sort of PID code or is there a simpler way?

Wiring diagram? Part number and source of shield?

Here is the link to the shield: http://www.arduino.cc/en/Main/ArduinoMotorShieldR3

And here is the code I have been testing:

int directionPin = 12;
int potPin = A5;
int ValvePin = 3;
int potValue = 0;
int ValveValue = 0;
int currentvalue = 0;

void setup() {
Serial.begin(9600);
pinMode(directionPin, OUTPUT);
pinMode(ValvePin, OUTPUT);

digitalWrite(directionPin, HIGH);

}
void loop() {
potValue = analogRead(potPin);
ValveValue = map(potValue, 0, 1023, 0, 255);
analogWrite(ValvePin, ValveValue);
currentvalue = analogRead(0);

Serial.print("potentiometer = " );
Serial.print(potValue);
Serial.print("\t motor = " );
Serial.print(ValveValue);
Serial.print("\t currentvalue =");
Serial.println(currentvalue);
delay(2);
}

Please use [ code ] tags.

This seems like a perfect job for a PID library. There's a few out there. Some of them may even be good.

An actual current driver may be used instead of the motor shield but you would be doing about the same amount of hacking either way, unless you can find something specific like an industrial 4-2mA current driver.

Thanks MorganS for your answer.

So you think that i need to use a PID library? I found someone proposing a simpler solution, something like this:

if (ReadCurrent < SetCurrent)then increase speed motor
if (ReadCurrent==SetCurrent)maintain speed
if ReadCurrent >SetCurrent ) then decrease the speed.

But I have no clue how or if that would work.

One thing I noticed is you are using the map function which gives a linear value between low end and high end, but the valve is non linear. Maybe some of the math whizzes that lurk around here can help out. Not me I'm afraid.

Good luck.

e-dahlgren:
if (ReadCurrent < SetCurrent)then increase speed motor
if (ReadCurrent==SetCurrent)maintain speed
if ReadCurrent >SetCurrent ) then decrease the speed.

Yes, that's a simple control system which will probably work in this example. The question is, by how much do you increase or decrease? The basic "P" term in the PID control loop sets the increase based on how far away you are from the goal:

 potValue = analogRead(potPin);  
 currentvalue = analogRead(0);
 ValveValue = ValveValue + (potValue - currentValue) * Gain;
 OutputValue = map(ValveValue, 0, 1023, 0, 255);
 analogWrite(ValvePin, OutputValue);

Note this keeps ValveValue at high resolution (0-1023) but maps it down to 0-255 for output only. Gain may be varied to change the speed of response. Use a floating-point number because it will probably end up rather small, like 0.05.

I don't know what the range of current readings are that you are expecting. You will probably end up with another map() function to expand the range of interest to match the pot's range.

Maybe I was unclear but the problem i am having is how to intergrate the current feedback so the output is adjusted to the current feedback.

Have you figured out a way to measure and convert the current value into a 0-5v voltage for the arduino analog input?

If you turn the pot until potValue = 128, what does currentvalue read?

How about 256, 384,512?

That part seems solved. He's using a motor shield that has current feedback built in.

voltage proportional to the measured current, which can be read as a normal analog input, through the function analogRead() on the analog input A0 and A1. For your convenience it is calibrated to be 3.3V when the channel is delivering its maximum possible current, that is 2A.

So then we go to the datasheet which was also provided in the first post and find that for 12V operation, the valve will use between 0 and 1.2A. The motor shield will translate this to 0-1.98V. Then since he's using a 5V Arduino (also provided in the first post) this will end up with a range of analogRead() values from 0 to 405.

So far, everything is linear. The map() function will work fine for this.

It goes highly non-linear if you are trying to use this to set a specific pressure or flow. The charts in the datasheet seem to show a big dependency on the temperature of the hydraulic fluid so you would need a thermometer input for the Arduino if that's what is really being controlled.

I hope the OP is actually trying to control a thing which is dependent on this valve's pressure. Then the position/height/force can be measured there and another "control loop" set up to maintain that measurement.

The pressure vs current curve is not linear, if it were it would be a straight diagonal line.

Thanks everyone for your answers.

I'm using this valve to control the pulling force on a hydraulic winsch. The linearity problem is not so
important right now because I read the input pressure with a manometer and can adjust it after that.

MorganS do you have the time to write up the code for me so i can test it?