Temp control working

Fix pid error
Remove pointless static keywords
This commit is contained in:
Ben V. Brown
2016-09-16 22:36:24 +10:00
parent 96bda69a0a
commit f355ff6c01
8 changed files with 31 additions and 134 deletions

View File

@@ -335,7 +335,9 @@ void TIM2_ISR(void) {
*******************************************************************************/
void TIM3_ISR(void) {
volatile static u8 heat_flag = 0; //heat flag == used to make the pin toggle
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); // Clear interrupt flag
if (gTimeOut > 0)
gTimeOut--;
if (gMs_timeout > 0)

View File

@@ -42,7 +42,7 @@ struct _pid {
s16 actualtemp; //Actual current temp of the tip
s16 err; //Error term
s16 err_last; //last error term
u32 ht_time; //
s32 ht_time; //
u16 kp, ki, kd; //Constants for the PID Controller
s32 integral; //
} pid;
@@ -135,7 +135,7 @@ u16 Pid_Realize(s16 temp) {
pid.actualtemp = temp;
pid.err = pid.settemp - pid.actualtemp; //
if (pid.err >= 500)
if (pid.err >= 500)//error is > 50 degrees
index = 0;
else {
index = 1;
@@ -143,7 +143,7 @@ u16 Pid_Realize(s16 temp) {
}
////////////////////////////////////////////////////////////////////////////////
//
if (pid.settemp < pid.actualtemp) {
if (pid.settemp < pid.actualtemp) {//cooling down
d_err = pid.actualtemp - pid.settemp;
if (d_err > 20) {
pid.integral = 0; //

View File

@@ -1,33 +0,0 @@
/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************
File Name : Flash.c
Version : Author : bure
*******************************************************************************/
#include "APP_Version.h"
#include "Flash.h"
#include "Bios.h"
/*******************************************************************************
Function: FLASH_Prog
Description: Programs the data into the system flash at the specified address
*******************************************************************************/
u8 FLASH_Prog(u32 Address, u16 Data) {
if (FLASH_WaitForLastOperation(WAIT_TIMES) != FLASH_TIMEOUT)
FLASH_ClearFlag(
FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
return FLASH_ProgramHalfWord(Address, Data);
}
/*******************************************************************************
Function: FLASH_Erase
Description: Erases a page of flash
Inputs: Starting address for the page to erase
*******************************************************************************/
void FLASH_Erase(u32 Address) {
if (Address % FLASH_PAGE == 0) { // FLASH Page start (1K/Page)
if (FLASH_WaitForLastOperation(WAIT_TIMES) != FLASH_TIMEOUT) //wait for last op to finish
FLASH_ClearFlag(
FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
FLASH_ErasePage(Address); // FLASH Page erase
}
}
/********************************* END OF FILE ******************************/

View File

@@ -27,64 +27,38 @@ u32 gKey_in;
u8 gLongkey_flag = 0;
u8 gAlarm_type = 1;
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_CalFlag
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡУ׼״̬
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:У׼״̬<D7B4><CCAC>־
*******************************************************************************/
u32 Get_CalFlag(void) {
return gCalib_flag;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_gKey
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>״̬
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>״̬
*******************************************************************************/
u32 Get_gKey(void) {
return gKey_in;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Set_gKey
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>ð<EFBFBD><C3B0><EFBFBD>״̬
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D2AA><EFBFBD>õİ<C3B5><C4B0><EFBFBD>״̬
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Set_gKey(u32 key) {
gKey_in = key;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Set_LongKeyFlag
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:0 :<3A><><EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD><EFBFBD><EFBFBD> 1: <20><><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Set_LongKeyFlag(u32 flag) {
gLongkey_flag = flag;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_AlarmType
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
0:<3A><><EFBFBD><EFBFBD>
1:sensor - err
2:<3A><><EFBFBD><EFBFBD>
3:<3A><>ѹ
*******************************************************************************/
u8 Get_AlarmType(void) {
return gAlarm_type;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Set_AlarmType
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
0:<3A><><EFBFBD><EFBFBD>
1:sen - err
2:<3A><><EFBFBD><EFBFBD>
3:<3A><>ѹ
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Set_AlarmType(u8 type) {
gAlarm_type = type;
@@ -107,7 +81,7 @@ int Read_Vb(u8 flag) {
gAlarm_type = HIGH_VOLTAGE;
return H_ALARM; //<2F><><EFBFBD><EFBFBD>3500
}
tmp = (tmp * 10 / 144); //<2F><>ѹvb = 3.3 * 85 *ad / 40950
tmp = (tmp * 10 / 144); //<2F><>ѹvb = 3.3 * 85 *ad / 40950 -> In X10 voltage
for (i = 0; i < 4; i++) {
if (i == 2) {
@@ -126,10 +100,7 @@ int Read_Vb(u8 flag) {
return (i + 1);
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Scan_Key
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><C9A8><EFBFBD><EFBFBD><EFBFBD>(50msÿ<73><C3BF>)
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Scan_Key(void) {
static u32 p_cnt = 0, key_statuslast = 0;
@@ -143,11 +114,11 @@ void Scan_Key(void) {
if (key_state == 0)
return;
if (gLongkey_flag == 1) { //LongKey_flag :<3A><><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
if (gLongkey_flag == 1) { //LongKey_flag -> we are looking for a long press or a quick press
if (key_statuslast == key_state) {
p_cnt++;
if (p_cnt > 21)
Set_gKey(KEY_CN | key_state); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Set_gKey(KEY_CN | key_state);
} else {
p_cnt = 0;
key_statuslast = key_state;
@@ -162,10 +133,7 @@ void Scan_Key(void) {
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_SlAvg
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>ֵ
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:avg_data ƽ<><C6BD><EFBFBD><EFBFBD>ADֵ
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>ֵ
*******************************************************************************/
u32 Get_SlAvg(u32 avg_data) {
static u32 sum_avg = 0;
@@ -200,13 +168,13 @@ u32 Get_AvgAd(void) {
This is read by turning off the heater
Then read the output of the op-amp that is connected across the connections
*/
static u32 ad_sum = 0;
static u32 max = 0, min = 5000;
u32 ad_value, avg_data, slide_data = 0;
u32 ad_sum = 0;
u32 max = 0, min = 5000;
u32 ad_value, avg_data;
Set_HeatingTime(0); //set the remaining time to zero
HEAT_OFF(); //heater must be off
Delay_HalfMs(25); //wait for the heater to time out
Delay_HalfMs(50); //wait for the heater to time out
gMeas_cnt = 10; //how many measurements to make
while (gMeas_cnt > 0) {
@@ -221,14 +189,12 @@ u32 Get_AvgAd(void) {
ad_sum = ad_sum - max - min; //remove the two outliers
avg_data = ad_sum / 8; //take the average
slide_data = Get_SlAvg(avg_data);
ad_sum = 0;
min = 5000;
max = 0;
return Get_SlAvg(avg_data);
}
gMeas_cnt--;
}
return slide_data; //gSlide_data;
return 0; //should never ever hit here
}
/*******************************************************************************
@@ -311,10 +277,7 @@ void Zero_Calibration(void) {
}
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_Temp
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>ȶ<EFBFBD><C8B6><EFBFBD>,<2C><><EFBFBD><EFBFBD>AD<41><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:wk_temp <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><><CAB5><EFBFBD><EFBFBD>
*******************************************************************************/
s16 Get_Temp(s16 wk_temp) {
int ad_value, cool_tmp, compensation = 0;

View File

@@ -14,7 +14,6 @@
#include "Bios.h"
#include "I2C.h"
#include "Flash.h"
#include "MMA8652FC.h"
#include "UI.h"
#include "Oled.h"

View File

@@ -720,7 +720,7 @@ void Print_Integer(s32 data, u8 posi) {
char str[8];
Clear_Screen();
sprintf(str, "%d", data);
sprintf(str, "%ld", data);
Display_Str(posi, str);
}
/*******************************************************************************