mirror of https://github.com/rusefi/wideband.git
pump controller
This commit is contained in:
parent
d39df2d199
commit
3fdf60b956
|
@ -129,6 +129,7 @@ CPPSRC = $(ALLCPPSRC) \
|
|||
sampling.cpp \
|
||||
heater_control.cpp \
|
||||
pid.cpp \
|
||||
pump_control.cpp \
|
||||
main.cpp
|
||||
|
||||
# List ASM source files here.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "can.h"
|
||||
#include "heater_control.h"
|
||||
#include "pump_control.h"
|
||||
#include "pump_dac.h"
|
||||
#include "sampling.h"
|
||||
|
||||
|
@ -32,15 +33,16 @@ int main() {
|
|||
halInit();
|
||||
chSysInit();
|
||||
|
||||
// Fire up all of our threads
|
||||
StartSampling();
|
||||
|
||||
InitPumpDac();
|
||||
|
||||
InitCan();
|
||||
StartHeaterControl();
|
||||
StartPumpControl();
|
||||
|
||||
uartStart(&UARTD1, &uartCfg);
|
||||
|
||||
StartHeaterControl();
|
||||
|
||||
InitCan();
|
||||
|
||||
/*for (int i = 0; i < 500; i++) {
|
||||
SetPumpCurrentTarget(current);
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
#include "pump_control.h"
|
||||
#include "wideband_config.h"
|
||||
#include "heater_control.h"
|
||||
#include "sampling.h"
|
||||
#include "pump_dac.h"
|
||||
#include "pid.h"
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
static Pid pumpPid(0, 0.01f, 2);
|
||||
|
||||
static THD_WORKING_AREA(waPumpThread, 256);
|
||||
static void PumpThread(void*)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
// Only actuate pump when running closed loop!
|
||||
if (IsRunningClosedLoop())
|
||||
{
|
||||
float nernstVoltage = GetNernstDc();
|
||||
|
||||
float result = pumpPid.GetOutput(NERNST_TARGET, nernstVoltage);
|
||||
|
||||
// result is in mA
|
||||
SetPumpCurrentTarget(result / 1000.0f);
|
||||
|
||||
// Run at 500hz
|
||||
chThdSleepMilliseconds(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StartPumpControl()
|
||||
{
|
||||
chThdCreateStatic(waPumpThread, sizeof(waPumpThread), NORMALPRIO + 4, PumpThread, nullptr);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void StartPumpControl();
|
|
@ -24,11 +24,9 @@
|
|||
#define LSU_SENSE_R (61.9f)
|
||||
|
||||
// *******************************
|
||||
// Pump driver
|
||||
// Pump controller
|
||||
// *******************************
|
||||
|
||||
// todo
|
||||
|
||||
#define NERNST_TARGET (0.45f)
|
||||
|
||||
// *******************************
|
||||
// Heater controller config
|
||||
|
|
Loading…
Reference in New Issue