Added thermistor equations, c from Adam Cately

master
Richard Meadows 2015-10-10 20:38:02 +01:00
rodzic 6f3db1a14c
commit f35ccb540b
8 zmienionych plików z 188 dodań i 3 usunięć

Wyświetl plik

@ -0,0 +1,30 @@
/*
* Thermistor equations
* Copyright (C) 2015 Adam Cately, Richard Meadows
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef THERMISTOR_H
#define THERMISTOR_H
float thermistor_voltage_to_temperature(float voltage);
#endif /* THERMISTOR_H */

Wyświetl plik

@ -33,6 +33,7 @@
#include "gps.h"
#include "ubx_messages.h"
#include "telemetry.h"
#include "thermistor.h"
#include "watchdog.h"
struct tracker_datapoint datapoint = {.time={0}};
@ -68,6 +69,7 @@ struct tracker_datapoint* collect_data(void)
datapoint.battery = get_battery(); /* Will return zero by default */
datapoint.solar = get_solar(); /* Will return zero by default */
datapoint.radio_die_temperature = telemetry_si_temperature();
datapoint.thermistor_temperature = thermistor_voltage_to_temperature(get_thermistor());
/**
* ---- Barometer ----

Wyświetl plik

@ -0,0 +1,41 @@
#ifndef __verification__
#define __verification__
#endif
/****************************//* adc_battery_solar_read_tc *//****************************/
/**
* Write a description of your test case here
*/
#include "analogue.h"
/* Parameters in */
struct adc_battery_solar_read_tc_params {
/* Input paramters to your test case go here */
uint32_t dummy;
} adc_battery_solar_read_tc_params;
/* Results out */
struct adc_battery_solar_read_tc_results {
/* Result values should be populated here */
float battery;
float solar;
} adc_battery_solar_read_tc_results;
/* Function */
__verification__ void adc_battery_solar_read_tc(void) {
/**
* The main body of the test case goes here.
*
* Use the input parameters to run the test case. Populate the
* results structure at the end
*/
start_adc_conversion_sequence();
while (!is_adc_conversion_done());
adc_battery_solar_read_tc_results.battery = get_battery();
adc_battery_solar_read_tc_results.solar = get_solar();
}

Wyświetl plik

@ -7,6 +7,7 @@
* Write a description of your test case here
*/
#include "analogue.h"
#include "thermistor.h"
/* Parameters in */
struct analogue_read_tc_params {
@ -38,6 +39,6 @@ __verification__ void analogue_read_tc(void) {
while (!is_adc_sequence_done());
analogue_read_tc_results.battery = get_battery();
analogue_read_tc_results.thermistor = get_thermistor();
analogue_read_tc_results.thermistor = thermistor_voltage_to_temperature(get_thermistor());
analogue_read_tc_results.solar = get_solar();
}

Wyświetl plik

@ -37,7 +37,8 @@ class analogue_read_tc:
Compare result and params here, decide sth.
Can use print_info
"""
print_info("Battery: {}V".format(result["battery"]))
print_info("Solar: {}V".format(result["solar"]))
print_info("Battery: {}V".format(result["battery"]))
print_info("Solar: {}V".format(result["solar"]))
print_info("Thermistor: {}degC".format(result["thermistor"]))
return True

Wyświetl plik

@ -0,0 +1,38 @@
#ifndef __verification__
#define __verification__
#endif
/****************************//* thermistor_equation_tc *//****************************/
/**
* Write a description of your test case here
*/
#include "thermistor.h"
/* Parameters in */
struct thermistor_equation_tc_params {
/* Input paramters to your test case go here */
float value;
} thermistor_equation_tc_params;
/* Results out */
struct thermistor_equation_tc_results {
/* Result values should be populated here */
float temperature;
} thermistor_equation_tc_results;
/* Function */
__verification__ void thermistor_equation_tc(void) {
/**
* The main body of the test case goes here.
*
* Use the input parameters to run the test case. Populate the
* results structure at the end
*/
thermistor_equation_tc_results.temperature =
thermistor_voltage_to_temperature(thermistor_equation_tc_params.value);
}

Wyświetl plik

@ -0,0 +1,71 @@
#!/usr/bin/env python
# ------------------------------------------------------------------------------
# Imports
# ------------------------------------------------------------------------------
import sys
sys.path.append("./test")
import main
from random import randint
# ------------------------------------------------------------------------------
# Test Script
# ------------------------------------------------------------------------------
class thermistor_equation_tc:
def __init__(self):
self.name = self.__class__.__name__
# Params
self.series_resistor = 10**5
self.thermistor_nominal = 10**4 # Nominal thermistor resistance at 25 degC
self.tolerance = 1 # Pass/fail error tolerance
# Resistance of thermistor at -55 to 100 degrees every 5 degrees, taken from datasheet
self.resistances = [96.3, 67.01, 47.17, 33.65, 24.26, 17.7, 13.04, 9.707, 7.293,
5.533, 4.232, 3.365, 2.539, 1.99, 1.571, 1.249, 1.000,
0.8057, 0.6531, 0.5327, 0.4369, 0.3603, 0.2986, 0.2488,
0.2083, 0.1752, 0.1481, 0.1258, 0.1072, 0.09117, 0.07885, 0.068];
self.iterations = len(self.resistances)
self.index = 0
def get_test(self):
"""Returns some suitable test parameters"""
params = main.struct_thermistor_equation_tc_params()
"""
Assign input parameters here
"""
i = self.index
# calculate expected ADC value for the current temperature
params.value = (self.series_resistor/(self.resistances[i]*self.thermistor_nominal + self.series_resistor)) * 1.85;
return params
def is_correct(self, params, result, print_info):
"""Returns if a result is correct for the given parameters"""
i = self.index
self.index = self.index + 1
expected = -55+(i*5)
calculated = float(result["temperature"])
"""
Compare result and params here, decide sth.
Can use print_info
"""
error = expected - calculated
print_info("expected: {}degC calculated: {}degC (error: {})".format(expected, calculated, error))
if (abs(error) > self.tolerance):
print_info("ERROR: {}".format(error))
return False
return True

Wyświetl plik

@ -51,6 +51,7 @@
#include "crc32_gen_buf.h"
#include "barometric_altitude.h"
#include "pressure_temperature.h"
#include "thermistor_equation.h"
/* [new_tc] */