Commit 33d95873 authored by Philippe Kalaf's avatar Philippe Kalaf

Optimisation work on temperature sensor driver

Added hardware schematics + PCB
parent b881a8cb
......@@ -15,7 +15,8 @@
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// brew worker to run 10 times per second
#define BREW_WORKER_PERIOD 0.1
......@@ -38,7 +39,9 @@ BrewControl::BrewControl( PinName brew_pin,
PinName pump_control_pin,
PinName pressure_sensor_pin,
PinName temp_sensor_pin,
//PinName temp2_sensor_pin,
#ifdef TEMP2
PinName temp2_sensor_pin,
#endif
PinName boiler_pwm_pin
) :
_brew_switch(brew_pin, 0),
......@@ -46,7 +49,9 @@ BrewControl::BrewControl( PinName brew_pin,
_pump_control(zcd_input_pin, pump_control_pin),
_pressure_sensor(pressure_sensor_pin),
_temp_sensor(temp_sensor_pin),
//_temp2_sensor(temp2_sensor_pin),
#ifdef TEMP2
_temp2_sensor(temp2_sensor_pin),
#endif
_boiler_pwm(boiler_pwm_pin)
{
_preinfuse_time = 0;
......@@ -76,8 +81,9 @@ float BrewControl::get_current_temperature_side()
float BrewControl::get_current_temperature_top()
{
// return _temp2_sensor.read();
#ifdef TEMP2
return _temp2_sensor.read();
#endif
return 0;
}
......@@ -256,9 +262,6 @@ void BrewControl::_brew_worker()
{
_shot_clock = _shot_clock + BREW_WORKER_PERIOD;
if (_mode != MODE_PRE_INFUSE)
_pressure_sensor.start_count();
if (_mode == MODE_PRE_INFUSE)
{
// First let's fill up the portafilter
......@@ -281,6 +284,7 @@ void BrewControl::_brew_worker()
_flow_sensor.reset_count();
_state = BREWING;
_stop_preinfuse = 0;
_pressure_sensor.start_count();
}
}
else if(_mode == MODE_TIME)
......@@ -408,6 +412,11 @@ void BrewControl::soft_stop()
_state = SOFT_STOPPING;
}
float BrewControl::get_average_pressure()
{
return _average_pressure;
}
uint8_t BrewControl::toggle()
{
if(_state == BREWING || _state == PRE_INFUSING)
......@@ -422,3 +431,15 @@ PhaseControl *BrewControl::get_pump_control_ptr()
{
return &_pump_control;
}
uint16_t BrewControl::get_last_pulse_count_side()
{
return _temp_sensor.get_last_pulse_count();
}
uint16_t BrewControl::get_last_pulse_count_top()
{
#ifdef TEMP2
return _temp2_sensor.get_last_pulse_count();
#endif
}
......@@ -40,6 +40,8 @@
#define PORTAFILTER_VOLUME 100
//#define TEMP2
/// This is the main class where all brew functions and sensors are handled
class BrewControl
{
......@@ -51,7 +53,9 @@ public:
PinName pump_control_pin,
PinName pressure_sensor_pin,
PinName temp_sensor_pin,
//PinName temp2_sensor_pin,
#ifdef TEMP2
PinName temp2_sensor_pin,
#endif
PinName boiler_pwm_pin);
/// Set the target shot temperature in C
......@@ -119,8 +123,13 @@ public:
/// Toggle PID boiler control
bool toggle_boiler();
/// Get average pressure of last shot
float get_average_pressure();
PhaseControl *get_pump_control_ptr();
void toggle_solenoid();
uint16_t get_last_pulse_count_side();
uint16_t get_last_pulse_count_top();
private:
// Signal to turn on/off pump
......@@ -140,7 +149,9 @@ private:
// Temperature control
LMT01 _temp_sensor;
//LMT01 _temp2_sensor;
#ifdef TEMP2
LMT01 _temp2_sensor;
#endif
PwmOut _boiler_pwm;
PIDControl _boiler_pid;
float _latest_temp;
......
espresso-on-crack-brd.svg
\ No newline at end of file
../../../espresso-on-crack.pdf
\ No newline at end of file
......@@ -31,6 +31,26 @@ LMT01::LMT01(PinName pin) : _interrupt(pin) { // create the InterruptIn o
_interrupt.mode(PullUp); // an internal pull up is used, otherwise disable here
_interrupt.fall(callback(this, &LMT01::increment)); // attach increment function of this counter instance
_pulse_timer.start();
_ticker.attach(callback(this, &LMT01::worker), 0.5);
}
void LMT01::worker()
{
// Find pulse/temp range from table
uint16_t i;
for (i = 0; i < sizeof(_pulse_temp_table); i++)
if (_last_pulse_count < _pulse_temp_table[i][1])
break;
// Read/convert/store count as temperature
_temperature =
(
(
((_last_pulse_count - _pulse_temp_table[i-1][1]) * 1000) /
(_pulse_temp_table[i][1] - _pulse_temp_table[i-1][1])
) * 10 // at this point unit is 10^3 Celsius
)
+ _pulse_temp_table[i-1][0] * 1000;
}
void LMT01::increment()
......@@ -40,23 +60,7 @@ void LMT01::increment()
if (_pulse_timer.read_ms() > 10)
{
_pulse_timer.reset();
// Find pulse/temp range from table
uint16_t i;
uint16_t pulse_count = _pulse_count;
for (i = 0; i < sizeof(_pulse_temp_table); i++)
if (pulse_count < _pulse_temp_table[i][1])
break;
// Read/convert/store count as temperature
_temperature =
(
(
((pulse_count - _pulse_temp_table[i-1][1]) * 1000) /
(_pulse_temp_table[i][1] - _pulse_temp_table[i-1][1])
) * 10 // at this point unit is 10^3 Celsius
)
+ _pulse_temp_table[i-1][0] * 1000;
_last_pulse_count = _pulse_count;
_pulse_count = 0;
}
else
......@@ -77,4 +81,8 @@ float LMT01::read()
{
return float(_temperature)/1000;
}
uint16_t LMT01::get_last_pulse_count()
{
return _last_pulse_count;
}
......@@ -28,17 +28,23 @@ class LMT01
public:
LMT01(PinName pin);
static const int _pulse_temp_table[20][2];
void increment();
int read_int();
float read();
static const int _pulse_temp_table[20][2];
uint16_t get_last_pulse_count();
private:
InterruptIn _interrupt;
volatile int _pulse_count;
volatile uint16_t _pulse_count;
volatile uint16_t _last_pulse_count;
// temperature in 10^3 Celsius
volatile int _temperature;
Timer _pulse_timer;
Ticker _ticker;
void worker();
};
#endif// lmt01_h
\ No newline at end of file
#endif// lmt01_h
......@@ -79,7 +79,12 @@ Timer js_timer;
// side temperature sensor (TEMP_IN)
// top temperature sensor (TEMP2_IN) - Not Implemented
// boiler control ssr (BOILER_CTRL)
#ifdef TEMP2
BrewControl brew_control(p10, p15, p12, p13, p20, p25, p14, p26);
#else
BrewControl brew_control(p10, p15, p12, p13, p20, p25, p26);
#endif
// Menu structures
//
......@@ -200,10 +205,10 @@ void draw_menu()
// Standby screen -> Temperature, Pressure, Yield, Shot Clock, Flow Rate
if (menu_level == L_STANDBY || menu_level == L_BREW) {
state = brew_control.get_state();
LCD.set_font((unsigned char*) Small_6);
if (menu_level == L_BREW)
{
state = brew_control.get_state();
// Invert screen while brewing
if (state)
LCD.invert(1);
......@@ -252,10 +257,14 @@ void draw_menu()
}
LCD.locate(4,4);
LCD.set_font((unsigned char*) Arial12x12);
LCD.printf("%.1f C %.1f bar %.1f ml/s",
brew_control.get_current_temperature(),
brew_control.get_current_pressure(),
brew_control.get_current_flow_rate());
if (state == SOFT_STOPPING)
LCD.printf("Av, pressure: %.1f bar",
brew_control.get_average_pressure());
else
LCD.printf("%.1fC %.1fbar %.1fml/s",
brew_control.get_current_temperature(),
brew_control.get_current_pressure(),
brew_control.get_current_flow_rate());
LCD.locate(55,17);
LCD.printf("%.0f ml %.0f s",
brew_control.get_current_volume(),
......@@ -603,6 +612,11 @@ int main()
brew_control.get_current_time(),
brew_control.get_current_flow_rate());
*/
pc.printf("%.1f %.1f %d %d\n", brew_control.get_current_temperature_side(),
brew_control.get_current_temperature_top(),
brew_control.get_last_pulse_count_side(),
brew_control.get_last_pulse_count_top()
);
Thread::wait(100); // wait 0.1s
#endif
}
......
......@@ -25,7 +25,7 @@ PressureSensor::PressureSensor(PinName pin) : _input(pin) { // create the
// returns pressure in bar
float PressureSensor::read_bars()
{
return float(read_pa()/100000);
return float(read_pa())/100000;
}
// returns pressure in Pa, 100000 Pa = 1 bar
......@@ -67,5 +67,5 @@ float PressureSensor::stop_count()
{
_read_count = -1;
_ticker.detach();
return _average_pressure / 100000;
return float(_average_pressure) / 100000;
}
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