Skip to content
Snippets Groups Projects
Commit f08f69a2 authored by Your Name's avatar Your Name
Browse files

Modified johan's code for valve PWM testing

parent c93fc372
Branches
No related merge requests found
......@@ -29,7 +29,7 @@ Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
// Set Board to "ESP32 Dev Module"
// Set Port to /dev/ttyUSB0 on Linux
const int freq = 900; // 900 Hz for burkert 2875; Note - could be 500 Hz; depending on valve
const int freq = 500; // 900 Hz for burkert 2875; Note - could be 500 Hz; depending on valve
float duty_cycle = 0.0;
const float max_duty_cycle = 0.85;
......@@ -87,15 +87,17 @@ void setup() {
// NodeMCU32
// pwm
ledcSetup(0, freq, 8);
ledcSetup(1, freq, 8);
ledcSetup(1,2200,8); // buzzer frequency
//ledcSetup(1,2200,8); // buzzer frequency
//ledcAttachPin(pin_valve_o2_in , 0);
ledcAttachPin(pin_valve_inhale , 0);
ledcAttachPin(pin_valve_exhale , 1);
ledcAttachPin(buzzer , 1);
ledcWrite(1, 128); //buzzer
//ledcWrite(1, 128); //buzzer
pinMode(A13, INPUT); // potentiometer
......@@ -113,7 +115,7 @@ void setup() {
// Valves IO config
pinMode(pin_valve_air_in,OUTPUT);
pinMode(pin_valve_exhale,OUTPUT);
//pinMode(pin_valve_exhale,OUTPUT);
pinMode(pin_valve_purge,OUTPUT);
pinMode(pin_valve_o2_in,OUTPUT);
......@@ -125,13 +127,13 @@ void setup() {
digitalWrite(pin_valve_air_in, HIGH);
digitalWrite(pin_valve_exhale, LOW);
//digitalWrite(pin_valve_exhale, LOW);
digitalWrite(pin_valve_purge, LOW);
digitalWrite(pin_valve_o2_in, HIGH);
digitalWrite(redled, HIGH);
digitalWrite(yellowled, HIGH);
digitalWrite(greenled, HIGH);
//digitalWrite(redled, HIGH);
//digitalWrite(yellowled, HIGH);
//digitalWrite(greenled, HIGH);
DEBUG_PRINT("Hello");
Serial.println("Hello");
......@@ -185,46 +187,59 @@ void loop() {
duty_cycle = max_duty_cycle;
}
//Serial.print("Pot ");
//Serial.print(String((int)res));
//Serial.print(" p_patient ");
//Serial.print(String((int)pressure_patient));
//Serial.print(" p_buffer ");
//Serial.print(String((int)pressure_buffer));
//Serial.print(" p_as ");
//Serial.print(String((int)pressure_asupply));
//Serial.print(" p_ar ");
//Serial.print(String((int)pressure_aregulated));
//Serial.print(" p_inhale ");
//Serial.print(String((int)pressure_inhale));
//Serial.print(" p_o2s ");
//Serial.print(String((int)pressure_o2supply));
//Serial.print(" p_o2r ");
//Serial.print(String((int)pressure_o2regulated));
//Serial.print(" Temp: ");
//Serial.print(c, 4);
//// measuring Valves voltage and current
//Serial.print(" ");
//Serial.print((float)INA.getBusMilliVolts(0)/1000.0,4);
//DEBUG_PRINT("V ");
//DEBUG_PRINT2((float)INA.getShuntMicroVolts(0)/5,0);
//DEBUG_PRINT("mA ");
//DEBUG_PRINT2((float)INA.getShuntMicroVolts(1)/5,0);
//DEBUG_PRINT("mA ");
//DEBUG_PRINT2((float)INA.getShuntMicroVolts(2)/5,0);
//DEBUG_PRINT("mA ");
//DEBUG_PRINT2((float)INA.getShuntMicroVolts(3)/5,0);
//DEBUG_PRINT("mA ");
duty_cycle = 0.6;
int val = (int)(255.0*duty_cycle);
Serial.print("Pot ");
Serial.print(String((int)res));
Serial.print(" p_patient ");
Serial.print(String((int)pressure_patient));
Serial.print(" p_buffer ");
Serial.print(String((int)pressure_buffer));
Serial.print(" p_as ");
Serial.print(String((int)pressure_asupply));
Serial.print(" p_ar ");
Serial.print(String((int)pressure_aregulated));
Serial.print(" p_inhale ");
Serial.print(String((int)pressure_inhale));
Serial.print(" p_o2s ");
Serial.print(String((int)pressure_o2supply));
Serial.print(" p_o2r ");
Serial.print(String((int)pressure_o2regulated));
Serial.print(" Temp: ");
Serial.print(c, 4);
// measuring Valves voltage and current
Serial.print(" ");
Serial.print((float)INA.getBusMilliVolts(0)/1000.0,4);
DEBUG_PRINT("V ");
DEBUG_PRINT2((float)INA.getShuntMicroVolts(0)/5,0);
DEBUG_PRINT("mA ");
DEBUG_PRINT2((float)INA.getShuntMicroVolts(1)/5,0);
DEBUG_PRINT("mA ");
DEBUG_PRINT2((float)INA.getShuntMicroVolts(2)/5,0);
DEBUG_PRINT("mA ");
DEBUG_PRINT2((float)INA.getShuntMicroVolts(3)/5,0);
DEBUG_PRINT("mA ");
Serial.print(" duty cycle ");
Serial.println(String(duty_cycle));
ledcWrite(0, val);
delay(1000);
int vallow = (int)(255.0*0.1);
//Serial.print(" duty cycle ");
//Serial.println(String(duty_cycle));
//Serial.print(" raw val ");
//Serial.println(String(val));
digitalWrite(greenled, HIGH);
//ledcWrite(0, val);// inhale
ledcWrite(0, 0);//vallow);// exhale
delay(1000);
ledcWrite(0, 0);//val);// exhale
delay(200);
//ledcWrite(1, 0);// exhale
//digitalWrite(greenled, LOW);
//delay(1000);
}
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