diff --git a/.gitignore b/.gitignore
index c1a6737c..36e1dcb0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,7 @@
*.obj
*.elf
*.d
-
+*.DS_Store
# Precompiled Headers
*.gch
*.pch
@@ -34,3 +34,5 @@
*.su
workspace/ts100/Debug/*
workspace/.metadata/*
+
+workspace/ts100/.settings/language.settings.xml
diff --git a/workspace/ts100/.settings/language.settings.xml b/workspace/ts100/.settings/language.settings.xml
deleted file mode 100644
index 36499f56..00000000
--- a/workspace/ts100/.settings/language.settings.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/workspace/ts100/inc/Analog.h b/workspace/ts100/inc/Analog.h
new file mode 100644
index 00000000..ca8dcee7
--- /dev/null
+++ b/workspace/ts100/inc/Analog.h
@@ -0,0 +1,14 @@
+/*
+ * Analog.h
+ *
+ * Created on: 20 Sep 2016
+ * Author: ralim
+ */
+
+#ifndef ANALOG_H_
+#define ANALOG_H_
+#include "stm32f10x.h"
+
+uint16_t Get_ADC1Value(uint8_t i);
+uint16_t readIronTemp(uint16_t calibration);
+#endif /* ANALOG_H_ */
diff --git a/workspace/ts100/src/Analog.c b/workspace/ts100/src/Analog.c
new file mode 100644
index 00000000..df059a3f
--- /dev/null
+++ b/workspace/ts100/src/Analog.c
@@ -0,0 +1,110 @@
+/*
+ * Analog.c
+ *
+ * Created on: 20 Sep 2016
+ * Author: ralim
+ * Contains the functions related to reading and scaling the adc pins
+ * This is used for temperature and battery voltage sense
+ */
+#include "Analog.h"
+
+uint16_t readDCVoltage() {
+ uint16_t reading = 0;
+ for (u8 i = 0; i < 10; i++) {
+ reading += ADC_GetConversionValue(ADC2);
+ }
+ reading /= 144; //take the average and convert to X10 voltage
+ return reading; //return the read voltage
+}
+
+//This reads the thermocouple in the tip
+//This allows us to read it in X10 mode
+//Returns temperature in C X10 mode
+int16_t readTipTemp() {
+ static uint32_t rollingAverage[4];
+ static uint8_t rIndex = 0;
+
+ /*The head has a thermocouple inline with the heater
+ This is read by turning off the heater
+ Then read the output of the op-amp that is connected across the connections
+ */
+ uint32_t ad_sum = 0;
+ uint32_t max = 0, min;
+ uint32_t ad_value, avg_data;
+
+ Set_HeatingTime(0); //set the remaining time to zero
+ HEAT_OFF(); //heater must be off
+ delayMs(50); //wait for the heater to time out
+ uint8_t gMeas_cnt = 9; //how many measurements to make
+ max = ad_sum = min = Get_ADC1Value(0);
+
+ while (gMeas_cnt > 0) {
+ ad_value = Get_ADC1Value(0);
+ ad_sum += ad_value;
+ if (ad_value > max)
+ max = ad_value;
+ if (ad_value < min)
+ min = ad_value;
+
+ gMeas_cnt--;
+ }
+ ad_sum = ad_sum - max - min; //remove the two outliers
+ avg_data = ad_sum / 8; //take the average
+ rollingAverage[rIndex] = avg_data;
+ rIndex = (rIndex + 1) % 4;
+ return (rollingAverage[0] + rollingAverage[1] + rollingAverage[2]
+ + rollingAverage[3]) / 4; //get the average
+
+}
+
+/*******************************************************************************
+ Function:
+ Description:Reads the temperature of the on board temp sensor for calibration
+ http://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf
+ Output: The onboardTemp in C X 10
+ *******************************************************************************/
+int readSensorTemp(void) {
+ static uint32_t rollingAverage[4];
+ static uint8_t rIndex = 0;
+ u32 ad_sum = 0;
+ u32 max, min;
+ u32 ad_value, avg_data, slide_data;
+
+ u8 gMeas_cnt = 9;
+ ad_sum = min = max = Get_ADC1Value(1);
+ while (gMeas_cnt > 0) {
+ ad_value = Get_ADC1Value(1);
+ ad_sum += ad_value;
+ if (ad_value > max)
+ max = ad_value;
+ if (ad_value < min)
+ min = ad_value;
+ gMeas_cnt--;
+ }
+ ad_sum = ad_sum - max - min;
+ avg_data = ad_sum / 8;
+ //^ Removes the two outliers from the data spread
+
+ rollingAverage[rIndex] = avg_data; //store this result
+ rIndex = (rIndex + 1) % 4; //move the index
+ slide_data = (rollingAverage[0] + rollingAverage[1] + rollingAverage[2]
+ + rollingAverage[3]) / 4; //get the average
+ return (250 + (3300 * slide_data / 4096) - 750);
+ //(25 + ((10*(33*gSlide_data)/4096)-75));
+ //^ Convert the reading to C
+
+}
+
+volatile uint16_t ADC1ConvertedValue[2];
+//returns the latest reading from ADC1 that was buffered using DMA
+uint16_t Get_ADC1Value(uint8_t i) {
+ return ADC1ConvertedValue[i];
+}
+//This returns the calibrated temperature reading of the iron temp
+uint16_t readIronTemp(uint16_t calibration_temp) {
+ static uint16_t calTemp = 0;
+ if (calibration_temp != 0)
+ calTemp = calibration_temp;
+ return (readTipTemp() * 1000 + 806 * readSensorTemp() - calTemp * 1000)
+ / 806;
+}
diff --git a/workspace/ts100/src/Bios.c b/workspace/ts100/src/Bios.c
index 17339e87..78ddd10f 100644
--- a/workspace/ts100/src/Bios.c
+++ b/workspace/ts100/src/Bios.c
@@ -15,74 +15,8 @@
#include
/******************************************************************************/
#define ADC1_DR_Address ((u32)0x4001244C)
-
-vu32 gTimeOut, gMs_timeout;
-volatile u32 gTime[8]; //times for timer storage
-//^-- gTime is automatically decremented on each firing of timer 2 if >0
-vu16 ADC1ConvertedValue[2];
vu32 gHeat_cnt = 0;
-/*******************************************************************************
- ������: Get_AdcValue
- ��������:��ȡADC ת����Ķ���
- �������:ת�����AD
- ���ز���:NULL
- *******************************************************************************/
-u16 Get_AdcValue(u8 i) {
- return ADC1ConvertedValue[i];
-}
-/*******************************************************************************
- ������: Set_HeatingTime
- ��������:���ü���ʱ��
- �������:heating_time ����ʱ��
- ���ز���:NULL
- *******************************************************************************/
-void Set_HeatingTime(u32 heating_time) {
- gHeat_cnt = heating_time;
-}
-/*******************************************************************************
- ������: Get_HeatingTime
- ��������:��ȡ����ʱ��
- �������:NULL
- ���ز���:����ʱ��
- *******************************************************************************/
-u32 Get_HeatingTime(void) {
- return gHeat_cnt;
-}
-/*******************************************************************************
- Function:
- Description: Init the global count down timers
- *******************************************************************************/
-void Init_Gtime(void) {
- u8 i;
-
- for (i = 0; i < 8; i++)
- gTime[i] = 0;
-}
-
-/*******************************************************************************
- ������: Delay_Ms
- ��������:��ʱ����
- �������:��ʱ�ȴ��ĺ�����ֵ
- ���ز���:NULL
- *******************************************************************************/
-void Delay_Ms(u32 ms) {
- gMs_timeout = ms * 20;
- while (gMs_timeout)
- ; // {if(Scan_key()!=0)break;}
-}
-/*******************************************************************************
- ������: Delay_HalfMs
- ��������:ÿ��λΪ0.5�������ʱ����
- �������:��ʱ�ȴ���0.5������
- ���ز���:NULL
- *******************************************************************************/
-void Delay_HalfMs(u32 ms) {
- gMs_timeout = ms * 10;
- while (gMs_timeout)
- ; // {if(Scan_key()!=0)break;}
-}
-
/*******************************************************************************
Function:RCC_Config
Description:Setup the system clocks to use internal HSE to run the system at 48Mhz
diff --git a/workspace/ts100/src/Hardware.c b/workspace/ts100/src/Hardware.c
index aa7a1c7b..9c203d13 100644
--- a/workspace/ts100/src/Hardware.c
+++ b/workspace/ts100/src/Hardware.c
@@ -132,128 +132,6 @@ void Scan_Key(void) {
}
-/*******************************************************************************
-
- *******************************************************************************/
-u32 Get_SlAvg(u32 avg_data) {
- static u32 sum_avg = 0;
- static u8 init_flag = 0;
- u16 si_avg = sum_avg / SI_COE, abs;
-
- if (init_flag == 0) { /*��һ���ϵ�*/
- sum_avg = SI_COE * avg_data;
- init_flag = 1;
- return sum_avg / SI_COE;
- }
- if (avg_data > si_avg)
- abs = avg_data - si_avg;
- else
- abs = si_avg - avg_data;
-
- if (abs > SI_THRESHOLD)
- sum_avg = SI_COE * avg_data;
- else
- sum_avg += avg_data - sum_avg / SI_COE;
-
- return sum_avg / SI_COE;
-}
-
-/*******************************************************************************
- Function:
- Description: Read the thermocouple in the soldering iron head
- Output:Soldering Iron temperature
- *******************************************************************************/
-u32 Get_AvgAd(void) {
- /*The head has a thermocouple inline with the heater
- This is read by turning off the heater
- Then read the output of the op-amp that is connected across the connections
- */
- 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(50); //wait for the heater to time out
- gMeas_cnt = 10; //how many measurements to make
-
- while (gMeas_cnt > 0) {
- ad_value = Get_AdcValue(0); //Read_Tmp();
- ad_sum += ad_value;
- if (ad_value > max)
- max = ad_value;
- if (ad_value < min)
- min = ad_value;
-
- if (gMeas_cnt == 1) { //We have just taken the last reading
- ad_sum = ad_sum - max - min; //remove the two outliers
- avg_data = ad_sum / 8; //take the average
-
- return Get_SlAvg(avg_data);
-
- }
- gMeas_cnt--;
- }
- return 0; //should never ever hit here
-}
-
-/*******************************************************************************
- Function:
- Description:
- *******************************************************************************/
-int Get_TempSlAvg(int avg_data) {
- static int sum_avg = 0;
- static u8 init_flag = 0;
-
- if (init_flag == 0) {
- sum_avg = 8 * avg_data;
- init_flag = 1;
- return sum_avg / 8;
- }
-
- sum_avg += avg_data - sum_avg / 8;
-
- return sum_avg / 8;
-}
-
-/*******************************************************************************
- Function:
- Description:Reads the temperature of the on board temp sensor for calibration
- http://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf
- Output: The onboardTemp in C
- *******************************************************************************/
-int Get_SensorTmp(void) {
- u32 ad_sum = 0;
- u32 max = 0, min = 5000;
- u32 ad_value, avg_data, slide_data;
- int sensor_temp = 0;
-
- gMeas_cnt = 10;
-
- while (gMeas_cnt > 0) {
- ad_value = Get_AdcValue(1);
- ad_sum += ad_value;
- if (ad_value > max)
- max = ad_value;
- if (ad_value < min)
- min = ad_value;
-
- if (gMeas_cnt == 1) {
- ad_sum = ad_sum - max - min;
- avg_data = ad_sum / 8;
- //^ Removes the two outliers from the data spread
- slide_data = Get_TempSlAvg(avg_data);
- sensor_temp = (250 + (3300 * slide_data / 4096) - 750); //(25 + ((10*(33*gSlide_data)/4096)-75));
- //^ Convert the reading to C
- ad_sum = 0;
- min = 5000;
- max = 0;
- }
- gMeas_cnt--;
- }
- return sensor_temp;
-}
-
/*******************************************************************************
Function:
Description: Reads the Zero Temp.. And does something..
diff --git a/workspace/ts100/src/Interrupt.c b/workspace/ts100/src/Interrupt.c
index c627c65b..eda231ac 100644
--- a/workspace/ts100/src/Interrupt.c
+++ b/workspace/ts100/src/Interrupt.c
@@ -7,10 +7,17 @@
#include "I2C.h"
volatile uint32_t system_Ticks;
+void delayMs(uint32_t ticks)
+{
+ uint32_t endtime = ticks+millis();
+ while(millis()