Hello,
I’m attempting to use an Arduino Uno to modulate the output voltage according to a signal supplied from a sensor. Acquiring the signal from the sensor works fine, but I’m having some problems controlling the output voltage.
I’m using a Sensair Sensor with an I2C connection which supplies Values for relative humidity, temperature and CO2 concentration. This part works fine so I have for now set that aside and am writing into the code a constant value (mV) which should be achieved as the output voltage. Once this is working, I’m planning to replace the constant value with the input from the sensor, scaled according to the appropriate voltage range.
I’m using a variable power supply as power source, and the FDS6990A logic-level MOSFET (data sheet attached) to control the output, with a signal from one of the PWM pins of the Arduino connected to the gate. I’ve read through much of the online information regarding these processes and have adopted code and hardware configurations from various sources, yet it’s still not functioning properly. I’ve included relevant code below and a schematic diagram of my circuit as an attachment.
Here I tie in the necessary libraries and initialize variables
#if ARDUINO < 100
#include <WProgram.h> // Add other libraries on demand as requested
#else
#include <Arduino.h> // Needed when working with libraries
#endif
#include <stdio.h>
/*** Declare constants and variables for the adjustable voltage regulator ***/
const byte actualValueVoltPin = A1; // Measure regulated voltage
const byte controlPin = 11; // PWM for output voltage control
/*** Declare constants and variables for analog input measurement ***/
const unsigned long refVolt = 5000; // Reference voltage default 5V (5000mV) to analog converter; change to 3300 if 3,3V
/*** Don’t adjust output voltage higher 19.500mV = 19,5V with existing resistor divider ***/
/*** Regulation does not work higher 20V!!! ***/
/////////////ADJUST VOLTAGE SETPOINT AND DURATION HERE///////////////////
const unsigned int outputVoltSetPoint = 7000; // Adjust output voltage (Set 0000 to 5000 in mV, depending on voltage divider)
const unsigned int duration = 180; //duration in seconds
///////////////////////////////////////////////////////////////////////////////////////////////////
unsigned int actualValueVolt = 0; // Initialize measured output voltage with 0mV to start with/*** Declare constants and variables for resistor voltage diviver at the analog input ***/
const unsigned int voltageDivider = 4; // Value depending on ratio of the resistor voltage dividerbyte
byte PWMValue = 0 ; // Initialize PWM value
unsigned long time;
long Interval = 1000;
int row = 0;
int duration_m = duration*1000;
Here I turn off the internal pull-up resistor and set the output pin to high:
void setup() {
//////Turn Pull-up Resistor on/off/////////////////////
pinMode(1+14, INPUT); //both lines, (x+14, ...) x=PinNumber
digitalWrite(1+14, LOW); //HIGH -> Resistor on
delay(100);
//////end adjust pull-up/////////////////////////////////
pinMode(controlPin, OUTPUT); // Pin to control the output voltage
digitalWrite(controlPin,HIGH); // Switch on MOSFET to drive current to the output RC
Serial.begin(128000);
Serial.println("CLEARDATA");
Serial.println("LABEL,Time,millis,set,voltage,pwm");
}
Ultimately I want to use the output voltage for electrolysis in water, or to produce heat by means of a resistance wire. I’ve tested it so far with the electrolysis (3 uA by about 8V output voltage) and also simply with an LED parallel to a capacitor as a load. I've been setting the input voltage at about 15V, but have also tried lower and higher values.
The output voltage is measured at the analog A1 pin of the Arduino after being reduced to a quarter of it’s actual level by a voltage divider. Then the value is multiplied by four in the program and used to adjust the PWM-signal (see code below). This is the idea, but it isn’t working. The PWM-signal adapts as it should, but the output voltage doesn’t respond. I suspect that it is a hardware problem.
void loop() { // Function Loop
/*** Calculate mV based on the 10-bit AD-Converter values from 0..1023 ***/
unsigned long currentMillis = millis();
actualValueVolt = ((refVolt * 1000) / 1023) * (analogRead(actualValueVoltPin)) / 1000;
actualValueVolt *= voltageDivider; // Multiply measured analog in voltage depending on divider factor
/*** Output voltage regulation ***/
if((actualValueVolt < outputVoltSetPoint)&&(PWMValue<255)) // Switch on MOSFET while increasing HIGH time of Digital Pin 6
analogWrite(controlPin,PWMValue++);
if((actualValueVolt > outputVoltSetPoint)&&(PWMValue>0))
analogWrite(controlPin,PWMValue--); // Reduce HIGH time of the PWM signal
I’ve tried many configurations, including other MOSFETs (not logic level, with a driver or a NPN transistor), but none have produced the correct results.
Here are some details regarding the incorrect functioning:
- With negative lead from power supply connected to source of MOSFET and to ground or Arduino, output voltage is measured to be about the same as input voltage
- When connection to ground removed, measured output voltage drops, but still rises and falls proportionately with power supply voltage and not according to set-point voltage in Arduino code
- With 1000uF, 35V capacitor in line between drain and negative pole of electrolysis, voltage drops below that of power supply but slowly rises and does not seem to be affected by PWM-signal from Arduino
I would be most appreciative of any insights or suggestions!
Arduino_voltagecontrol.pdf (75.7 KB)
MOSFET_logic_FDS6690A.pdf (453 KB)