Commit 322c14c9 authored by Philippe Kalaf's avatar Philippe Kalaf

Implemented pressure setting and auto-pressure adjust for auto-time and auto-volume modes

Calibrated pressure transducer
parent 74ecc5be
......@@ -59,6 +59,12 @@ BrewControl::BrewControl( PinName brew_pin,
// let's start at 93 C
_target_shot_temperature = 93;
// 9 bars is default
_target_shot_pressure = 9;
_boiler_pid.setPIDGains(0.075, 0.1, 0.9);
_boiler_pid.setIntegratorLimits(0, 1);
// Boiler is on by default
enable_boiler();
}
......@@ -96,11 +102,19 @@ float BrewControl::get_shot_temperature()
return _target_shot_temperature;
}
void BrewControl::set_shot_pressure(float pressure)
{
if(pressure <= 0)
_target_shot_pressure = 0;
else if(pressure >= 12)
_target_shot_pressure = 12;
_target_shot_pressure = pressure;
}
// Return pressure in bars
float BrewControl::get_current_pressure()
{
return float(_pressure_sensor.read_pa())/100000;
return _pressure_sensor.read_bars();
}
int BrewControl::get_shot_volume()
......@@ -160,14 +174,14 @@ bool BrewControl::toggle_boiler()
return _enable_boiler;
}
void BrewControl::pressure_up()
void BrewControl::pressure_up(uint8_t value)
{
_pump_control.level_up();
_pump_control.level_up(value);
}
void BrewControl::pressure_down()
void BrewControl::pressure_down(uint8_t value)
{
_pump_control.level_down();
_pump_control.level_down(value);
}
// pre-infuse time in seconds
......@@ -251,16 +265,31 @@ void BrewControl::brew_worker()
_pump_control.set_level(_prev_pressure);
_shot_clock = 0;
_flow_sensor.reset_count();
_state = BREWING;
}
}
else if(_mode == MODE_TIME)
{
// Auto-adjust pressure to target
float error = _target_shot_pressure - get_current_pressure();
if(error < -0.25)
pressure_down();
else if(error > 0.25)
pressure_up();
if(_shot_clock >= _target_shot_time)
soft_stop();
}
}_target_shot_pressure - get_current_pressure()
else if(_mode == MODE_VOLUME)
{
if(_flow_sensor.read() >= _target_shot_volume)
// Auto-adjust pressure to target
float error = _target_shot_pressure - get_current_pressure();
if(error < -0.25)
pressure_down();
else if(error > 0.25)
pressure_up();
if(_flow_sensor.read() >= _target_shot_volume)
soft_stop();
}
else if(_mode == MODE_PRESSURE)
......
......@@ -84,16 +84,21 @@ public:
float get_current_volume();
/// Set the target shot flow rate in ml/s
void set_target_flow_rate(float flow_rate);
void set_shot_flow_rate(float flow_rate);
/// Get the target shot flow rate in ml/s
float get_target_flow_rate();
float get_shot_flow_rate();
/// Get the live shot flow rate in ml/s
float get_current_flow_rate();
/// Set the target pressure in bars
void set_shot_pressure(float pressure);
/// Get the target pressure in bars
float get_shot_pressure();
/// Get the current measured pressure in bars
float get_current_pressure();
void pressure_up();
void pressure_down();
void pressure_up(uint8_t value = 1);
void pressure_down(uint8_t value = 1);
/// Get the currently set pump level (0 to 100%)
uint8_t get_pump_level();
......@@ -151,6 +156,8 @@ private:
int _target_shot_time;
int _target_shot_volume;
float _target_shot_temperature;
float _target_flow_rate;
float _target_shot_pressure;
// Operating modes
uint8_t _state;
......
......@@ -116,7 +116,7 @@ const char* MENU_TITLES[5]= {
};
const uint8_t MENU_ITEMS[NUM_BREW_MENUS][5]= {
{1, 3, TEMPERATURE, PRE_INFUSE_TIME, FLOW_RATE},
{1, 3, TEMPERATURE, PRE_INFUSE_TIME, PRESSURE},
{1, 1, SHOT_TIME, EMPTY, EMPTY},
{1, 1, YIELD, EMPTY, EMPTY},
{1, 2, YIELD, SHOT_TIME, EMPTY}
......@@ -177,8 +177,12 @@ void set_params(uint8_t menu_id)
case TEMPERATURE: brew_control.set_shot_temperature(
brew_params[menu_id][0][i]);
break;
case FLOW_RATE: break;
case PRESSURE: break;
case FLOW_RATE: brew_control.set_shot_flow_rate(
float(brew_params[menu_id][0][i]/10));
break;
case PRESSURE: brew_control.set_shot_pressure(
brew_params[menu_id][0][i]);
break;
}
}
}
......@@ -382,7 +386,7 @@ void menu_handler()
edit_mode -= (MENU_ITEMS[active_menu][0] == 1)?3:1;
break;
case L_BREW: if(active_menu == M_BREW_MANUAL)
brew_control.pressure_up();
brew_control.pressure_up(5);
break;
}
}
......@@ -422,7 +426,7 @@ void menu_handler()
edit_mode += (MENU_ITEMS[active_menu][0] == 1)?3:1;
break;
case L_BREW: if(active_menu == M_BREW_MANUAL)
brew_control.pressure_down();
brew_control.pressure_down(5);
break;
}
}
......
......@@ -143,14 +143,14 @@ void PhaseControl::set_level(int level)
_timeout_usec = HALF_PERIOD_USEC - (_timeouts_usec[_level]*10000/8333) - ZCD_DELAY;
}
void PhaseControl::level_up()
void PhaseControl::level_up(uint8_t value)
{
if (_level < 100)
set_level(_level + 1);
set_level(_level + value);
}
void PhaseControl::level_down()
void PhaseControl::level_down(uint8_t value)
{
if (_level > 0)
set_level(_level - 1);
set_level(_level - value);
}
......@@ -30,8 +30,8 @@ public:
~PhaseControl();
uint8_t get_level();
void level_up();
void level_down();
void level_up(uint8_t value = 1);
void level_down(uint8_t value = 1);
void start();
void stop();
void set_level(int level);
......
......@@ -25,17 +25,20 @@ PressureSensor::PressureSensor(PinName pin) : _input(pin) { // create the
// returns pressure in bar
float PressureSensor::read_bars()
{
return (_input.read() - 0.1) / 0.9 * 12;
return float(read_pa()/100000);
}
// returns pressure in Pa, 100000 Pa = 1 bar
// avoids float calculations for
int PressureSensor::read_pa()
{
// sensor provides linear voltage between 0.5V to 5V representing 0 to 12 bars
// read_u16 will return a value between 6553 and 65535 representing 0.5 to 5V (5V system)
// each 4915 represents 100000 Pa (1 bar) -> each unit represents 20.35 Pa
int pressure_pascal = (_input.read_u16() - 6553);
pressure_pascal = pressure_pascal * 20 + pressure_pascal / 3;
// sensor provides linear voltage between 0.5V to 5V representing 0 to 20 bars
// 0.5V to 3.3V <-> 0 bar to 12.44 bar
// read_u16 should return a value between 9930 and 65535 representing 0.5 to 3.3V
// measurements show a range between 10300 and 60000 respresenting 0.5 to 3.3V
// each 3995 represents 100000 Pa (1 bar) -> each unit represents 25 Pa
// measurements show the 0.5V value at around 10300
int pressure_pascal = (_input.read_u16() - 10300);
pressure_pascal = (pressure_pascal * 25);
return pressure_pascal;
}
\ No newline at end of file
}
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