1
0
forked from me/IronOS

Increase pre PID filtering, reducing display flicker

Also improve movement sensitivities to be less extreme ramp up
This commit is contained in:
Ben V. Brown
2017-07-07 23:22:11 +10:00
parent f72fc36427
commit 7b4f467eec
6 changed files with 51 additions and 24 deletions

View File

@@ -14,8 +14,8 @@
#define SETTINGSVERSION 0x08 /*Change this if you change the struct below to prevent people getting out of sync*/ #define SETTINGSVERSION 0x08 /*Change this if you change the struct below to prevent people getting out of sync*/
//Motion Sensitivity //Motion Sensitivity
#define MOTION_HIGH (0x00) #define MOTION_HIGH (0x00)
#define MOTION_MED (0x10) #define MOTION_MED (0x01)
#define MOTION_LOW (0x20) #define MOTION_LOW (0x02)
//Display Speeds //Display Speeds
#define DISPLAYMODE_FAST (0x00) #define DISPLAYMODE_FAST (0x00)
#define DISPLAYMODE_MEDIUM (0x01) #define DISPLAYMODE_MEDIUM (0x01)

View File

@@ -23,7 +23,7 @@ uint16_t readDCVoltage(uint16_t divFactor) {
//This allows us to read it in X10 mode //This allows us to read it in X10 mode
//Returns temperature in C X10 mode //Returns temperature in C X10 mode
int16_t readTipTemp() { int16_t readTipTemp() {
static uint32_t rollingAverage[4]; static uint32_t rollingAverage[16];
static uint8_t rIndex = 0; static uint8_t rIndex = 0;
/*The head has a thermocouple inline with the heater /*The head has a thermocouple inline with the heater
@@ -54,9 +54,13 @@ int16_t readTipTemp() {
ad_sum = ad_sum - max - min; //remove the two outliers ad_sum = ad_sum - max - min; //remove the two outliers
avg_data = ad_sum / 8; //take the average avg_data = ad_sum / 8; //take the average
rollingAverage[rIndex] = avg_data; rollingAverage[rIndex] = avg_data;
rIndex = (rIndex + 1) % 4; rIndex = (rIndex + 1) % 16;
return (rollingAverage[0] + rollingAverage[1] + rollingAverage[2] return (rollingAverage[0] + rollingAverage[1] + rollingAverage[2]
+ rollingAverage[3]) / 4; //get the average + rollingAverage[3] + rollingAverage[4] + rollingAverage[5]
+ rollingAverage[6] + rollingAverage[7] + rollingAverage[8]
+ rollingAverage[9] + rollingAverage[10] + rollingAverage[11]
+ rollingAverage[12] + rollingAverage[13] + rollingAverage[14]
+ rollingAverage[15]) / 16; //get the average
} }

View File

@@ -34,7 +34,20 @@ void StartUp_Accelerometer(uint8_t sensitivity) {
I2C_RegisterWrite( CTRL_REG2, 0x40); // Reset all registers to POR values I2C_RegisterWrite( CTRL_REG2, 0x40); // Reset all registers to POR values
delayMs(2); // ~1ms delay delayMs(2); // ~1ms delay
I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X and Y axis, latch enabled I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X and Y axis, latch enabled
I2C_RegisterWrite(FF_MT_THS_REG, sensitivity|0x0F); // Set threshold uint8_t sens =0x0F;
switch(sensitivity)
{
case 0:
sens=0x1A;
break;
case 1:
sens=0x20;
break;
case 2:
sens=0x2A;
break;
}
I2C_RegisterWrite(FF_MT_THS_REG, sens); // Set threshold
I2C_RegisterWrite(FF_MT_COUNT_REG, 0x01); // Set debounce to 100ms I2C_RegisterWrite(FF_MT_COUNT_REG, 0x01); // Set debounce to 100ms
I2C_RegisterWrite( CTRL_REG4, 0x04); // Enable motion interrupt I2C_RegisterWrite( CTRL_REG4, 0x04); // Enable motion interrupt

View File

@@ -38,6 +38,6 @@ void setup() {
Init_Oled(systemSettings.flipDisplay); //Init the OLED display Init_Oled(systemSettings.flipDisplay); //Init the OLED display
OLED_DrawString("VER 1.10", 8); //Version Number OLED_DrawString("VER 1.10", 8); //Version Number
delayMs(800); //Pause to show version number delayMs(500); //Pause to show version number
Start_Watchdog(1000); //start the system watch dog as 1 second timeout Start_Watchdog(1000); //start the system watch dog as 1 second timeout
} }

View File

@@ -5,14 +5,14 @@
* Author: Ralim <ralim@ralimtek.com> * Author: Ralim <ralim@ralimtek.com>
*/ */
#include "Modes.h" #include "Modes.h"
const char *SettingsLongNames[] = { " Undervoltage Cutout", const char *SettingsLongNames[] = { " Undervoltage Cutout (V)",
" Sleep Temperature", " Sleep Timeout", " Sleep Temperature (C)", " Sleep Timeout (Minutes)",
" Shutdown Timeout", " Motion Detection", " Shutdown Timeout (Minutes)", " Motion Detection",
" Motion Sensitivity", " Temperature Unit", " Motion Sensitivity", " Temperature Unit",
" Temperature Rounding Amount", " Temperature Rounding Amount",
" Temperature Display Update Rate", " Temperature Display Update Rate",
" Flip Display for Left Hand" }; " Flip Display for Left Hand" };
const uint8_t SettingsLongNamesLengths[] = { 25, 23, 19, 22, 22, 24, 22, 33, 37, const uint8_t SettingsLongNamesLengths[] = { 29, 27, 29, 32, 22, 24, 22, 33, 37,
25 }; 25 };
uint8_t CalStatus = 0; uint8_t CalStatus = 0;
//This does the required processing and state changes //This does the required processing and state changes
@@ -141,9 +141,8 @@ void ProcessUI() {
systemSettings.flipDisplay = !systemSettings.flipDisplay; systemSettings.flipDisplay = !systemSettings.flipDisplay;
break; break;
case MOTIONSENSITIVITY: case MOTIONSENSITIVITY:
systemSettings.sensitivity += 0x10; systemSettings.sensitivity++;
if (systemSettings.sensitivity > 0x20) systemSettings.sensitivity = systemSettings.sensitivity % 3;
systemSettings.sensitivity = 0; //reset to high on wrap
break; break;
case TEMPROUNDING: case TEMPROUNDING:
@@ -320,6 +319,9 @@ void drawTemp(uint16_t temp, uint8_t x, uint8_t roundingMode) {
*/ */
void DrawUI() { void DrawUI() {
static uint32_t lastOLEDDrawTime = 0; static uint32_t lastOLEDDrawTime = 0;
static uint16_t lastSolderingDrawnTemp1 = 0;
static uint16_t lastSolderingDrawnTemp2 = 0;
static uint8_t settingsLongTestScrollPos = 0; static uint8_t settingsLongTestScrollPos = 0;
uint16_t temp = readIronTemp(0, 0, 0xFFFF); uint16_t temp = readIronTemp(0, 0, 0xFFFF);
switch (operatingMode) { switch (operatingMode) {
@@ -348,17 +350,24 @@ void DrawUI() {
&& (millis() - lastOLEDDrawTime < 50)) && (millis() - lastOLEDDrawTime < 50))
return; return;
drawTemp(temp, 0, systemSettings.temperatureRounding); uint32_t tempavg = (temp + lastSolderingDrawnTemp1
+ lastSolderingDrawnTemp2);
tempavg /= 3;
drawTemp(tempavg, 0, systemSettings.temperatureRounding);
lastSolderingDrawnTemp1 = temp;
lastSolderingDrawnTemp2 = lastSolderingDrawnTemp1;
lastOLEDDrawTime = millis(); lastOLEDDrawTime = millis();
//Now draw symbols //Now draw symbols
OLED_DrawChar(' ', 3); OLED_DrawChar(' ', 3);
OLED_BlankSlot(6 * 12 + 16, 24 - 16);//blank out the tail after the arrows OLED_BlankSlot(6 * 12 + 16, 24 - 16);//blank out the tail after the arrows
OLED_BlankSlot(4 * 12 + 16, 24 - 16);//blank out the tail after the temp OLED_BlankSlot(4 * 12 + 16, 24 - 16);//blank out the tail after the temp
if (getIronTimer() == 0) { if (getIronTimer() == 0
&& (temp / 10) > (systemSettings.SolderingTemp / 10)) {
//Cooling
OLED_DrawSymbol(6, 5); OLED_DrawSymbol(6, 5);
} else { } else {
if (getIronTimer() < 1000) { if (getIronTimer() < 1500) {
//Maintaining
OLED_DrawSymbol(6, 7); OLED_DrawSymbol(6, 7);
} else { //we are heating } else { //we are heating
OLED_DrawSymbol(6, 6); OLED_DrawSymbol(6, 6);
@@ -507,6 +516,7 @@ void DrawUI() {
//Draw in temp and sleep //Draw in temp and sleep
OLED_DrawString("SLP", 3); OLED_DrawString("SLP", 3);
drawTemp(temp, 4, systemSettings.temperatureRounding); drawTemp(temp, 4, systemSettings.temperatureRounding);
OLED_BlankSlot(84, 96 - 85); //blank out after the temp
if (millis() - getLastMovement() > (10 * 60 * 1000) if (millis() - getLastMovement() > (10 * 60 * 1000)
&& (millis() - getLastButtonPress() > (10 * 60 * 1000))) { && (millis() - getLastButtonPress() > (10 * 60 * 1000))) {

View File

@@ -15,8 +15,8 @@ int32_t computePID(uint16_t setpoint) {
uint16_t currentReading = readIronTemp(0, 1,setpoint); //get the current temp of the iron uint16_t currentReading = readIronTemp(0, 1,setpoint); //get the current temp of the iron
int16_t error = (int16_t) setpoint - (int16_t) currentReading; //calculate the error term int16_t error = (int16_t) setpoint - (int16_t) currentReading; //calculate the error term
ITerm += (pidSettings.ki * error); ITerm += (pidSettings.ki * error);
if (ITerm > MAXPIDOUTPUT) if (ITerm > MAXPIDOUTPUT/2)
ITerm = MAXPIDOUTPUT; ITerm = MAXPIDOUTPUT/2;
else if (ITerm < 0) else if (ITerm < 0)
ITerm = 0; //cap at 0 since we cant force the iron to cool itself :) ITerm = 0; //cap at 0 since we cant force the iron to cool itself :)
@@ -34,8 +34,8 @@ int32_t computePID(uint16_t setpoint) {
} }
/*Sets up the pid values*/ /*Sets up the pid values*/
void setupPID(void) { void setupPID(void) {
pidSettings.kp = 25; pidSettings.kp = 15;
pidSettings.ki = 7; pidSettings.ki = 2;
pidSettings.kd = 2; pidSettings.kd = 3;
} }