Hi all,
I am using an Arduino Mega to control a Relays that controls a VFD. I want to control the VFD directly with the arduino, but it needs a 0-10V control input(photo). I want to replace the speed pot with the circuit and the arduino.
So, there are a lot of posts about that problem in other forums but I wasn't able to find a circuit that really worked, unless this one:
http://playground.arduino.cc/Main/Regul ... ageBooster
But this brings 12V up to 60V and I already get a 10V signal from the VFD.
I am sure, someone had that problem before. Could please someone post a circuit that works for this specific use?
Thanks!
Convert PWM to 0-10V
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- bdellal
- Posts: 51
- Joined: Tue Jun 10, 2014 6:00 pm
Convert PWM to 0-10V
- Attachments
-
- IMG_20140721_134435124.jpg (825.57 KiB) Viewed 2099 times
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Convert PWM to 0-10V
You don't need a boost converter. A transistor, a capacitor, and a few resistors will do.
The circuit you want looks like this:
Connect the top of the 10k resistor to the VFD's 10v supply (same place the pot connects now). The transistor will allow varying amounts of current to flow through the 10k, producing a voltage between 0 and 10v.
The 470 ohm resistor and 100nF capacitor make a low-pass filter that will turn the Arduino's PWM into a more or less stable DC voltage. There's a tradeoff between how smooth the voltage is and how quickly it can respond to changes though.. you may need to play with the values to get the behavior you want. Making either the resistor or capacitor values larger will make the voltage smoother/more sluggish. Making either of them smaller will make the voltage choppier/more responsive.
Since the filter makes it hard to predict the exact output voltage you'll get from a given PWM ratio, the 100k resistor divider divides the output by 2 so you can measure it with the Arduino's ADC.
The circuit you want looks like this:
Connect the top of the 10k resistor to the VFD's 10v supply (same place the pot connects now). The transistor will allow varying amounts of current to flow through the 10k, producing a voltage between 0 and 10v.
The 470 ohm resistor and 100nF capacitor make a low-pass filter that will turn the Arduino's PWM into a more or less stable DC voltage. There's a tradeoff between how smooth the voltage is and how quickly it can respond to changes though.. you may need to play with the values to get the behavior you want. Making either the resistor or capacitor values larger will make the voltage smoother/more sluggish. Making either of them smaller will make the voltage choppier/more responsive.
Since the filter makes it hard to predict the exact output voltage you'll get from a given PWM ratio, the 100k resistor divider divides the output by 2 so you can measure it with the Arduino's ADC.
- bdellal
- Posts: 51
- Joined: Tue Jun 10, 2014 6:00 pm
Re: Convert PWM to 0-10V
Thank you very much! I built a modified version of this circle with a mosfet and without RC filter, because the VFD accepts PWM.
So, I need to run the attached profile with it. What's the easiest way to set a profile on the arduino?
I wrote this code so far, that converts the PWM to Hertz for my VFD:
So, I need to run the attached profile with it. What's the easiest way to set a profile on the arduino?
I wrote this code so far, that converts the PWM to Hertz for my VFD:
Code: Select all
int32_t frequency = 35; //frequency (in Hz)
void setup()
{
//initialize all timers except for 0, to save time keeping functions
// InitTimersSafe();
//if the pin frequency was set successfully, turn pin 13 on
pinMode(3, OUTPUT);
// digitalWrite(3, HIGH);
}
void loop()
{
//use this functions instead of analogWrite on 'initialized' pins
setSpeed(50);
delay(30);
}
void setSpeed(int freq)
{
float output = -5*freq+255;
if(output > 255)
output = 255;
else if(output < 0)
output = 0;
analogWrite(3, output);
}
- Attachments
-
- Capture.JPG (56.96 KiB) Viewed 2054 times
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Convert PWM to 0-10V
You're missing some critical information.
The table you posted above specifies a VFD frequency, but you haven't defined a rule that converts a PWM duty cycle value to a VFD frequency.
Once you have that, the output curve shown in the graph is what math types called a 'piecewise linear function'. You can use a simple y=mx+b function to calculate the height of the line at any time, but the values of the constants 'm' and 'b' change at specific times.
The code to calculate the value of the curve would look something like this:
But then you'd need to convert the value 'freq' to a value suitable for analogWrite();
The table you posted above specifies a VFD frequency, but you haven't defined a rule that converts a PWM duty cycle value to a VFD frequency.
Once you have that, the output curve shown in the graph is what math types called a 'piecewise linear function'. You can use a simple y=mx+b function to calculate the height of the line at any time, but the values of the constants 'm' and 'b' change at specific times.
The code to calculate the value of the curve would look something like this:
Code: Select all
float now = millis() / 1000.0;
float freq = 0;
// first slope
if ( now < 6 ) {
freq = 4.28 * now;
} else if ( now < 49 ) {
freq = ( 0.597 * ( now - 6 ) ) + 25.7;
} else if ( now < 64 ) {
freq = ( -3.425 * ( now - 49 ) ) + 51.375;
} else {
freq = 0;
}
- bdellal
- Posts: 51
- Joined: Tue Jun 10, 2014 6:00 pm
Re: Convert PWM to 0-10V
But the function on the end of my code does convert a frequency to a PWM duty cycle.
I did this so far:
The problem is, that the rest of my code is very complex. I'll attach it at the end of my post. My Arduino Mega has to deal with eight flow sensors, three thermocouples and a relay. I am not sure if I can use an interrupt for the speed control. Running it without an interrupt, the speedcontrol gives out setpoints not fast enough. Running just the speedcontrol skript is not smooth too, but acceptable.
What is your advice? And if using an interrupt would work, how can I implement it the best way?
I did this so far:
Code: Select all
unsigned long currentMillis = millis();
if((currentMillis - previousMillis) < 6000) {
setSpeed(4.28*(currentMillis - previousMillis)/1000);
}
if((currentMillis - previousMillis) > 6000 && (currentMillis - previousMillis) < 49000) {
setSpeed(0.597*((currentMillis - previousMillis)-6000)/1000+25.7);
}
if((currentMillis - previousMillis) > 49000 && (currentMillis - previousMillis) < 64000) {
setSpeed(-3.425*((currentMillis - previousMillis)-49000)/1000+51.375);
}
if((currentMillis - previousMillis) > 64000 && (currentMillis - previousMillis) < 67000) {
setSpeed(0);
}
if((currentMillis - previousMillis) >= 67000) {// reset the timer and start again
previousMillis = currentMillis;
cycles++;
}
}
void setSpeed(int freq)
{
float output = -4.7*freq+255;
if(output > 255)
output = 255;
else if(output < 0)
output = 0;
analogWrite(PWM_VFD, output);
}
What is your advice? And if using an interrupt would work, how can I implement it the best way?
Code: Select all
//Pump durability tester code
//includes:
//-thermal shutdown circuit
//-motor speed control via relay
//-pump flowrate monitoring
// include the library code for I2C and the LCD shield:
#include "Adafruit_MAX31855.h"
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); // this creates an LCD object that is controlled using the Adafruit library
//------------------INPUTS------------------------
float flowrate_delta = 5.0; //set maximum flow rate delta before tester stops
int max_cycles = 8710; //set program runtime in cycles. Every cycle is 62 seconds
//DATALOGGING---------------------------------------------------------------------------
// include the library code data logging shield:
#include <SD.h>
#include <SPI.h>
#include "RTClib.h"
RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
// the logging file
File logfile;
int32_t frequency = 35; //frequency (in Hz)
//DATALOGGING---------------------------------------------------------------------------
#define PIN_BUTTON 7 // connects to the ON/OFF button
#define THRESHOLD_TEMPERATURE_Reservoir1 80 // maximum oil temperature for normal operation
#define THRESHOLD_TEMPERATURE_Reservoir2 80 // maximum oil temperature for normal operation
#define THRESHOLD_TEMPERATURE_AMBIENT 60 // maximum ambient temperature for normal operation
#define Relay_STOP 40 // Relay control output
#define Relay1 42 // Relay speed1
#define Relay2 44 // Relay speed2
#define Relay3 46 // Relay speed3
#define Relay4 48 // Relay speed4
//Pins thermocouples
#define thermoDO 3 // Data out (shared)
#define thermoCS1 5 // Chip select for thermocouple 1
#define thermoCLK 2 // Clock (shared)
#define thermoCS2 6 // Chip select for thermocouple 2
#define thermoCS3 4 // Chip select for thermocouple 3
#define PWM_VFD 9
#define time double (millis()/1000)/60 // Program runtime.
long start_sequence_time = 15000; //time for the start sequence which fills the hoses with oil, appears only when program will start first time
long previousMillis = start_sequence_time+2000; //sets time used later in speed control, a 2000 millisecond addition is necessary(just tested out)
int failcounter = 0; //failcounter is a variable used in the flow rate safety shutdown
unsigned long currentFailMillis = 0; //variables used in the speedcontrol
long previousFailMillis = 0; //previouFailMillis is a timer variable used in the flow rate safety shutdown
//Thermocouples
Adafruit_MAX31855 thermocouple1(thermoCLK, thermoCS1, thermoDO);
Adafruit_MAX31855 thermocouple2(thermoCLK, thermoCS2, thermoDO);
Adafruit_MAX31855 thermocouple3(thermoCLK, thermoCS3, thermoDO);
unsigned long runtime = 0; //arduino runtime
int cycles = 0; //cycle = one profile run
//FLOWMETERS-------------------------------------------------------------------------------------
float flow_average = 0; //define average value of all flow rates
typedef struct Meter_t //define variables to calculate the flowrate counting the pulses of hall sensor
{
uint8_t pin; // pin meter is attached to the arduino
uint16_t pulses;
uint8_t lastflowpinstate; //was the pin high or low the last time
uint32_t lastflowratetimer;
float flowrate;
float wert; //variable used for the average filter of the values
float lmin; //variable that shows filtered flow rate in liters per minute
};
volatile Meter_t meters[] = { // Initialize meter array
{ 22, 0, 0, 0, 0.0 }, // meter 1: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
{ 24, 0, 0, 0, 0.0 }, // meter 2: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
{ 26, 0, 0, 0, 0.0 }, // meter 3: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
{ 28, 0, 0, 0, 0.0 }, // meter 4: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
{ 30, 0, 0, 0, 0.0 }, // meter 5: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
{ 32, 0, 0, 0, 0.0 }, // meter 6: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
{ 34, 0, 0, 0, 0.0 }, // meter 7: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
{ 36, 0, 0, 0, 0.0 } // meter 8: pin, pulses, lastflowpinstate, lastflowratetimer, flowrate
// add more meters as needed
};
#define NUM_METERS (sizeof(meters) / sizeof(Meter_t))
SIGNAL(TIMER0_COMPA_vect)
{
for (int m = 0; m < NUM_METERS; m++) //for loop for calculating the meters flowrate
{
uint8_t x = digitalRead(meters[m].pin);
if (x == meters[m].lastflowpinstate) {
meters[m].lastflowratetimer++;
}
else
{
if (x == HIGH) {
//low to high transition!
meters[m].pulses++;
}
meters[m].lastflowpinstate = x;
meters[m].flowrate = 1000.0;
meters[m].flowrate /= meters[m].lastflowratetimer; // flowrate calculated in hertz(pulses per second)
meters[m].lastflowratetimer = 0;
}
}
}
void useInterrupt(boolean v)
{
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
}
else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
}
//FLOWMETERS-------------------------------------------------------------------------------------
}
void setup()
{
Serial.begin(9600);
Serial.println("OCTOPUMPER");
lcd.begin(16, 2); // declare the number of columns and rows for the LCD:
//FLOWMETERS-------------------------------------------------------------------------------------
for (int m = 0; m < NUM_METERS; m++) //for loop reading the flow meters flowrate
{
pinMode(meters[m].pin, INPUT);
digitalWrite(meters[m].pin, HIGH);
meters[m].lastflowpinstate = digitalRead(meters[m].pin);
}
useInterrupt(true); /*use the interrupt of the Arduino to read the flowmeters, interrupts allow certain
important tasks to happen in the background and are enabled by default. Some functions
will not work while interrupts are disabled, and incoming communication may be ignored.
Interrupts can slightly disrupt the timing of code, however, and may be disabled for
particularly critical sections of code.*/
//FLOWMETERS-------------------------------------------------------------------------------------
pinMode(PIN_BUTTON, INPUT_PULLUP); //set button to pullup
pinMode(Relay_STOP, OUTPUT); //Relay which stops motor set as output
digitalWrite(Relay_STOP, LOW); //setting the relay LOW means closing it and in this case enabling the motor
lcd.setCursor(0,0);
lcd.print("Motor ON");
lcd.setCursor(0,1);
lcd.print("VFD Enabled");
//SPEEDCONTROL-------------------------------------------------------------------------------------
//setting up relays, the connect when the pin is set to LOW
pinMode(Relay1, OUTPUT); //relay one enables speed#1(36Hz = 4700rpm pump speed = 90mph vehicle speed) programmed in the Variable frequency drive
digitalWrite(Relay1, HIGH); //disconnect it
pinMode(Relay2, OUTPUT); //relay one enables speed#2 (2Hz needed for the flowmeters, flow shouldnt stop immediatly otherwise they wouldnt show 0 liters per minute) programmed in the Variable frequency drive
digitalWrite(Relay2, HIGH); //disconnect it
pinMode(Relay3, OUTPUT); //relay one enables speed#3 (0Hz to drain the pump to cause the critical piston stuck failure) programmed in the Variable frequency drive
digitalWrite(Relay3, HIGH); //disconnect it
pinMode(Relay4, OUTPUT); //relay one enables speed#3 (0Hz to drain the pump to cause the critical piston stuck failure) programmed in the Variable frequency drive
digitalWrite(Relay4, HIGH); //disconnect it
//SPEEDCONTROL-------------------------------------------------------------------------------------
//DATALOGGING--------------------------------------------------------------------------------------
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(53, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(10,11,12,13)) {
Serial.print("Card failed, or not present");
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
Serial.print("Logging to: ");
Serial.println(filename);
// connect to RTC(Real time clock)
Wire.begin();
logfile.println("Flowrate-1 [l/min],Flowrate-2 [l/min],Flowrate-3 [l/min],Flowrate-4 [l/min],Flowrate-5 [l/min],Flowrate-6 [l/min],Flowrate-7 [l/min],Flowrate-8 [l/min],Runtime Arduino[millis],Cycles,Temp Motor[C],Temp Oil_1[C],Temp Oil_2[C],Runtime Pumps[seconds]");
//DATALOGGING--------------------------------------------------------------------------------------
//STARTSEQUENCE-------------------------------------------------------------------------------------
// draws oil in the hoses so that the security flowrate stop doesn't stop the tester while starting, because some pumps are higher than others and need longer to create a flow
digitalWrite(Relay1, LOW);
Serial.print("Startsequence initialized");
delay(start_sequence_time); //startsequence time is set before setup
//STARTSEQUENCE-------------------------------------------------------------------------------------
pinMode(PWM_VFD, OUTPUT);
} //end of setup()
void loop()
{
if (digitalRead(PIN_BUTTON) == LOW){ //if loop starts the cycle only if button is on
digitalWrite(Relay_STOP, HIGH); // otherwise program will stay in this loop: motor not running
delay(100);
}
//thats where the usual operation loop function starts
else{
digitalWrite(Relay1, HIGH);
unsigned long loop_start_time = millis(); //keep time to calculate time pumps are really running
digitalWrite(Relay_STOP, LOW); //enable VFD and motor
//TIMEKEEPING---------------------------------------------------------------------------------------
// Serial.print("Cycles: "); Serial.println(cycles);
// Serial.println(" ");
//TIMEKEEPING---------------------------------------------------------------------------------------
//FLOWMETERS-------------------------------------------------------------------------------------
//define varaibles needed for safety shutdown when one pump fails, set to high and low values to make sure they will be overwritten and don't cause a failure in the first loop operation
float lmin_max = 0.0; //lmin means LITERS PER MINUTE
float lmin_min = 1000.0;
int pump_max = 99; //this will set to the pump that pumps the maximum amount of flow
int pump_min = 98; //this will set to the pump that pumps the maximum amount of flow
int failed_pump = 99;
float flow_sum = 0; //sum of all flowrates, used to calculate the average to figure out which of the pumps failed
//loop that calculates the actual flowrates in liters per minute
for (int m = 0; m < NUM_METERS; m++)
{
//average filter: measures 50 flowrates per meter and then takes the average of that to reduce the noise of the cheap flowmeters
int i;
meters[m].wert = 0;
for(i = 0; i < 50; i++) {
meters[m].wert += meters[m].flowrate;}
meters[m].wert /= 50;
meters[m].lmin = meters[m].wert;
meters[m].lmin *=0.12; //unit of "wert" now is pulses per second, one pulse is 2ml of fluid, so .12 converts it into liters per minute
flow_sum += meters[m].lmin; //sum calculation
if( meters[m].lmin > lmin_max){ //figuring out which pump has the highest flow rate and save it to variable
lmin_max = meters[m].lmin;
pump_max = m;
}
if (meters[m].lmin < lmin_min) //figuring out which pump has the lowest flow rate and save it to variable
{
lmin_min = meters[m].lmin;
pump_min = m;
}
if ((lmin_max - lmin_min) >= flowrate_delta) // program will go into pump fail mode when difference betweem min and max flow rate is greater than a certain value
{
failcounter = failcounter + 1; //counter starts counting when flowrate difference is higher than set value
currentFailMillis = millis(); //time when the difference is higher than allowed is saved
// Serial.println(failcounter);
}
/*if the delta doesn't rise over the set value for 20 seconds then the failcounter will be reset. All that is used to avoid false shutdowns because of
peaks appearing in a few milliseconds because of the inaccurate flow meters*/
if ((millis()-currentFailMillis) > 20000)
{
failcounter = 0;
// Serial.println("RESET");
}
if (failcounter >= 80) //if counter hits 80, what happens after 5 to 10 seconds of a higher delta than set value the program will go in this loop
{
digitalWrite(Relay_STOP, HIGH); //shuts motor down
Serial.println(" ");
Serial.println("Z"); // printing a "Z" on the Serial monitor tells the python script that runs on the laptop to send an e-mail that the tester failed
Serial.print(" ");
Serial.print("Failed Pumps:");
//next loop is meant to figure out which of the two potentially failed pumps(the one with the lowest and the one with the highest flow rate) actually failed
if((flow_average-lmin_min) > (flow_average-lmin_max)){
Serial.print(pump_min+1); //have to add a numbver because it starts at 0
Serial.print(" ");
logfile.println(" ");
logfile.print("Failed pump: ");
logfile.print("++ "); logfile.print(pump_min+1); logfile.print(" ++");
logfile.flush(); //flushing the SD card actually writes on the card
failed_pump= pump_min +1;
}
else{
Serial.print(pump_max+1); //have to add a numbver because it starts at 0
Serial.print(" ");
logfile.print("Failed pump: ");
logfile.print("++ "); logfile.print(pump_max+1); logfile.print(" ++");
logfile.flush();
failed_pump= pump_max +1;
}
unsigned long failtime = runtime; //saves the runtime of the program to a variable
Serial.print("Failed after Cycles:");
Serial.print(cycles);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Fail: ");
lcd.print(failed_pump);
lcd.setCursor(0,1);
lcd.print("Cycles: ");
lcd.print(cycles);
while(1) {} //Arduino stops working till it will be reset
}
// Serial.print("Meter ");
// Serial.print(m+1);
// Serial.print(" FLowrate in l/min: ");
// Serial.println(meters[m].lmin);
// Serial.println("");
logfile.print(meters[m].lmin); //logs flow rates of all meters to SD card
logfile.print(", ");
}
flow_average = flow_sum/ NUM_METERS;
//FLOWMETERS-------------------------------------------------------------------------------------
//SPEEDCONTROL-------------------------------------------------------------------------------------
unsigned long currentMillis = millis();
if((currentMillis - previousMillis) < 6000) {
setSpeed(4.28*(currentMillis - previousMillis)/1000);
}
if((currentMillis - previousMillis) > 6000 && (currentMillis - previousMillis) < 49000) {
setSpeed(0.597*((currentMillis - previousMillis)-6000)/1000+25.7);
}
if((currentMillis - previousMillis) > 49000 && (currentMillis - previousMillis) < 64000) {
setSpeed(-3.425*((currentMillis - previousMillis)-49000)/1000+51.375);
}
if((currentMillis - previousMillis) > 64000 && (currentMillis - previousMillis) < 67000) {
setSpeed(0);
}
if((currentMillis - previousMillis) >= 67000) {// reset the timer and start again
previousMillis = currentMillis;
cycles++;
}
//SPEEDCONTROL-------------------------------------------------------------------------------------
//TEMPMONITORING-----------------------------------------------------------------------------------
double temperatureAmbient = thermocouple1.readCelsius(); // read motor temperature from thermocouple
double temperatureReservoir1 = temperatureReservoir1 = thermocouple2.readCelsius();// read ambiant temperature from thermocouple
double temperatureReservoir2 = temperatureReservoir2 = thermocouple3.readCelsius();// read ambiant temperature from thermocouple
// Serial.print("Temperature Motor: ");
// Serial.print(temperatureAmbient); Serial.println(" C");
//
// Serial.print("Temperature Reservoir 1: ");
// Serial.print(temperatureReservoir1); Serial.println(" C");
//
// Serial.print("Temperature Reservoir 2: ");
// Serial.print(temperatureReservoir2); Serial.println(" C");
// Serial.println(" ");
lcd.setCursor(0,0); // display data on LCD
lcd.print("Motor:");
lcd.print(temperatureAmbient);
lcd.print(" C");
lcd.setCursor(0,1); // display data on LCD
lcd.print("Oil:");
lcd.print(temperatureReservoir1);
lcd.print(" & ");
lcd.print(temperatureReservoir2);
lcd.print(" C");
if (temperatureAmbient >= THRESHOLD_TEMPERATURE_AMBIENT) // if temperature is too high
{
digitalWrite(Relay_STOP, HIGH); // shut down Motor
// display warning on LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("T_Motor Limit Reached");
lcd.setCursor(0,1);
lcd.print("Cycles: ");
lcd.println(cycles);
Serial.println(" ");
Serial.println("Z");
while(1) {} // wait for reset
}
if (temperatureReservoir1 > THRESHOLD_TEMPERATURE_Reservoir1) // if temperature is too high
{
digitalWrite(Relay_STOP, HIGH); // shut down Motor
// display warning on LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("T_RES1 Limit Reached");
lcd.setCursor(0,1);
lcd.print("Cycles: ");
lcd.println(cycles);
Serial.println("Z");
while(1) {} // wait for reset
}
if (temperatureReservoir2 > THRESHOLD_TEMPERATURE_Reservoir2) // if temperature is too high
{
digitalWrite(Relay_STOP, HIGH); // shut down Motor
// display warning on LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("T_RES2 Limit Reached");
lcd.setCursor(0,1);
lcd.print("Cycles: ");
lcd.println(cycles);
Serial.println(" ");
Serial.println("Z");
while(1) {} // wait for reset
}
//TEMPMONITORING-----------------------------------------------------------------------------------
//PROGRAM RUNTIME---------------------------------------------------------------------------------------
if( cycles > max_cycles){
digitalWrite(Relay_STOP, HIGH);
while(1) {} // wait for reset
}
//PROGRAM RUNTIME---------------------------------------------------------------------------------------
//DATALOGGING--------------------------------------------------------------------------------------
unsigned long loop_end_time = millis();
unsigned long difference = loop_end_time - loop_start_time;
runtime = runtime + difference;
unsigned long runtime_seconds = runtime/1000;
// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
logfile.print(cycles); //cycles
logfile.print(", ") ;
logfile.print(temperatureAmbient);
logfile.print(", ");
logfile.print(temperatureReservoir1);
logfile.print(", ");
logfile.print(temperatureReservoir2);
logfile.print(", ");
logfile.println(runtime_seconds);
logfile.flush();
//DATALOGGING--------------------------------------------------------------------------------------
}
} // end of loop()
void setSpeed(int freq)
{
float output = -4.7*freq+255;
if(output > 255)
output = 255;
else if(output < 0)
output = 0;
analogWrite(PWM_VFD, output);
}
Please be positive and constructive with your questions and comments.