Increase filter on temp & add batt filter

This commit is contained in:
Ben V. Brown
2017-10-22 21:07:33 +11:00
parent 3b8cd980a7
commit 3bf52cfc69

View File

@@ -23,7 +23,7 @@ uint16_t getHandleTemperature() {
uint16_t result = getADC(0); uint16_t result = getADC(0);
if (result < 4964) if (result < 4964)
return 0; return 0;
result -= 4964;//remove 0.5V offset result -= 4964; //remove 0.5V offset
result /= 10; //convert to X10 C result /= 10; //convert to X10 C
return result; return result;
@@ -58,7 +58,7 @@ uint16_t getTipInstantTemperature() {
uint16_t getTipRawTemp(uint8_t instant) { uint16_t getTipRawTemp(uint8_t instant) {
#define filterDepth1 1 #define filterDepth1 1
/*Pre filter used before PID*/ /*Pre filter used before PID*/
#define filterDepth2 8 #define filterDepth2 16
/*Post filter used for UI display*/ /*Post filter used for UI display*/
static uint16_t filterLayer1[filterDepth1]; static uint16_t filterLayer1[filterDepth1];
static uint16_t filterLayer2[filterDepth2]; static uint16_t filterLayer2[filterDepth2];
@@ -91,8 +91,19 @@ uint16_t getInputVoltageX10(uint8_t divisor) {
//ADC maximum is 16384 == 3.3V at input == 28V at VIN //ADC maximum is 16384 == 3.3V at input == 28V at VIN
//Therefore we can divide down from there //Therefore we can divide down from there
//Ideal term is 117 //Ideal term is 117
#define BATTFILTERDEPTH 64
static uint32_t samples[BATTFILTERDEPTH];
static uint8_t index = 0;
samples[index] = getADC(1);
index = (index + 1) % BATTFILTERDEPTH;
uint32_t sum = 0;
return getADC(1) / divisor; for (uint8_t i = 0; i < BATTFILTERDEPTH; i++)
sum += samples[i];
sum /= BATTFILTERDEPTH;
return sum / divisor;
} }
uint8_t getTipPWM() { uint8_t getTipPWM() {
return htim2.Instance->CCR4; return htim2.Instance->CCR4;