From f355ff6c0106f12afafccd6359cfd4a9f0a4eb9f Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Fri, 16 Sep 2016 22:36:24 +1000 Subject: [PATCH] Temp control working Fix pid error Remove pointless static keywords --- workspace/ts100/inc/Flash.h | 29 ------------- workspace/ts100/inc/S100V0_1.h | 17 +++----- workspace/ts100/src/Bios.c | 2 + workspace/ts100/src/CTRL.c | 6 +-- workspace/ts100/src/Flash.c | 33 --------------- workspace/ts100/src/Hardware.c | 75 +++++++++------------------------- workspace/ts100/src/Main.c | 1 - workspace/ts100/src/UI.c | 2 +- 8 files changed, 31 insertions(+), 134 deletions(-) delete mode 100644 workspace/ts100/inc/Flash.h delete mode 100644 workspace/ts100/src/Flash.c diff --git a/workspace/ts100/inc/Flash.h b/workspace/ts100/inc/Flash.h deleted file mode 100644 index fc5a9271..00000000 --- a/workspace/ts100/inc/Flash.h +++ /dev/null @@ -1,29 +0,0 @@ -/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ******************** - File Name : Flash.h - Version : Author : bure -*******************************************************************************/ -#ifndef __EXT_FLASH_H -#define __EXT_FLASH_H -#include "stm32f10x.h" -#define PAGESIZE 256 - -#define WREN 0x06 // Write enable instruction -#define READ 0x03 // Read from Memory instruction -#define RDSR 0x05 // Read Status Register instruction -#define PP 0x02 // Write to Memory instruction -#define PW 0x0A // Page write instruction - -#define OK 0 // -#define SEC_ERR 1 // -#define TMAX 100000 // - -#define WIP_Flag 0x01 // Write In Progress (WIP) flag -#define Dummy_Byte 0xA5 - -u8 FLASH_Prog(u32 Address, u16 Data); -void FLASH_Erase(u32 Address); -void ExtFlashPageWR(u8* pBuffer, u32 WriteAddr); -void ExtFlashDataRD(u8* pBuffer, u32 ReadAddr, u16 Lenght); -#endif - -/********************************* END OF FILE ******************************/ diff --git a/workspace/ts100/inc/S100V0_1.h b/workspace/ts100/inc/S100V0_1.h index a700d9a1..efe53064 100644 --- a/workspace/ts100/inc/S100V0_1.h +++ b/workspace/ts100/inc/S100V0_1.h @@ -6,15 +6,10 @@ #define PRODUCT_INFO "TS100" #define MCU_TYPE "STM32F103T8" -#define ADC_TYPE "MCU's ADC" -#define FPGA_TYPE "None" #define SCH_VER "2.46" -// #define SSD1316 1 -// #define MFTSEEED "Manufacturer" -// #define MFTMINI "Manufacturer" + #define SPIx SPI1 -#define FLASH_PAGE 0x0400 //--------------------------- key Definitions ------------------------------// #define KEY1_PIN GPIO_Pin_9 //PA8 #define KEY2_PIN GPIO_Pin_6 //PA6 @@ -33,23 +28,23 @@ #define I2C2_DR_Address 0x40005810 -//--------------------------- OLED ��ؿ����ź� ------------------------------// +//--------------------------- OLED ------------------------------// #define OLED_RST_PIN GPIO_Pin_8 //PA9 #define OLED_RST() GPIO_ResetBits(GPIOA, OLED_RST_PIN) #define OLED_ACT() GPIO_SetBits (GPIOA, OLED_RST_PIN) -//------------------------------ ���ȿ����ź� --------------------------------// +//------------------------------ --------------------------------// #define HEAT_PIN GPIO_Pin_4 #define HEAT_OFF() GPIOB->BRR = HEAT_PIN #define HEAT_ON() GPIOB->BSRR = HEAT_PIN -//---------------------�����ѹ���--VB---------------------------------------// +//-----------------------VB---------------------------------------// #define VB_PIN GPIO_Pin_1 //PB1(Ai9) //----------------------------ADX345 INT1,INT2--------------------------------// #define INT1_PIN GPIO_Pin_5 //PB5 #define INT2_PIN GPIO_Pin_3 //PB3 -//------------------------------ GPIO �˿����� -------------------------------// +//------------------------------ GPIO -------------------------------// #define GPIOA_OUTPUT() GPIOA->ODR = 0xFFFF; #define GPIOA_L_DEF() GPIOA->CRL = 0x08888888; /* Ai7 K2 xxx xxx xxx xxx xxx xxx */ @@ -59,7 +54,7 @@ #define GPIOB_L_DEF() GPIOB->CRL = 0x44838800; /* SDA SCL It1 Po It2 xxx Ai9 Ai8 */ #define GPIOB_H_DEF() GPIOB->CRH = 0x88888888; /* xxx xxx xxx xxx xxx xxx xxx xxx */ -//--------------------------------- RCC ���� ---------------------------------// +//--------------------------------- RCC Clock Config ---------------------------------// #define RCC_PLL_EN() RCC->CR |= 0x01000000;// PLL En diff --git a/workspace/ts100/src/Bios.c b/workspace/ts100/src/Bios.c index 8ceba44e..31b0d29f 100644 --- a/workspace/ts100/src/Bios.c +++ b/workspace/ts100/src/Bios.c @@ -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) diff --git a/workspace/ts100/src/CTRL.c b/workspace/ts100/src/CTRL.c index 9632f0c0..a69f57f7 100644 --- a/workspace/ts100/src/CTRL.c +++ b/workspace/ts100/src/CTRL.c @@ -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; // diff --git a/workspace/ts100/src/Flash.c b/workspace/ts100/src/Flash.c deleted file mode 100644 index ee5b4f73..00000000 --- a/workspace/ts100/src/Flash.c +++ /dev/null @@ -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 ******************************/ diff --git a/workspace/ts100/src/Hardware.c b/workspace/ts100/src/Hardware.c index 0a0294df..da59a702 100644 --- a/workspace/ts100/src/Hardware.c +++ b/workspace/ts100/src/Hardware.c @@ -27,64 +27,38 @@ u32 gKey_in; u8 gLongkey_flag = 0; u8 gAlarm_type = 1; /******************************************************************************* - ������: Get_CalFlag - ��������:��ȡУ׼״̬ - �������:NULL - ���ز���:У׼״̬��־ + *******************************************************************************/ u32 Get_CalFlag(void) { return gCalib_flag; } /******************************************************************************* - ������: Get_gKey - ��������:��ȡ����״̬ - �������:NULL - ���ز���:����״̬ + *******************************************************************************/ u32 Get_gKey(void) { return gKey_in; } /******************************************************************************* - ������: Set_gKey - ��������:���ð���״̬ - �������:Ҫ���õİ���״̬ - ���ز���:NULL + *******************************************************************************/ void Set_gKey(u32 key) { gKey_in = key; } /******************************************************************************* - ������: Set_LongKeyFlag - ��������:���ó�������־ - �������:0 :�����Գ����� 1: ���Գ��� - ���ز���:NULL + *******************************************************************************/ void Set_LongKeyFlag(u32 flag) { gLongkey_flag = flag; } /******************************************************************************* - ������: Get_AlarmType - ��������:��ȡ�������� - �������:NULL - ���ز���: �������� - 0:���� - 1:sensor - err - 2:���� - 3:��ѹ + *******************************************************************************/ u8 Get_AlarmType(void) { return gAlarm_type; } /******************************************************************************* - ������: Set_AlarmType - ��������:���ñ������� - �������: �������� - 0:���� - 1:sen - err - 2:���� - 3:��ѹ - ���ز���: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; //����3500 } - tmp = (tmp * 10 / 144); //��ѹvb = 3.3 * 85 *ad / 40950 + tmp = (tmp * 10 / 144); //��ѹ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); } /******************************************************************************* - ������: Scan_Key - ��������:ɨ�����(50msÿ��) - �������:NULL - ���ز���: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 :���Ƴ�������־ + 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); //������ + Set_gKey(KEY_CN | key_state); } else { p_cnt = 0; key_statuslast = key_state; @@ -162,10 +133,7 @@ void Scan_Key(void) { } /******************************************************************************* - ������: Get_SlAvg - ��������:����ƽ��ֵ - �������:avg_data ƽ����ADֵ - ���ز���:����ƽ��ֵ + *******************************************************************************/ 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) { } } /******************************************************************************* - ������: Get_Temp - ��������:�������,�ȶ��¶�,����AD�����¶� - �������:wk_temp �����¶� - ���ز���:ʵ���¶� + *******************************************************************************/ s16 Get_Temp(s16 wk_temp) { int ad_value, cool_tmp, compensation = 0; diff --git a/workspace/ts100/src/Main.c b/workspace/ts100/src/Main.c index f9b6183d..e0b3819a 100644 --- a/workspace/ts100/src/Main.c +++ b/workspace/ts100/src/Main.c @@ -14,7 +14,6 @@ #include "Bios.h" #include "I2C.h" -#include "Flash.h" #include "MMA8652FC.h" #include "UI.h" #include "Oled.h" diff --git a/workspace/ts100/src/UI.c b/workspace/ts100/src/UI.c index 1d0e1685..3137d883 100644 --- a/workspace/ts100/src/UI.c +++ b/workspace/ts100/src/UI.c @@ -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); } /*******************************************************************************