Permalink
Browse files

Version 1.5

-restructured code to allow for different IO cards
-added reflow profile support
-eliminated LCD flicker
-error message when thermocouple is disconnected
-extreme code size / RAM improvement (mainly menu and EEPRom)
-consolodated the code into fewer files
 * osPID_Firmware.ino - Just about everything
 * io.h - IO card code.  pre-compiler flags control which card code is used
 * EEPROMAnything.h - halley's amazing EEPROMWriteAnything code.
 * AnalogButton .cpp _local.h - ospid button-reading/debounce code
 * PID_AutoTune_v0 .cpp _local.h - local copy of the autotune library (to avoid
   conflicts with possibly pre-installed copies)
 * PID_v1 .ccp _local.h - local copy of the PID library
 * max6675 .cpp _local.h - local copy of the max6675 library, used by the input card.
  • Loading branch information...
1 parent 14bb605 commit da74de950a9373cf27363dbda216654383ef46f5 @br3ttb br3ttb committed Apr 15, 2012
Showing with 1,661 additions and 920 deletions.
  1. +0 −119 EEPROM.ino
  2. +20 −0 EEPROMAnything.h
  3. +19 −3 README.txt
  4. +0 −177 Serial.ino
  5. +406 −0 io.h
  6. +0 −421 menu.ino
  7. +1,216 −138 osPID_Firmware.ino
  8. +0 −48 pid.ino
  9. +0 −14 thermistor.ino
View
@@ -1,119 +0,0 @@
-void initializeEEPROM()
-{
- //read in eeprom values
- byte firstTime = EEPROM.read(0);
- if(firstTime!=1)
- {//the only time this won't be 1 is the first time the program is run after a reset.
- //initialize with default values
- eepromTunings.asFloats[0]=kp;
- eepromTunings.asFloats[1]=ki;
- eepromTunings.asFloats[2]=kd;
- eepromWindowSize.asLong = WindowSize;
-
- eepromATune.asFloats[0]=aTuneStep;
- eepromATune.asFloats[1]=aTuneNoise;
- eepromATune.asFloats[2]=aTuneLookBack;
-
- eepromThermistor.asFloats[0] = THERMISTORNOMINAL;
- eepromThermistor.asFloats[1] = BCOEFFICIENT;
- eepromThermistor.asFloats[2] = TEMPERATURENOMINAL;
- kp = 3;
- //put them into the eeprom for next time
- EEPROM.write(eepromTuningOffset, 0); //default action is DIRECT
- for(int i=0;i<12;i++)
- {
- EEPROM.write(eepromTuningOffset+i+1,eepromTunings.asBytes[i]);
- EEPROM.write(eepromATuneOffset+i,eepromATune.asBytes[i]);
- EEPROM.write(eepromThermistorOffset+i,eepromThermistor.asBytes[i]);
- }
- for(int i=0;i<4;i++)EEPROM.write(eepromWindowSizeOffset+i,eepromWindowSize.asBytes[i]);
- EEPROM.write(eepromIOTypeOffset,inputType);
- EEPROM.write(eepromIOTypeOffset+1,outputType);
-
- EEPROMBackupDash();
- EEPROMBackupOutput();
-
- EEPROM.write(0,1); //so that first time will never be true again
- }
- else
- {
- myPID.SetControllerDirection((int)EEPROM.read(eepromTuningOffset));
- for(int i=0;i<12;i++)
- {
- eepromTunings.asBytes[i] = EEPROM.read(eepromTuningOffset+i+1);
- eepromATune.asBytes[i] = EEPROM.read(eepromATuneOffset+i);
- eepromThermistor.asBytes[i] = EEPROM.read(eepromThermistorOffset+i);
- }
- for(int i=0;i<4;i++)eepromWindowSize.asBytes[i] = EEPROM.read(eepromWindowSizeOffset+i);
- inputType = EEPROM.read(eepromIOTypeOffset);
- outputType = EEPROM.read(eepromIOTypeOffset+1);
- kp = eepromTunings.asFloats[0];
- ki = eepromTunings.asFloats[1];
- kd = eepromTunings.asFloats[2];
-
- WindowSize = eepromWindowSize.asLong;
- outWindowSec = (double)WindowSize/1000;
- aTuneStep = eepromATune.asFloats[0];
- aTuneNoise = eepromATune.asFloats[1];
- aTuneLookBack = eepromATune.asFloats[2];
- THERMISTORNOMINAL = eepromThermistor.asFloats[0];
- BCOEFFICIENT = eepromThermistor.asFloats[1];
- TEMPERATURENOMINAL = eepromThermistor.asFloats[2];
-
- changeMode((int)EEPROM.read(eepromDashOffset));
- for(int i=0;i<8;i++)
- {
- eepromDash.asBytes[i] = EEPROM.read(eepromDashOffset+i+1);
- }
- setpoint = eepromDash.asFloats[0];
- output = eepromDash.asFloats[1];
- }
-}
-
-void EEPROMreset()
-{
- EEPROM.write(0,0);
-}
-
-void EEPROMBackupTunings()
-{
- EEPROM.write(eepromTuningOffset,ctrlDirection);
- eepromTunings.asFloats[0]=kp;
- eepromTunings.asFloats[1]=ki;
- eepromTunings.asFloats[2]=kd;
- for(byte i=0;i<12;i++)
- {
- EEPROM.write(eepromTuningOffset+i+1,eepromTunings.asBytes[i]);
- }
-}
-
-void EEPROMBackupIOParams()
-{
- EEPROM.write(eepromIOTypeOffset, inputType);
- EEPROM.write(eepromIOTypeOffset+1, outputType);
- eepromThermistor.asFloats[0] = THERMISTORNOMINAL;
- eepromThermistor.asFloats[1] = BCOEFFICIENT;
- eepromThermistor.asFloats[2] = TEMPERATURENOMINAL;
-
- for(byte i=0;i<12;i++)
- {
- EEPROM.write(eepromThermistorOffset+i,eepromThermistor.asBytes[i]);
- }
-}
-
-void EEPROMBackupDash()
-{
- EEPROM.write(eepromDashOffset, (byte)myPID.GetMode());
- eepromDash.asFloats[0] = setpoint;
- eepromDash.asFloats[1] = output;
- for(byte i=0;i<8;i++)
- {
- EEPROM.write(eepromDashOffset+i+1,eepromDash.asBytes[i]);
- }
-}
-
-void EEPROMBackupOutput()
-{
- eepromWindowSize.asLong = WindowSize;
- for(int i=0;i<4;i++)EEPROM.write(eepromWindowSizeOffset+i,eepromWindowSize.asBytes[i]);
-}
View
@@ -0,0 +1,20 @@
+#include <EEPROM.h>
+#include <Arduino.h> // for type definitions
+
+template <class T> int EEPROM_writeAnything(int ee, const T& value)
+{
+ const byte* p = (const byte*)(const void*)&value;
+ unsigned int i;
+ for (i = 0; i < sizeof(value); i++)
+ EEPROM.write(ee++, *p++);
+ return i;
+}
+
+template <class T> int EEPROM_readAnything(int ee, T& value)
+{
+ byte* p = (byte*)(void*)&value;
+ unsigned int i;
+ for (i = 0; i < sizeof(value); i++)
+ *p++ = EEPROM.read(ee++);
+ return i;
+}
View
@@ -1,6 +1,22 @@
/********************************************************
- * osPID Firmware, Version 0.0
+ * osPID Firmware, Version 1.5
* by Brett Beauregard & Rocket Scream
* License: GPLv3 & BSD License (For autotune)
- * February 2012
- ********************************************************/
+ * April 2012
+ ********************************************************/
+
+Updates for version 1.5
+-restructured code to allow for different IO cards
+-added reflow profile support
+-eliminated LCD flicker
+-error message when thermocouple is disconnected
+-extreme code size / RAM improvement (mainly menu and EEPRom)
+-consolodated the code into fewer files
+ * osPID_Firmware.ino - Just about everything
+ * io.h - IO card code. pre-compiler flags control which card code is used
+ * EEPROMAnything.h - halley's amazing EEPROMWriteAnything code.
+ * AnalogButton .cpp _local.h - ospid button-reading/debounce code
+ * PID_AutoTune_v0 .cpp _local.h - local copy of the autotune library (to avoid
+ conflicts with possibly pre-installed copies)
+ * PID_v1 .ccp _local.h - local copy of the PID library
+ * max6675 .cpp _local.h - local copy of the max6675 library, used by the input card.
View
@@ -1,177 +0,0 @@
-/********************************************
- * Serial Communication functions / helpers
- ********************************************/
-
-
-union { // This Data structure lets
- byte asBytes[24]; // us take the byte array
- float asFloat[6]; // sent from processing and
-} // easily convert it to a
-foo; // float array
-
-
-
-// getting float values from processing into the arduino
-// was no small task. the way this program does it is
-// as follows:
-// * a float takes up 4 bytes. in processing, convert
-// the array of floats we want to send, into an array
-// of bytes.
-// * send the bytes to the arduino
-// * use a data structure known as a union to convert
-// the array of bytes back into an array of floats
-void SerialReceive()
-{
-
- // read the bytes sent from Processing
- int index=0;
- byte Auto_Man = -1;
- byte Direct_Reverse = -1;
- byte ATune = -1;
- byte resetFlag=-1;
- byte iType=-1, oType=-1;
- int identifier=0;
-
-
- while(Serial.available())
- {
- byte val = Serial.read();
- if(index==0) identifier = val;
- else if(identifier==1) //general
- {
- if(index==1) Auto_Man = val;
- else if (index<14) foo.asBytes[index-2] = val;
- }
- else if(identifier==2)//Tunings
- {
- if(index==1) Direct_Reverse = val;
- else if(index<14)foo.asBytes[index-2] = val;
- }
- else if(identifier==3)//Auto Tune
- {
- if(index==1) ATune = val;
- else if(index<14)foo.asBytes[index-2] = val;
- }
- else if(identifier==4)//EEPROM reset
- {
- if(index==1) resetFlag = val;
- }
- else if(identifier==5) //config set
- {
- if(index==1) iType = val;
- else if(index==2) oType= val;
- else if(index<19) foo.asBytes[index-3] = val;
- }
- index++;
- }
-
- // if the information we got was in the correct format,
- // read it into the system
- if(identifier==1 && index==14 && (Auto_Man==0 || Auto_Man==1))
- {
- setpoint=double(foo.asFloat[0]);
- //Input=double(foo.asFloat[1]); // * the user has the ability to send the
- // value of "Input" in most cases (as
- // in this one) this is not needed.
- if(Auto_Man==0) // * only change the output if we are in
- { // manual mode. otherwise we'll get an
- output=double(foo.asFloat[2]); // output blip, then the controller will
- } // overwrite.
-
- if(Auto_Man==0) myPID.SetMode(MANUAL);// * set the controller mode
- else myPID.SetMode(AUTOMATIC); //
-
- EEPROMBackupDash();
-
- serialAcknowledge=1;
-
- }
- else if(identifier==2 && index==14 && (Direct_Reverse==0 || Direct_Reverse==1))
- {
- // * read in and set the controller tunings
- kp = double(foo.asFloat[0]); //
- ki = double(foo.asFloat[1]); //
- kd = double(foo.asFloat[2]); //
- ctrlDirection = Direct_Reverse;
- myPID.SetTunings(kp, ki, kd); //
- if(Direct_Reverse==0) myPID.SetControllerDirection(DIRECT);// * set the controller Direction
- else myPID.SetControllerDirection(REVERSE); //
- EEPROMBackupTunings();
- serialAcknowledge=2;
- }
- else if(identifier==3 && index==14 && (ATune==0 || ATune==1))
- {
-
- aTuneStep = foo.asFloat[0];
- aTuneNoise = foo.asFloat[1];
- aTuneLookBack = (unsigned int)foo.asFloat[2];
- if((!tuning && ATune==1)||(tuning && ATune==0))
- { //toggle autotune state
- changeAutoTune(0);
- }
- serialAcknowledge=3;
- }
- else if(identifier==4 && index==2 && (resetFlag==0||resetFlag==1))
- {
- EEPROMreset();
- serialAcknowledge=4;
- }
- else if(identifier==5 && index==19 && (iType==0 || iType==1 || iType==2) && (oType==0 || oType==1))
- {
- inputType = iType;
- if(outputType != oType)
- {
- if (oType==0)digitalWrite(SSRPin, LOW);
- else if(oType==1) digitalWrite( RelayPin,LOW); //turn off the other pin
- outputType=oType;
- }
- digitalWrite(2, (inputType==2 ? true : false));
- THERMISTORNOMINAL = foo.asFloat[0];
- BCOEFFICIENT = foo.asFloat[1];
- TEMPERATURENOMINAL = foo.asFloat[2];
- outWindowSec = foo.asFloat[3];
- EEPROMBackupIOParams();
- setOutputWindow(outWindowSec);
- serialAcknowledge=5;
- }
-
-
- Serial.flush(); // * clear any random data from the serial buffer
-}
-
-// unlike our tiny microprocessor, the processing ap
-// has no problem converting strings into floats, so
-// we can just send strings. much easier than getting
-// floats from processing to here no?
-
-union { // This Data structure lets
- byte asBytes[36]; // us take the byte array
- float asFloat[9]; // sent from processing and
-} // easily convert it to a
-sender;
-
-void SerialSend()
-{
- Serial.print("PID1 ");
- Serial.print(setpoint); Serial.print(" ");
- Serial.print(input); Serial.print(" ");
- Serial.print(output); Serial.print(" ");
- Serial.print(myPID.GetKp()); Serial.print(" ");
- Serial.print(myPID.GetKi()); Serial.print(" ");
- Serial.print(myPID.GetKd()); Serial.print(" ");
- Serial.print(aTuneStep); Serial.print(" ");
- Serial.print(aTuneNoise); Serial.print(" ");
- Serial.print(aTuneLookBack); Serial.print(" ");
- Serial.print(THERMISTORNOMINAL); Serial.print(" ");
- Serial.print(BCOEFFICIENT); Serial.print(" ");
- Serial.print(TEMPERATURENOMINAL); Serial.print(" ");
- Serial.print(outWindowSec); Serial.print(" ");
- Serial.print((int)inputType); Serial.print(" ");
- Serial.print((int)outputType); Serial.print(" ");
- Serial.print(myPID.GetMode()); Serial.print(" ");
- Serial.print(myPID.GetDirection()); Serial.print(" ");
- Serial.print(tuning?1:0); Serial.print(" ");
- Serial.println((int)serialAcknowledge);
- serialAcknowledge=0;
-}
-
Oops, something went wrong.

0 comments on commit da74de9

Please sign in to comment.