1
0
forked from me/IronOS

PID regulating (fix error being unsigned..)

This commit is contained in:
Ben V. Brown
2016-09-21 00:26:43 +10:00
parent 65659b7b99
commit f4d5b8b000
7 changed files with 37 additions and 14 deletions

View File

@@ -10,6 +10,7 @@
#include "stm32f10x.h"
#include "S100V0_1.h"
#include "Bios.h"
#include "Interrupt.h"
extern volatile uint16_t ADC1ConvertedValue[2];
uint16_t Get_ADC1Value(uint8_t i);

View File

@@ -10,7 +10,7 @@
#include "Interrupt.h"
#include "S100V0_1.h"
#include "Oled.h"
#include "PID.h"
enum {
STARTUP, //we are sitting on the prompt to push a button
SOLDERING,

View File

@@ -103,8 +103,16 @@ uint16_t Get_ADC1Value(uint8_t i) {
//This returns the calibrated temperature reading of the iron temp
uint16_t readIronTemp(uint16_t calibration_temp) {
static uint16_t calTemp = 0;
static uint16_t lastVal = 0;
static uint32_t lastUpdate = 0;
if (calibration_temp != 0)
calTemp = calibration_temp;
return (readTipTemp() * 1000 + 806 * readSensorTemp() - calTemp * 1000)
/ 806;
if (millis() - lastUpdate > 50) {
lastVal = (readTipTemp() * 1000 + 806 * readSensorTemp()
- calTemp * 1000) / 806;
lastUpdate = millis();
}
return lastVal;
}

View File

@@ -15,7 +15,7 @@
#include "Bios.h"
#include "I2C.h"
#include "MMA8652FC.h"
#include "PID.h"
#include "Oled.h"
#include "Interrupt.h"
@@ -35,10 +35,11 @@ int main(void) {
Init_Oled(); //init the OLED display
Clear_Screen(); //clear the display buffer to black
systemSettings.SleepTemp = 200;
systemSettings.SleepTemp = 1000;
systemSettings.SleepTime = 1;
systemSettings.SolderingTemp = 320;
readIronTemp(239);//load the default calibration value
systemSettings.SolderingTemp = 1500;
readIronTemp(239); //load the default calibration value
setupPID(); //init the PID values
//OLED_DrawString("TEST012",7);
/*for (;;) {

View File

@@ -40,8 +40,15 @@ void ProcessUI() {
operatingMode = SLEEP; //Goto Sleep Mode
return;
}
//If no buttons pushed we need to read the current temperatures
// and then setup the drive signal time for the iron
/*if (millis() - getLastButtonPress()
> (systemSettings.SleepTime * 60000))
operatingMode = SLEEP;
return;*/
//If no buttons pushed we need to perform the PID loop for the iron temp
int32_t newOutput = computePID(systemSettings.SolderingTemp);
if (newOutput >= 0) {
setIronTimer(newOutput);
}
}
break;
case TEMP_ADJ:
@@ -99,15 +106,21 @@ void ProcessUI() {
if (Buttons & BUT_A) {
//A Button was pressed so we are moving back to soldering
operatingMode = SOLDERING;
return;
} else if (Buttons & BUT_B) {
//B Button was pressed so we are moving back to soldering
operatingMode = SOLDERING;
return;
} else if (systemSettings.movementEnabled)
if (millis() - getLastMovement() > 100) {
operatingMode = SOLDERING; //Goto active mode again
return;
}
//else if nothing has been pushed we need to compute the PID to keep the iron at the sleep temp
int32_t newOutput = computePID(systemSettings.SleepTemp);
if (newOutput >= 0) {
setIronTimer(newOutput);
}
break;
default:
break;
@@ -132,7 +145,7 @@ void DrawUI() {
//We draw in the current system temp and an indicator if the iron is heating or not
//First lets draw the current tip temp
//OLED_DrawString("SOLD ", 6);
OLED_DrawThreeNumber(readIronTemp(0), 0);
OLED_DrawThreeNumber(readIronTemp(0)/10, 0);
break;
case TEMP_ADJ:

View File

@@ -14,9 +14,9 @@ int32_t computePID(uint16_t setpoint) {
int32_t ITerm = 0;
static int16_t lastReading = 0;
if (millis() - lastSample > 50) {
//only sample every 100 milliseconds
//only sample every 50 milliseconds
uint16_t currentReading = readIronTemp(0); //get the current temp of the iron
uint16_t error = setpoint - currentReading; //calculate the error term
int16_t error = (int16_t)setpoint - (int16_t)currentReading; //calculate the error term
ITerm += (pidSettings.ki * error);
if (ITerm > MAXPIDOUTPUT)
ITerm = MAXPIDOUTPUT;