add IsRunningClosedLoop

This commit is contained in:
Matthew Kennedy 2020-10-31 14:54:50 -07:00
parent ac7a2a9e68
commit 453a4c4337
4 changed files with 26 additions and 9 deletions

View File

@ -32,17 +32,20 @@ static HeaterState GetNextState(HeaterState state, float sensorEsr)
rampDuty = 0.5f;
return HeaterState::WarmupRamp;
}
else
{
// Stay in preheat - wait for time to elapse
return HeaterState::Preheat;
}
// Stay in preheat - wait for time to elapse
break;
case HeaterState::WarmupRamp:
if (sensorEsr < 2000)
{
return HeaterState::ClosedLoop;
}
break;
case HeaterState::ClosedLoop: break;
}
return state;
}
static float GetDutyForState(HeaterState state, float heaterEsr)
@ -61,17 +64,18 @@ static float GetDutyForState(HeaterState state, float heaterEsr)
case HeaterState::ClosedLoop:
{
// do something more intelligent here
float error = (300 - heaterEsr) / 100;
float error = (heaterEsr - 250) / 100;
return error * 1.0f;
}
}
}
static HeaterState state = HeaterState::Preheat;
static THD_WORKING_AREA(waHeaterThread, 256);
static void HeaterThread(void*)
{
HeaterState state = HeaterState::Preheat;
while (true)
{
@ -97,3 +101,8 @@ void StartHeaterControl()
chThdCreateStatic(waHeaterThread, sizeof(waHeaterThread), NORMALPRIO + 1, HeaterThread, nullptr);
}
bool IsRunningClosedLoop()
{
return state == HeaterState::ClosedLoop;
}

View File

@ -1,3 +1,4 @@
#pragma once
void StartHeaterControl();
bool IsRunningClosedLoop();

View File

@ -1,5 +1,6 @@
#include "pump_dac.h"
#include "pwm.h"
#include "heater_control.h"
#include "wideband_config.h"
@ -19,10 +20,16 @@ void InitPumpDac()
void SetPumpCurrentTarget(int32_t microampere)
{
// Don't allow pump current when the sensor isn't hot
if (!IsRunningClosedLoop())
{
microampere = 0;
}
// 47 ohm resistor
// 0.147 gain
// effective resistance of 317 ohms
float volts = 0.000321162f * microampere;
float volts = -0.000321162f * microampere;
// offset by half vcc
volts += HALF_VCC;

View File

@ -78,6 +78,6 @@ float GetPumpNominalCurrent()
// Gain is 10x, then a 61.9 ohm resistor
// Effective resistance with the gain is 619 ohms
// 1000 is to convert to milliamperes
constexpr float ratio = 1000 / (PUMP_CURRENT_SENSE_GAIN * LSU_SENSE_R);
constexpr float ratio = -1000 / (PUMP_CURRENT_SENSE_GAIN * LSU_SENSE_R);
return pumpCurrentSenseVoltage * ratio;
}