Patching Filter Depth

Fixes #115
This commit is contained in:
Ben V. Brown
2017-10-29 10:01:16 +11:00
parent 812fbcd902
commit fd92271121
2 changed files with 14 additions and 7 deletions

View File

@@ -58,7 +58,7 @@ uint16_t getTipInstantTemperature() {
uint16_t getTipRawTemp(uint8_t instant) {
#define filterDepth1 1
/*Pre filter used before PID*/
#define filterDepth2 16
#define filterDepth2 32
/*Post filter used for UI display*/
static uint16_t filterLayer1[filterDepth1];
static uint16_t filterLayer2[filterDepth2];
@@ -92,8 +92,14 @@ uint16_t getInputVoltageX10(uint8_t divisor) {
//Therefore we can divide down from there
//Ideal term is 117
#define BATTFILTERDEPTH 64
static uint8_t preFillneeded = 1;
static uint32_t samples[BATTFILTERDEPTH];
static uint8_t index = 0;
if (preFillneeded) {
for (uint8_t i = 0; i < BATTFILTERDEPTH; i++)
samples[i] = getADC(1);
preFillneeded = 0;
}
samples[index] = getADC(1);
index = (index + 1) % BATTFILTERDEPTH;
uint32_t sum = 0;
@@ -102,7 +108,8 @@ uint16_t getInputVoltageX10(uint8_t divisor) {
sum += samples[i];
sum /= BATTFILTERDEPTH;
if (sum < 50)
preFillneeded = 1;
return sum / divisor;
}
uint8_t getTipPWM() {

View File

@@ -52,7 +52,7 @@ int main(void) {
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
/* definition and creation of PIDTask */
osThreadDef(PIDTask, startPIDTask, osPriorityHigh, 0, 256);
osThreadDef(PIDTask, startPIDTask, osPriorityRealtime, 0, 256);
PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL);
/* definition and creation of ROTTask */
@@ -73,7 +73,7 @@ int main(void) {
}
}
void GUIDelay() {
osDelay(60);
osDelay(50);//20Hz
}
ButtonState getButtonState() {
/*
@@ -681,7 +681,7 @@ void startGUITask(void const * argument) {
lcd.clearScreen(); //Ensure the buffer starts clean
lcd.setCursor(0, 0); //Position the cursor at the 0,0 (top left)
lcd.setFont(1); //small font
lcd.print((char*) "V2.00a5"); //Print version number
lcd.print((char*) "V2.00a6"); //Print version number
lcd.setCursor(0, 8); //second line
lcd.print(__DATE__); //print the compile date
lcd.refresh();
@@ -791,8 +791,8 @@ void startPIDTask(void const * argument) {
int32_t kp, ki, kd, kb;
int32_t backoffOverflow = 0;
kp = 20;
ki = 50;
kd = 40;
ki = 40;
kd = 30;
kb = 0;
const int32_t itermMax = 40;
for (;;) {