I am using a TIP120 Mosfet with an Arduino Uno to control a solenoid valve (see here). As listed in the datasheet, it must be driven with a PWM signal of 1200 Hz. The valve should be used in another context than here, however I am using an Arduino in a first step to test the valve (to characterise its behaviour).
I connected the valve analogously to this schematic.
I changed the PWM-frequency to 1200 HZ using this tutorial.
When I am now changing the duty cycle of the AnalogWrite of the Arduino, I notice that the solenoid valve almost only draws current from D=230 and upwards, below this, current draw is very small and the valve is closed.
For debugging purposes, I used an oscilloscope to check the PWM signal that goes into the valve (Probe between Drain and GND). I could see the following behaviour, which seems very odd to me (please check images)
Image 1: Duty cycle of D = 25 (x-axis: 200μs/div and y-axis: 40V/div)
Image 2: Duty cycle of D = 221 (x-axis: 200μs/div and y-axis: 40V/div)
Connecting just a resistor as a load (instead of the valve) results in the PWM square wave that I am familiar with.
- What could be the reason for this spiky PWM signal (my guess is that it might be due to the inductance of the coil) and what might I do to resolve the issue?
- Why does the Solenoid valve only draw current when the duty cycle of the AnalogWrite is above (approx) 230? I think that this should not be the common behaviour. Preferably I would like to use the entire span of the Analog Write to set the orifice size of the valve.
Also, if it might be of use, here is my code (PWM.h is an import to change the standard PWM frequency):
#include <PWM.h>
int PWM_PIN = 10;
int pwmval = 0;
int32_t frequency = 1200;
void setup() {
InitTimersSafe();
bool success = SetPinFrequencySafe(PWM_PIN, frequency);
Serial.begin(9600);
pinMode(PWM_PIN,OUTPUT);
Serial.println("Send a value between 1 and 255");
}
void loop() {
if (Serial.available() > 1) {
pwmval = Serial.parseInt();
Serial.print("Set Speed to: ");
Serial.println(pwmval);
analogWrite(PWM_PIN, pwmval);
Serial.println("done!");
}
}
Hope that anybody can help.