Voltage control with PWM-signal


hello,
i'm attempting use arduino uno modulate output voltage according signal supplied sensor. acquiring signal sensor works fine, i'm having problems controlling output voltage.

i'm using sensair sensor i2c connection supplies values relative humidity, temperature , co2 concentration. part works fine have set aside , writing code constant value (mv) should achieved output voltage. once working, i'm planning replace constant value input sensor, scaled according appropriate voltage range.

i'm using variable power supply power source, , fds6990a logic-level mosfet (data sheet attached) control output, signal 1 of pwm pins of arduino connected gate. i've read through of online information regarding these processes , have adopted code , hardware configurations various sources, yet it's still not functioning properly. i've included relevant code below , schematic diagram of circuit attachment.

here tie in necessary libraries , initialize variables
code: [select]

#if arduino < 100
#include <wprogram.h>                          // add other libraries on demand requested
#else
#include <arduino.h>                               // needed when working libraries
#endif
#include <stdio.h>
/***  declare constants , variables adjustable voltage regulator  ***/
const byte actualvaluevoltpin       =  a1;      // measure regulated voltage
const byte controlpin                  =  11;       // pwm output voltage control
/***  declare constants , variables analog input measurement  ***/
const unsigned long refvolt            =  5000;    // reference voltage default 5v (5000mv) analog converter; change 3300 if 3,3v
/***  don't adjust output voltage higher 19.500mv = 19,5v existing resistor divider  ***/
/***  regulation not work higher 20v!!!  ***/

/////////////adjust voltage setpoint , duration here///////////////////
const unsigned int outputvoltsetpoint  =  7000;    // adjust output voltage (set 0000 5000 in mv, depending on voltage divider)
const unsigned int duration            =  180;     //duration in seconds
///////////////////////////////////////////////////////////////////////////////////////////////////

unsigned int actualvaluevolt           = 0;       // initialize measured output voltage 0mv start with/***  declare constants , variables resistor voltage diviver @ analog input   ***/
const unsigned int voltagedivider      = 4;        // value depending on ratio of resistor voltage dividerbyte
byte pwmvalue =  0  ;                              // initialize pwm value
unsigned long time;
long interval                          = 1000;
int row = 0;
int duration_m = duration*1000;   


here turn off internal pull-up resistor , set output pin high:
code: [select]

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 control output voltage
digitalwrite(controlpin,high);                    // switch on mosfet drive current output rc

serial.begin(128000);
serial.println("cleardata");
serial.println("label,time,millis,set,voltage,pwm");
}       


ultimately want use output voltage electrolysis in water, or produce heat means of resistance wire. i've tested far electrolysis (3 ua 8v output voltage) , led parallel capacitor load. i've been setting input voltage @ 15v, have tried lower , higher values.

the output voltage measured @ analog a1 pin of arduino after being reduced quarter of it's actual level voltage divider. value multiplied 4 in program , used adjust pwm-signal (see code below). idea, isn't working. pwm-signal adapts should, output voltage doesn't respond. suspect hardware problem.


code: [select]

void loop() {                                    // function loop
/***  calculate mv based on 10-bit ad-converter values 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 pwm signal


i've tried many configurations, including other mosfets (not logic level, driver or npn transistor), none have produced correct results. 
here details regarding incorrect functioning:
  • with negative lead power supply connected source of mosfet , ground or arduino, output voltage measured same input voltage
  • when connection ground removed, measured output voltage drops, still rises , falls proportionately power supply voltage , not according set-point voltage in arduino code
  • with 1000uf, 35v capacitor in line between drain , negative pole of electrolysis, voltage drops below of power supply rises , not seem affected pwm-signal arduino


i appreciative of insights or suggestions!

pwm intended control amount of energy rather voltage. if on time maximum amount of energy. if on 50% of time 50% of energy averaged on period of time. actual voltage either high or low.

you can use rc filter smooth voltage. if want control voltage better use digital analog converter chip.

...r


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Voltage control with PWM-signal


arduino

Comments