Declarations of the sketch

 

In the sketch, I use the following declarations:

 

#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include "Adafruit_AD569x.h"
#include "Adafruit_ADS1X15.h"
#include <Adafruit_TMP117.h>
#include <Adafruit_Sensor.h>
#include <math.h>
#include <Wire.h>

 

LiquidCrystal_I2C lcd(0x27,20,4);

 

uint8_t ADDR_Bliley = 0x48; //adr pin to GND
uint8_t ADDR_Case = 0x49; //addr pin to VCC
uint8_t ADDR_Box = 0x4A; //addr pin to SDA

 

Adafruit_TMP117 tmp117Bliley;
Adafruit_TMP117 tmp117Box;
Adafruit_TMP117 tmp117Case;

 

float Temp_Bliley = 00.00;
float Temp_Bliley_IIR_Filtered = 20.00;
float Temp_Box = 00.00;
float Temp_Box_ref = 28.00;
float Temp_Box_IIR_Filtered = 20.00;
float Temp_Case = 00.00;
float Temp_Case_ref = 28.00;
float Temp_Case_IIR_Filtered = 20.00;


int IIR_Filter_Weight = 3; // IIC filter weight value
// paulv: IIR filter for the temperature sensors
// avg = avg + ((new_value - avg) / filter_weight)

 

//AD5693 I2C address is 0x4c (76)
Adafruit_AD569x ad5693;            //create an object for the adafruit AD5693 DAC library
#define AddrDAC 0x4C

 

//ADS1115 I2C address is 0x4B Address pin to SCKL
Adafruit_ADS1115 ads1115; //create an object for the adafruit ADS1115 ADC library
#define AddrADC 0x4B
//int16_t adc3; gebruiken we nu TIC_Value voor

float Volt3;

// paulv: added a decharge for C1 after the ADC read cycle
const int decharge = 10; // Decharge pin for C1. Port is toggled between hi-Z input and output driven low
const int screen_State_button = 2;
bool screen_State_button_value = false;
int screen_State = 0;
volatile boolean PPS_ReadFlag = false; // set true every time pps is received
volatile int TIC_Value_raw;
volatile float TIC_Value_scaled;
volatile int TIC_Value; // analog read 0 - time value. About 1ns per bit with 3.7kohm+1nF MOET AANGEPAST WORDEN
int TIC_ValueOld;//old not filtered TIC_value
int TIC_Offset = 500; // ADC value for Reference time
long TIC_ValueFiltered; // prefiltered TIC value
long TIC_ValueFilteredOld;// old filtered value
long TIC_ValueFilteredForPPS_lock; // prefiltered value just for PPS lock
volatile unsigned int timer1CounterValue = 0; //counts 5MHz clock modulo 50000
long timer1CounterValueOld = 0;
volatile signed int timer1CounterValue_diff = 0;

long timer_us; // timer1 value in microseconds offset from 1pps
long timer_us_old; // used for diff_ns
long diff_ns; // difference between old and new TIC_Value
long diff_ns_ForPPS_lock; // prefiltered value just for PPS lock

const int PWM_FAN_Box = 6; //PWM-out pin for FAN speed cooling VCO box
int FAN_Box_Value = 0; //Value of the Box_FAN
//const int PWM_FAN_Case = 9; //PWM-out for FAN speed cooling Arduino case pin 9 doet het niet, is dacht ik gebruikt voor iets anders intern ??
const int PWM_FAN_Case = 6;
int FAN_Case_Value = 0;
int FAN_Case_Value_Max = 200;
int FAN_Case_Value_Min = 0;
const int PWM_Heater_Box = 3; //geschakelde 10 Ohm weerstand. Kan max 2,5 Watt leveren bij 5 Volt
int Heater_Box_Value = 0; // Bij 0 Volt heater uit
int Heater_Box_Value_Max = 80;
int Heater_Box_Value_Min = 10;
const int PWM_Heater_Case = 11;
int Heater_Case_Value = 0;
int Heater_Case_Value_Max = 80;
int Heater_Case_Value_Min = 10;

long tempCoeff = 0;
long dacValueOut = 37375; // 16bit PWM-DAC setvalue=startvalue Max 65535 (if nothing stored in the EEPROM)
long dacValue = 39500; // this is also same as "DACvalueOld" Note: is "0-65535" * timeconst
long dacValue2 = 39000; // had to add this for calculation in PI-loop
long dacValueWithTempComp = 0; // Note: is "0-65535" * timeconst
//const int dacOutputPin = 3; // DAC pin (connected to 39k)
unsigned int TCNT1new = 0;//in main loop
unsigned int TCNT1old = 0;
unsigned long overflowCount = 0; // counter for timer1 overflows

long timeConst = 25; // Time constant in seconds; default 25
long timeConstOld = 25; // old Time constant
int filterDiv = 2; // filterConst = timeConst / filterDiv
long filterConst = 16; // pre-filter time const in secs (TIC-filtering)
long filterConstOld = 16; // old Filter time constant

float I_term; //for PI-loop
float P_term;
long I_term_long;
float I_term_remain;

long gain = 225; //PE0MJX Bliley with R109 = 330k, t(ime constant) = ?????
float damping = 4.0; //Damping in loop

unsigned long time; //seconds since start
unsigned long timeOld; //last seconds since start
unsigned int missedPPS; // incremented every time pps is missed
unsigned long timeSinceMissedPPS;

int lockPPSlimit = 100; // if TIC filtered for PPS within +- this for lockPPSfactor * timeConst = PPSlocked
int lockPPSfactor = 5; // see above
unsigned long lockPPScounter; // counter for PPSlocked
boolean PPSlocked; //digital pin 13 and prints 0 or 1
boolean PPSlockedOld;

unsigned int ID_Number;

//int skip_first = 1;
//uint16_t countertje = 0;
//unsigned long myTime1;
//unsigned long myTime2;
//unsigned long currentTime = micros();
const int ppsLockedLED = 13; // LED pin for pps locked
const int testpin = 12;
int i; // counter for 300secs before storing temp and dac readings average
int j; // counter for stored 300sec readings
int k; // counter for stored 3hour readings
boolean restartFlag = true;

boolean lessInfoDisplayed;
boolean nsDisplayedDecimals;

// for get command
int incomingByte; // for incoming serial data in getCommand
enum Modes {hold, run};
Modes opMode = run; //operating mode
Modes newMode = hold; // used to reset timer_us when run is set and at to many missing PPS
unsigned int holdValue; //DAC value for Hold mode

float ADC_corr_Factor = 4096.0/(4*5390.0);

// for TIC linearization
float TICmin = 12.0;
float TICmax = 1012.0;
float x3 = 0.03;
float x2 = 0.1;
float x1;
float TIC_Scaled;
float TIC_ValueCorr;
float TIC_ValueCorrOld;
float TIC_ValueCorrOffset;
int p = 0; //tellertje voor wat te printen
int random_variable = 0;
int TC_Box = 0;
int EEPROM_length = EEPROM.length();
//char screen_0[] = "Screen 0";
//char screen_2[] = "Screen 2";
//char screen_3[] = "Screen 3";
//char screen_4[] = "Screen 4";
////////////////////////////////////////////////////////////////////////////////////////////////
// Timer1 capture interrupt routine - this runs at rising edge of 1PPS on D8
// paulv: **** modified to add a digital decharge of C1

ISR (TIMER1_CAPT_vect) //TIMER1_CAPT_vect means that timer1 16 bits counter will use this vector
// meaning that the timer captures events on a D port (in our case D5)
{
timer1CounterValue = ICR1; // read the captured timer1 200ns counter value.
//The timer module will be free running all the time, and its value (TCNTx)
//is captured and saved into the input capture register (ICRx) immediately
//when the input capture pin state has changed. This is like taking a time
//stamp from the running timer at certain pin state change events (on the ICPn pin).

PPS_ReadFlag = true;

}

// end declarations

////////////////////////////////////////////////////////////////////////////////////////////////