creating the temperature functions

This commit is contained in:
Ben V. Brown
2016-09-20 14:33:59 +10:00
parent f700422878
commit 98ca6784a0
8 changed files with 136 additions and 217 deletions

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1236130657" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1712937092972889568" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.release.1113492345" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1773231373176167964" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>

View File

@@ -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_ */

View File

@@ -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;
}

View File

@@ -15,74 +15,8 @@
#include <Hardware.h>
/******************************************************************************/
#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;
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_AdcValue
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡADC ת<><D7AA><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D7AA><EFBFBD><EFBFBD><EFBFBD>AD
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
u16 Get_AdcValue(u8 i) {
return ADC1ConvertedValue[i];
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Set_HeatingTime
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>ʱ<EFBFBD><CAB1>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:heating_time <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Set_HeatingTime(u32 heating_time) {
gHeat_cnt = heating_time;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Get_HeatingTime
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:NULL
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:<3A><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
*******************************************************************************/
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;
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Delay_Ms
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʱ<EFBFBD>ȴ<EFBFBD><C8B4>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>ֵ
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>:NULL
*******************************************************************************/
void Delay_Ms(u32 ms) {
gMs_timeout = ms * 20;
while (gMs_timeout)
; // {if(Scan_key()!=0)break;}
}
/*******************************************************************************
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: Delay_HalfMs
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:ÿ<><C3BF>λΪ0.5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ʱ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>0.5<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>: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

View File

@@ -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) { /*<2A><>һ<EFBFBD><D2BB><EFBFBD>ϵ<EFBFBD>*/
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..

View File

@@ -7,10 +7,17 @@
#include "I2C.h"
volatile uint32_t system_Ticks;
void delayMs(uint32_t ticks)
{
uint32_t endtime = ticks+millis();
while(millis()<endtime);
}
/******************************************************************************/
/* Processor Exceptions Handlers */
/******************************************************************************/
void NMI_Handler(void) {
;
}

View File

@@ -9,8 +9,9 @@
void ProcessUI() {
uint8_t Buttons = Get_gKey(); //read the buttons status
if (millis() - LastButtonPushTime < 50) //rough prevention for debouncing
if (millis() - LastButtonPushTime < 50)
Buttons = 0;
//rough prevention for debouncing and allocates settling time
switch (operatingMode) {
case STARTUP: