Commit f37e9c9e authored by Sebastián Fernández's avatar Sebastián Fernández

Se agrega medicion de nivel durante irradiacion. Si no se llega a minimos...

Se agrega medicion de nivel durante irradiacion. Si no se llega a minimos durante calibracion o irradiacion, entra en estado erro dando un mensaje
parent dea12ff6
......@@ -81,10 +81,10 @@ por
/****************************************
* User parameters
****************************************/
#define version "Version 1.1"
#define version "Version 1.2"
// UV metering
const float target_dose = 2000; // mJ/cm2
const float target_dose = 2000; // 2000 mJ/cm2
const float min_percent_initial_adc = 0.45;
/****************************************
* Platform parameters
......@@ -116,7 +116,7 @@ const int tics_slow_blink = tics_per_sec ;
const int tics_slow_chime = tics_slow_blink * 6;
const int tics_fast_blink = tics_per_sec/2 ;
const int tics_fast_chime = tics_fast_blink * 3;
const int sec_wait_power_stabilization_period = 200;
const int sec_wait_power_stabilization_period = 200; //200
const int tics_wait_power_stabilization_period = tics_per_sec * sec_wait_power_stabilization_period;
volatile int tic = LOW;
......@@ -164,7 +164,7 @@ const int relay_pin = 2;
// EEPROM
#define ADD_UVC_SENSOR_PRESENT 0 // 1 is sensor present, 0 if not present
#define ADD_ADC_RAW_DEF 4 // store default radiation power (4 bytes)
#define ADD_ADC_RAW 8 // store last radiation power (4 bytes)
#define ADD_ADC_MIN 8 // store last radiation power (4 bytes)
#define ADD_ON_TIME 12 // store UVC_LIGHT_ON on minutes (4 bytes)
#define ADD_ON_CYCLE 16 // store UVC_LIGHT ON Cycles (4 bytes)
#define ADD_CAL_G 20 // address 3 and 4 store Calibration parameter 1 (4 bytes)
......@@ -173,12 +173,13 @@ const int relay_pin = 2;
int uvc_sensor_present;
float uvc_read_def;
float uvc_read_last;
float uvc_read_min;
float scale;
float offset;
// UV metering
float last_adc_value, new_adc_value;
float new_adc_value;
float min_adc_value_while_apply;
float radiation_power;
int total_desinfection_time; // seconds
int remaining_desinfection_time;
......@@ -186,7 +187,7 @@ int remaining_desinfection_time;
// States
enum State_enum {POWER_UP, CALIBRATE_WAIT, CALIBRATE_POWER, DOSE_CALCULATION, WAIT_TO_START, \
DOSE_APPLY, DOSE_END_NOTIFICATION, WAIT_UNLOAD, \
AL_DOOR_OPEN_WHEN_DOSE_APPLYING
AL_DOOR_OPEN_WHEN_DOSE_APPLYING, ERROR_POWER
};
uint8_t state = POWER_UP;
......@@ -271,6 +272,13 @@ void display_msg_7seg(const char *chars8) {
}
}
void display_clear() {
lcd.setCursor(0, 0);
lcd.print(" "); //
lcd.setCursor(0, 1);
lcd.print(" "); //
}
void display_calibration_unload() {
//76543210
// ToDo: 7 segment message
......@@ -300,6 +308,15 @@ void display_calibration_power(int value) {
lcd.print(" uW/cm2 "); //
}
void display_low_power(int value) {
lcd.setCursor(0, 0);
lcd.print("Err: Pot. baja "); //
lcd.setCursor(0, 1);
lcd.print("Pot.: "); //
lcd.print(value);
lcd.print(" uW/cm2 "); //
}
void display_calibration_warming(int value) {
//76543210
// ToDo: 7 segment message
......@@ -483,9 +500,9 @@ void setup() {
EEPROM.get(ADD_UVC_SENSOR_PRESENT,uvc_sensor_present);
Serial.println((String)"Sensor UVC presente : "+uvc_sensor_present);
EEPROM.get(ADD_ADC_RAW_DEF, uvc_read_def);
Serial.println((String)"default_radiation_power_raw : "+uvc_read_def);
EEPROM.get(ADD_ADC_RAW, uvc_read_last);
Serial.println((String)"stored radiation_power_raw : "+uvc_read_last);
Serial.println((String)"uvc_read_def : "+uvc_read_def);
EEPROM.get(ADD_ADC_MIN, uvc_read_min);
Serial.println((String)"stored uvc_read_min : "+uvc_read_min);
delay(20);
EEPROM.get(ADD_ON_TIME, fvar);
Serial.println((String)"minutes_on : "+fvar);
......@@ -546,7 +563,7 @@ switch(state)
DEBUGST_PRINT("state: POWER_UP");
if (uvc_sensor_present == 0){
radiation_power = calculate_radiation_power(uvc_read_last);
radiation_power = calculate_radiation_power(uvc_read_min);
state = DOSE_CALCULATION;
} else {
radiation_power = 0;
......@@ -555,7 +572,6 @@ switch(state)
load_detected = LOW;
tics_gral_passed = 0;
last_adc_value = 0;
new_adc_value = 0;
digitalWrite(alarm_ledr_pin, LOW);
......@@ -593,15 +609,20 @@ switch(state)
tics_gral_passed = 0;
new_adc_value = get_adc_read();
DEBUG_PRINT((String)"new_adc_value: " + new_adc_value);
radiation_power = calculate_radiation_power(new_adc_value);
display_calibration_power(radiation_power);
// stable if difference between read < 5%
state = DOSE_CALCULATION;
min_adc_value_while_apply = new_adc_value * min_percent_initial_adc;
if (new_adc_value < uvc_read_min) {
display_low_power(radiation_power);
mute_chime = LOW;
tics_gral_passed = 0;
state = ERROR_POWER;
} else {
display_calibration_power(radiation_power);
state = DOSE_CALCULATION;
}
} else {
tics_gral_passed += 1;
remaining_warmup_sec = ((tics_wait_power_stabilization_period - tics_gral_passed) / tics_per_sec);
......@@ -623,6 +644,7 @@ switch(state)
tics_on_passed = 0;
secs_on_passed = 0;
display_clear();
lc.clearDisplay(0);
display_power_time(displayPower,radiation_power);
......@@ -671,7 +693,8 @@ switch(state)
///////////////////////////////////////
case DOSE_APPLY:
DEBUGST_PRINT("state: DOSE_APPLY");
display_power_time(displayPower,radiation_power);
tics_on_passed += 1;
if (tics_on_passed >= tics_per_sec){
......@@ -683,6 +706,17 @@ switch(state)
if (secs_on_passed > 60){
secs_on_passed = 0;
new_adc_value = get_adc_read();
DEBUG_PRINT((String)"DOSE_APPLY, new_adc_value: " + new_adc_value);
if (new_adc_value < min_adc_value_while_apply) {
radiation_power = calculate_radiation_power(new_adc_value);
display_low_power(radiation_power);
mute_chime = LOW;
tics_gral_passed = 0;
state = ERROR_POWER;
}
// S.Fernandez: comentado pues da problemas al escribir a la eeprom
// update_time_on();
}
......@@ -701,7 +735,7 @@ switch(state)
digitalWrite(alarm_ledv_pin, LOW);
digitalWrite(alarm_ledr_pin, HIGH);
display_power_time(displayPower,radiation_power);
break;
......@@ -738,6 +772,7 @@ switch(state)
if(check_load_present()!=HIGH){ //
state = DOSE_CALCULATION;
display_clear();
}
tics_gral_passed += 1;
......@@ -757,7 +792,6 @@ switch(state)
state = DOSE_APPLY;
else if (check_load_present() != HIGH)
state = DOSE_CALCULATION;
if (check_button_pressed() == HIGH){ // espero que lo suelten
mute_chime = HIGH;
}
......@@ -778,5 +812,31 @@ switch(state)
display_msg_door();
break;
///////////////////////////////////////
case ERROR_POWER:
DEBUGST_PRINT("state: ERROR_POWER");
if (check_button_pressed() == HIGH){ // espero que lo suelten
mute_chime = HIGH;
}
tics_gral_passed += 1;
if ((tics_gral_passed % tics_fast_blink) == 0)
blink_led_state = !blink_led_state;
digitalWrite(alarm_ledr_pin, blink_led_state);
digitalWrite(alarm_ledv_pin, LOW);
if (tics_gral_passed >= tics_fast_chime)
{
tics_gral_passed = 0;
if (mute_chime == LOW)
sound_alarm();
}
break;
}
}
......@@ -8,6 +8,7 @@
* leer valores eeprom : e
* sensor uvc presente : u,presencia
* guardar lectura ADC : p,lectura_raw_adc
* guardar minimo ADC : n, minimo_raw_adc
* tiempo de encendido : t,minutos
* ciclos de encendido : c,ciclos
* calibracion scale : g,scale
......@@ -37,9 +38,10 @@
*
* v1.0 - 2020/07/08 : version inicial
* v1.1 - 2020/07/13 : no hay cambios, se aumenta version por cambios en uv)meter_arduino
* v1.2 - 2020/07/27 : ADD_ADC_RAW (ultimo valor ADC leido) se cambia por ADD_ADC_RAW_MIN *minimo valro aceptable paa funcionar)
*/
#define version "Version 1.1"
#define version "Version 1.2"
#include <EEPROM.h>
#include "LedControl.h" // 8 digit 7 segment. MAX
......@@ -88,8 +90,8 @@ LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,16,2)
// EEPROM
// define the number of byte needed
#define ADD_UVC_SENSOR_PRESENT 0 // 1 is sensor present, 0 if not present
#define ADD_ADC_RAW_DEF 4 // store default radiation power (4 bytes)
#define ADD_ADC_RAW 8 // store last radiation power (4 bytes)
#define ADD_ADC_RAW_DEF 4 // store default radiation power (4 bytes)
#define ADD_ADC_RAW_MIN 8 // store min radiation power (4 bytes)
#define ADD_ON_TIME 12 // store UVC_LIGHT_ON on minutes (4 bytes)
#define ADD_ON_CYCLE 16 // store UVC_LIGHT ON Cycles (4 bytes)
#define ADD_CAL_G 20 // address 3 and 4 store Calibration parameter 1 (4 bytes)
......@@ -109,7 +111,7 @@ float radiation_power;
int uvc_sensor_present;
float default_raw_adc_value;
float stored_raw_adc_value;
float min_raw_adc_value;
float stored_radiation_power;
float fminutes_on;
......@@ -117,6 +119,8 @@ int iminutes_on;
float fcycles_on;
bool recepcion_ok;
float ADCValueToRadiation(float adc_value)
{
return adc_value * scale + offset;
......@@ -203,6 +207,7 @@ if (Serial.available() > 0)
Serial.println("val. eeprom : e");
Serial.println("sensor uvc : u,presencia");
Serial.println("valor adc raw default : p,valor_adc ");
Serial.println("valor adc raw min : n,valor_adc ");
Serial.println("tiempo ON : t,minutos");
Serial.println("ciclos ON : c,ciclos");
Serial.println("scale : g,scale");
......@@ -237,7 +242,7 @@ if (Serial.available() > 0)
Serial.println("= com: minutos encendido =");
// formato mensaje: t,minutos
int minutos_on = 1;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -261,11 +266,11 @@ if (Serial.available() > 0)
Serial.println("= com: ciclos encendido =");
// formato mensaje: c,ciclos
int ciclos_on = 1;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
if (readString) {
if (readString != "") {
ciclos_on = round(readString.toInt());
Serial.print("Ciclos a grabar en EEPROM: ");
Serial.println(ciclos_on);
......@@ -285,7 +290,7 @@ if (Serial.available() > 0)
Serial.println("= com: presencia de sensor =");
// formato mensaje: u,presente
int sensor_presente;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -305,10 +310,10 @@ if (Serial.available() > 0)
if (inData[0] == 'p') //f
{
Serial.println("= com: setear valor ADC manualmente =");
Serial.println("= com: setear valor ADC default =");
// formato mensaje: p,valor_adc
float valor_adc = 1;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
//Serial.println(inData[j]);
readString += inData[j];
......@@ -318,9 +323,30 @@ if (Serial.available() > 0)
Serial.print("Valor ADC raw default a grabar en EEPROM: ");
Serial.println(valor_adc);
EEPROM.put(ADD_ADC_RAW_DEF, valor_adc);
Serial.print("Ultimo valor ADC leido a grabar en EEPROM: ");
recepcion_ok = true;
}
if (not recepcion_ok)
{
Serial.println("Incompleto");
}
}
if (inData[0] == 'n') //n
{
Serial.println("= com: setear valor ADC minimo =");
// formato mensaje: n,valor_adc
float valor_adc = 1;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
Serial.println(inData[j]);
readString += inData[j];
}
if (readString != "") {
valor_adc = (float)readString.toInt();
Serial.print("Ultimo valor ADC minimo a grabar en EEPROM: ");
Serial.println(valor_adc);
EEPROM.put(ADD_ADC_RAW, valor_adc);
EEPROM.put(ADD_ADC_RAW_MIN, valor_adc);
recepcion_ok = true;
}
......@@ -329,12 +355,12 @@ if (Serial.available() > 0)
Serial.println("Incompleto");
}
}
if (inData[0] == 'g') //g
{
Serial.println("= com: escalado de ADC a potencia =");
// formato mensaje: g,scale
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -356,7 +382,7 @@ if (Serial.available() > 0)
Serial.println("= com: calibracion offset =");
// formato mensaje: o,offset
//int offset_read = 1;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -379,7 +405,7 @@ if (Serial.available() > 0)
Serial.println("= com: led verde =");
// formato mensaje: v, estado
int estado = 0;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -401,7 +427,7 @@ if (Serial.available() > 0)
Serial.println("= com: led rojo = ");
// formato mensaje: r, estado
int estado = 0;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -423,7 +449,7 @@ if (Serial.available() > 0)
Serial.println("= com: relay ==");
// formato mensaje: r, estado
int estado = 0;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -446,7 +472,7 @@ if (Serial.available() > 0)
Serial.println("= com: buzzer =");
// formato mensaje: b, estado
int estado = 0;
bool recepcion_ok = false;
recepcion_ok = false;
for (int j = 2; j < indexData; j = j + 1) {
readString += inData[j];
}
......@@ -487,29 +513,29 @@ float showValuesInEEPROM(){
// Values from EEPROM
EEPROM.get(ADD_UVC_SENSOR_PRESENT,uvc_sensor_present);
EEPROM.get(ADD_ADC_RAW_DEF, default_raw_adc_value);
EEPROM.get(ADD_ADC_RAW, stored_raw_adc_value);
EEPROM.get(ADD_ADC_RAW_MIN, min_raw_adc_value);
EEPROM.get(ADD_ON_TIME, fminutes_on);
EEPROM.get(ADD_ON_CYCLE, fcycles_on);
EEPROM.get(ADD_CAL_G, scale);
EEPROM.get(ADD_CAL_O, offset);
Serial.print("Sensor UVC : ");
Serial.print("Sensor: ");
Serial.println(uvc_sensor_present);
Serial.print("default_raw_adc_value : ");
Serial.print("default adc: ");
Serial.println(default_raw_adc_value);
Serial.print("stored raw_adc_value : ");
Serial.println(stored_raw_adc_value);
Serial.print("min adc : ");
Serial.println(min_raw_adc_value);
Serial.print("scale : ");
Serial.println(scale);
Serial.print("offset : ");
Serial.println(offset);
Serial.print("minutes_on : " );
Serial.print("min_on : " );
Serial.println(fminutes_on);
Serial.print("cylces_on : ");
Serial.print("cyc_on : ");
Serial.println(fcycles_on);
Serial.print("P. default : ");
stored_radiation_power = ADCValueToRadiation(stored_raw_adc_value);
Serial.print("P.def : ");
stored_radiation_power = ADCValueToRadiation(default_raw_adc_value);
Serial.println(stored_radiation_power);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment