Hello All,
I've been looking through this site for a while now to help me out with various projects and the old posts have been immensely helpful. I have a new problem that I have been fighting by myself for about a month and a half now and i am no closer to figuring it out than when i started. Unfortunately my programming is self taught and more than likely a little rough. It works, for the most part, but after about 4-12 hours of running the program just freezes. No serial updates, nothing. (This is bad because it is controlling an oven, so if it freezes with the oven on, well you guess what happens). I do have a temperature cutout to prevent any catastrophic run-aways.
I first thought that my power supply was noisy, but i have tried many including a $2000 lab grade DC power supply. I thought it might be my arduino board, i was using a Ocean Controls KTA-223 board, switched to a genuine arduino uno with a transistor shield Link and some externally powered relays and it ran for a week and a half straight. I thought great, its fixed. But it just started acting up again a week ago and now it cant run 4 hours or so without freezing.
The only constant hardward are two Sparkfun MAX31855K Thermocouple boards Link and one sparkfun ACS723 current monitor. Link I am using the adafruit MAX31855K library (Because it allows me to select a chip and use the same data lines), and the sparkfun ACS723 just runs off an analog input.
I am almost certain it is not a hardware issue, because everything but the above chips have changed with the same result. The way the serial monitor prints, it makes me think there is memory issues, either stuff being overwritten, or just running out of ram. I do not know enough about that side of programming though. I have added the F macro to some constant serial prints to move then to flash memory instead of SRAM. Its not a big program so i cant picture why im running out of anything...
Any help here would be great! Post 2 will follow up with photos.
/*
Measuring AC Current Using ACS712, Measuring Temperature with Sparkfun MAX31855
*/
#include "Adafruit_MAX31855.h" // Using the max31855k driver
#include <SPI.h>
int MAXCLK = 13; //TC Clock Pin
int MAXCS = 10; // TC 1 Chip Select Pin
int MAXCS2 = 11; // TC 2 Chip Select Pin
int MAXDO = 12; //TC data out pin
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO); //Define pins per Adafruit Library
Adafruit_MAX31855 thermocouple2(MAXCLK, MAXCS2, MAXDO); //Define pins per Adafruit Library
float temp = 0; //Variable for TC 1 data
float temp2 = 0; //Variable for TC 2 data
const int sensorIn = A2; //Current sensor Analog input
int mVperAmp = 410; //Trim variable to make voltage to current calcs correct
double Voltage = 0; //Voltage variable for current monitor (It reads a voltage and converts to current)
double VRMS = 0; //Voltage variable for current monitor after converting to RMS
double AmpsRMS = 0; //current value through thermal links DUT
int settemp = 110; //SET OPERATING TEMPERATURE //SET OPERATING TEMPERATURE //SET OPERATING TEMPERATURE //SET OPERATING TEMPERATURE //SET OPERATING TEMPERATURE //SET OPERATING TEMPERATURE //SET OPERATING TEMPERATURE //SET OPERATING TEMPERATURE
int heaterrelay = 3; //oven relay controller through transistor shield
int loadrelay = 6; // load is circuit inside oven with 2.0A on it with thermal links i am testing
int indicatorrelay = 5; //indicator is an LED strip to indicate a thermal link has failed
double loadcurrent = 0.2; //highest current in error state, anything higher will function normally
int settemp2 = settemp - 4; //temp trim to reduce setpoint 4 degrees
int settemp3 = settemp - 4; //temp trim to reduce setpoint 4 degrees
int once = 0;
long previousMillis = 0;
void setup() {
Serial.begin(9600);
pinMode(heaterrelay, OUTPUT);
pinMode(loadrelay, OUTPUT);
pinMode(indicatorrelay, OUTPUT);
delay(3000);
}
void loop() {
runprogram(); //(Should) Run for 3 days
cooldown(); // Cools oven for 12 hours
}
void cooldown() { //12 hour off time
unsigned long currentMillis = millis();
unsigned long StartTime = millis();
while (millis() - currentMillis < 43200000) {
previousMillis = currentMillis;
unsigned long CurrentTime = millis();
}
Serial.println(F("12 Hour Delay Complete"));
}
void runprogram() { //run for 3 days
unsigned long currentMillis = millis();
while (millis() - currentMillis < 259200000) {
//Serial.println("Back to the beginning...");
temp = gettemp();
temp2 = gettemp2();
while (temp2 > settemp + 16) {//brick temp overshoot
Serial.print(F("OVEN TOO HOT: "));
Serial.println(temp2);
stoprun10();
temp2 = gettemp2();
}
if (temp < settemp3) {
// Serial.print("Load on ");
digitalWrite(loadrelay, HIGH);
//Serial.print("Before Delay ");
delay(500);
// Serial.println("After Delay");
Voltage = getVPP();
//Serial.print(":1");
VRMS = ((Voltage - 0.07) / 2.0) * 0.707;
//Serial.print(":2 ");
AmpsRMS = ((VRMS * 1000) / mVperAmp);
Serial.print(AmpsRMS);
Serial.println(" Amps RMS");
while (AmpsRMS < loadcurrent) {
if (once == 0) {
Serial.println(F("LINK BROKEN"));
once = 1;
}
digitalWrite(heaterrelay, LOW);
digitalWrite(indicatorrelay, HIGH);
delay(1000);
digitalWrite(indicatorrelay, LOW);
digitalWrite(loadrelay, HIGH);
delay(1000);
Voltage = getVPP();
Serial.println(F(""));
VRMS = ((Voltage - 0.07) / 2.0) * 0.707;
AmpsRMS = ((VRMS * 1000) / mVperAmp);
digitalWrite(loadrelay, LOW);
}
once = 0;
digitalWrite(heaterrelay, HIGH);
stoprun5();
digitalWrite(loadrelay, LOW);
digitalWrite(heaterrelay, LOW);
}
digitalWrite(heaterrelay, LOW);
digitalWrite(loadrelay, LOW);
stoprun10();
}
Serial.println(F("3 Day Run Time Complete; Starting 12 Hour Cool Down."));
}
void stoprun5() {
Serial.print(F("5 Second Oven On Time START"));
unsigned long currentMillis = millis();
while (millis() - currentMillis < 5000) {
}
Serial.println(F("---> COMPLETE"));
}
void stoprun10() {
Serial.println(F("10 Second Oven OFF Time START"));
delay(1000);
unsigned long currentMillis = millis();
static unsigned long lastRefreshTime = 0;
while (millis() - currentMillis < 9000) {
if (millis() - lastRefreshTime >= 5000)
{
lastRefreshTime += 5000;
temp = gettemp();
temp2 = gettemp2();
Serial.print("TemP1[C]=");
Serial.print(temp);
Serial.print(" TemP2[C]=");
Serial.println(temp2);
}
}
Serial.println(F("---> COMPLETE"));
}
double getVPP() {
// Serial.print(F("IntoVPPLoop "));
double result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
Serial.print(F("Checking Load Current"));
uint32_t start_time = millis();
while ((millis() - start_time) < 1000) //sample for 1 Sec
{
readValue = analogRead(sensorIn);
if (readValue > maxValue)
{
maxValue = readValue;
}
if (readValue < minValue)
{
minValue = readValue;
}
}
result = ((maxValue - minValue) * 5.0) / 1024.0;
Serial.print(F(":"));
return result;
}
float gettemp()
{
MAXCS = 0;
double c1 = thermocouple.readCelsius();
MAXCS = 1;
c1 = c1 - 3.5; //temp trim
return c1;
}
float gettemp2()
{
MAXCS2 = 0;
double c2 = thermocouple2.readCelsius();
MAXCS2 = 1;
c2 = c2 - 3.5; //temp trim
return c2;
}[\code]