Add thermistor voltage readings to analogue.c

analogue.c is now configured from hw_config.h. Refactored a few things including the testcase.
master
Richard Meadows 2015-10-06 23:39:36 +01:00
rodzic ec98df64f9
commit 1171a90e98
7 zmienionych plików z 111 dodań i 61 usunięć

Wyświetl plik

@ -26,9 +26,11 @@
#define ANALOGUE_H
void start_adc_conversion_sequence(void);
uint8_t is_adc_conversion_done(void);
void start_adc_sequence(void);
uint8_t is_adc_sequence_done(void);
float get_battery(void);
float get_thermistor(void);
float get_solar(void);
#endif /* ANALOGUE_H */

Wyświetl plik

@ -118,6 +118,7 @@
#define THERMISTOR_ADC_PIN PIN_PA03
#define THERMISTOR_ADC_PINMUX PINMUX_PA03
#define THERMISTOR_ADC_CHANNEL ADC_POSITIVE_INPUT_PIN1
#define THERMISTOR_ADC_CHANNEL_DIV 1
/**
* Solar ADC

Wyświetl plik

@ -27,17 +27,25 @@
#include "system/interrupt.h"
#include "hw_config.h"
float battery_v = 0.0, solar_v = 0.0;
float battery_v = 0.0, thermistor_v = 0.0, solar_v = 0.0;
#define ADC_GAINF ADC_GAIN_FACTOR_DIV2
#define ADC_GAINF_VAL 0.5
#define ADC_RESOLUTION ADC_RESOLUTION_12BIT
#define ADC_RESOLUTION_VAL 4096
enum {
enum adc_phase_t {
ADC_PHASE_NONE,
ADC_PHASE_START,
#if BATTERY_ADC
ADC_PHASE_CONVERT_BATTERY,
#endif
#if THERMISTOR_ADC
ADC_PHASE_CONVERT_THERMISTOR,
#endif
#if SOLAR_ADC
ADC_PHASE_CONVERT_SOLAR,
#endif
ADC_PHASE_DONE,
} adc_phase = ADC_PHASE_NONE;
@ -66,11 +74,64 @@ void configure_adc(enum adc_positive_input input)
irq_register_handler(ADC_IRQn, ADC_INT_PRIO);
}
/**
* Gets the channel to sample in the current phase
*/
enum adc_positive_input adc_get_channel(enum adc_phase_t phase)
{
switch (phase) {
#if BATTERY_ADC
case ADC_PHASE_CONVERT_BATTERY: return BATTERY_ADC_CHANNEL;
#endif
#if THERMISTOR_ADC
case ADC_PHASE_CONVERT_THERMISTOR: return THERMISTOR_ADC_CHANNEL;
#endif
#if SOLAR_ADC
case ADC_PHASE_CONVERT_SOLAR: return SOLAR_ADC_CHANNEL;
#endif
default: return SOLAR_ADC_CHANNEL;
}
}
/**
* Assigns the value for the current phase
*/
void assign_adc_value(enum adc_phase_t phase, float pin_v)
{
switch (phase) {
#if BATTERY_ADC
case ADC_PHASE_CONVERT_BATTERY:
battery_v = pin_v / BATTERY_ADC_CHANNEL_DIV;
break;
#endif
#if THERMISTOR_ADC
case ADC_PHASE_CONVERT_THERMISTOR:
thermistor_v = pin_v / THERMISTOR_ADC_CHANNEL_DIV;
break;
#endif
#if SOLAR_ADC
case ADC_PHASE_CONVERT_SOLAR:
solar_v = pin_v / SOLAR_ADC_CHANNEL_DIV;
break;
#endif
default:
break;
}
}
/**
* Is the ADC sequence done?
*/
uint8_t is_adc_sequence_done(void) {
return (adc_phase == ADC_PHASE_DONE);
}
/**
* Called on a ADC result ready event
*/
void adc_complete_callback(void) {
uint16_t result;
uint16_t result = 0;
float pin_v;
adc_read(&result);
@ -78,60 +139,44 @@ void adc_complete_callback(void) {
pin_v = (float)result / (ADC_GAINF_VAL * ADC_RESOLUTION_VAL);
if (adc_phase == ADC_PHASE_CONVERT_BATTERY) {
/* Battery */
/* Calcuate the battery votage */
battery_v = pin_v / BATTERY_ADC_CHANNEL_DIV;
/* Next up: Solar */
configure_adc(SOLAR_ADC_CHANNEL);
adc_start_conversion();
} else {
/* Solar */
/* Calculate the solar voltage */
solar_v = pin_v / SOLAR_ADC_CHANNEL_DIV;
}
/* Assign this value to the correct channel */
assign_adc_value(adc_phase, pin_v);
adc_phase++;
if (!is_adc_sequence_done()) { /* Another channel still to do.. */
/* Start conversion on this channel */
configure_adc(adc_get_channel(adc_phase));
adc_start_conversion();
}
}
void start_adc_conversion_sequence(void)
/**
* Called to start the ADC sequence
*/
void start_adc_sequence(void)
{
/* First up: Battery */
configure_adc(BATTERY_ADC_CHANNEL);
/* Move to the first sampling phase */
adc_phase = ADC_PHASE_START;
adc_phase++;
/* Start conversion on this channel */
configure_adc(adc_get_channel(adc_phase));
adc_start_conversion();
adc_phase = ADC_PHASE_CONVERT_BATTERY;
}
uint8_t is_adc_conversion_done(void) {
return (adc_phase == ADC_PHASE_DONE);
}
/**
* Getters
*/
float get_battery(void)
{
return battery_v;
}
float get_thermistor(void)
{
return thermistor_v;
}
float get_solar(void)
{
return solar_v;
}
/* float get_temperature(void) */
/* { */
/* configure_adc(TEMP_ADC); */
/* adc_start_conversion(&adc_instance); */
/* uint16_t result; */
/* do { */
/* /\* Wait for conversion to be done and read out result *\/ */
/* } while (adc_read(&adc_instance, &result) == ADC_STATUS_BUSY); */
/* /\* 12-bit, 1V ref, div 2 *\/ */
/* float voltage = (float)(result * 2) / 4096; */
/* float millivolt_offset = (voltage - 0.667) * 1000; */
/* /\* Temperature? Uncalibrated.. *\/ */
/* return 25 + (millivolt_offset / 2.4); */
/* } */

Wyświetl plik

@ -54,7 +54,7 @@ void collect_data_async(void)
measure_xosc(XOSC_MEASURE_TIMEPULSE, xosc_measure_callback);
/* Analogue Measurements */
start_adc_conversion_sequence();
start_adc_sequence();
}
/**
* Collects data synchronously and return datapoint

Wyświetl plik

@ -2,29 +2,30 @@
#define __verification__
#endif
/****************************//* adc_battery_solar_read_tc *//****************************/
/****************************//* analogue_read_tc *//****************************/
/**
* Write a description of your test case here
*/
#include "analogue.h"
/* Parameters in */
struct adc_battery_solar_read_tc_params {
struct analogue_read_tc_params {
/* Input paramters to your test case go here */
uint32_t dummy;
} adc_battery_solar_read_tc_params;
} analogue_read_tc_params;
/* Results out */
struct adc_battery_solar_read_tc_results {
struct analogue_read_tc_results {
/* Result values should be populated here */
float battery;
float thermistor;
float solar;
} adc_battery_solar_read_tc_results;
} analogue_read_tc_results;
/* Function */
__verification__ void adc_battery_solar_read_tc(void) {
__verification__ void analogue_read_tc(void) {
/**
* The main body of the test case goes here.
@ -33,9 +34,10 @@ __verification__ void adc_battery_solar_read_tc(void) {
* results structure at the end
*/
start_adc_conversion_sequence();
while (!is_adc_conversion_done());
start_adc_sequence();
while (!is_adc_sequence_done());
adc_battery_solar_read_tc_results.battery = get_battery();
adc_battery_solar_read_tc_results.solar = get_solar();
analogue_read_tc_results.battery = get_battery();
analogue_read_tc_results.thermistor = get_thermistor();
analogue_read_tc_results.solar = get_solar();
}

Wyświetl plik

@ -14,7 +14,7 @@ from random import randint
# Test Script
# ------------------------------------------------------------------------------
class adc_battery_solar_read_tc:
class analogue_read_tc:
def __init__(self):
self.name = self.__class__.__name__
self.iterations = 20
@ -22,7 +22,7 @@ class adc_battery_solar_read_tc:
def get_test(self):
"""Returns some suitable test parameters"""
params = main.struct_adc_battery_solar_read_tc_params()
params = main.struct_analogue_read_tc_params()
"""
Assign input parameters here

Wyświetl plik

@ -46,7 +46,7 @@
#include "backlog_write_read.h"
#include "backlog_read.h"
#include "mem_erase_all.h"
#include "adc_battery_solar_read.h"
#include "analogue_read.h"
#include "gps_baud_error.h"
#include "crc32_gen_buf.h"
#include "barometric_altitude.h"