 # change PWM frequency

Hello!

I want to use a solenoid valve. It needs 0-10 V analog signal. I use pin 10 pwm to give the signal with RC filter and an amplifier to raise 0-5 V to 0-10 V. If i change frequency then if arduino gives out for example 2,5 V which means amplifier must give out about 5 V. But the amplifier gives out about 4,5 V. If i dont change the fequency it gives exactly 5V but the signal frequency is 500 Hz which is not good for the valve

i used this example

``````#include <PWM.h>

//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int led = 7;                // the pin that the LED is attached to
int brightness = 0;         // how bright the LED is
int fadeAmount = 5;         // how many points to fade the LED by
int32_t frequency = 20000; //frequency (in Hz)

void setup()
{
//initialize all timers except for 0, to save time keeping functions

//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, frequency);

//if the pin frequency was set successfully, pin 13 turn on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
}

void loop()
{
//use this functions instead of analogWrite on 'initialized' pins
pwmWrite(led, brightness);

if (brightness == 0 || brightness == 255) {
}

delay(30);
}
``````

Without a schematic and details of the solenoid your post is useless...

Btw, I've never seen a solenoid who needs a control signal between 0v and 10V. What's it going to control? A solenoid is on or off. So isn't it simply a 10V solenoid?

And my guess at the problem, the amp can't deliver the current for the solenoid...

The valve is FESTO MPYE. It needs 0-10V analog signal it controls two pneumatic artificial muscle.the full code here. Arduino reads a distance it compares with the distance what i give in labview then fuzzy calculate a number between 0-255 and writes on pin10

``````#include <Wire.h>
#include <PWM.h>

char cb;
String req;
int pneuPin = 10;
int32_t frequency = 32500;

int t0, t1;
bool echo = false;

void setup(void) {

Serial.begin(115200);
Wire.begin();

//initialize all timers except for 0, to save time keeping functions

//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(pneuPin, frequency);

//if the pin frequency was set successfully, turn pin 13 on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);

pinMode(pneuPin, OUTPUT);
analogWrite(pneuPin, 0);

}

}

void loop() {

if (Serial.available()) {

if (echo) {
Serial.write(cb);
if (cb == 13) {
Serial.println("");
}
}

req += cb;

if (cb == 13) {

if (req.startsWith("REQ_POS")) {

float distance = 28.6*pow(volts, -1.05);
Serial.println(distance);

} else if (req.startsWith("REQ_PNEU<")) {

int gtpos = req.indexOf("<");
int ltpos = req.indexOf(">");
String str_value = req.substring(gtpos + 1, ltpos);

pwmWrite(pneuPin, str_value.toInt());

Serial.println("REP_PNEU<ACK>");

} else {
Serial.print("UNKNOWN COMMAND:");
Serial.println(req);
}

req = "";
}
}
}
``````

Ah, yes, that's a bit more then a simple solenoid...

But uhm, still no schematic (and that's probably where the error is...)

sorry for that I cant make that now

Arduino read sharp distance sensor on A0 then labview reads this value. I give the desired value then the fuzzy calculate the value sneds back to arduino and it writes on pin10. It goes through an RC filter 330ohm and 2,2 uF and goes to amp 2m324n. Then amp output goes to the valve.

I give the desired value then the fuzzy calculate the value sneds back to arduino and it writes on pin10.

You want to proof-read that sentence? Then, comment on what "the fuzzy" is.

but the signal frequency is 500 Hz which is not good for the valve

What frequency do you want? Can your RC filter operate at that frequency?

Can't find anything for a 2m324n, Did you mean LM324? If so, an opamp alone isn't going to give you anything useful on it's own. So how did you connect that?

Also, RC filter of 330Ohm and 2,2uF seems rather low. What frequency do you use? Defaults for an Uno are (+-) 975Hz for pin 5 and 6 and 490Hz for the others. For a control application where I needed a voltage I used 100k and 100n but I changed the PWM frequency to 30k(-ish).

I thing I can't find about the actuator is it's input impedance. Because it's just a control input I assume it's very high but the datasheet doesn't mention it And yeah, assumption is the mother of all fuck ups...

And last but not least, what on earth has labview to do with this? And what is labview doing what the Arduino can't do? But more important, that's not important here, so why not make a simple test sketch (without the labview and sensor crap) and do some tests.