move scheduling constants

This commit is contained in:
2016-09-07 13:58:52 +02:00
parent c7041300e6
commit e34a95227d
6 changed files with 201 additions and 22 deletions

View File

@ -15,6 +15,7 @@
#include "time.h"
const uint32_t DISPLAY_CYCLE = 10;
const uint16_t INIT_CYCLE_DELAY = 200;

View File

@ -9,7 +9,7 @@
#define DISPLAY_H_
const uint32_t DISPLAY_CYCLE = 10;
extern const uint32_t DISPLAY_CYCLE;
void displayInit(void *handleArg);
void displayExec(void *handleArg);

View File

@ -24,6 +24,11 @@ const float PT1000_R0 = 1000.0;
const float PT1000_Coeff = 3.85e-3;
const uint32_t MEASURE_CYCLE = 20;
const uint32_t MEASURE_FETCH_RESULT_DELAY = 5;
const uint8_t AVERAGING_CYCLES = 50;
void measureInit(void *handleArg) {
ADC10CTL0 = SREF1 | ADC10SHT_3 | ADC10SR | REFOUT | REFON | REF2_5V | ADC10ON;
@ -34,39 +39,48 @@ void measureInit(void *handleArg) {
void measureCollectAndProcessConversion(void *handleArg);
void measureStartConversion(void *handleArg) {
//gpioSetPin(TESTPIN1, HIGH);
ADC10CTL0 |= ENC | ADC10SC;
schAdd(measureCollectAndProcessConversion, NULL, MEASURE_FETCH_RESULT_DELAY, 0);
//gpioSetPin(TESTPIN1, LOW);
}
void measureCollectAndProcessConversion(void *handleArg) {
static uint32_t averagingSum = 0;
static uint8_t averagingCnt = 0;
//gpioSetPin(TESTPIN2, HIGH);
uint16_t n = 0xffff;
if ((ADC10CTL0 & ADC10IFG) != 0) {
n = ADC10MEM;
ADC10CTL0 &= ~(ADC10IFG | ENC);
}
// process adcValue
// store result in variable temperature
float r = 0.0;
if (n == 0) {
r = 0.0;
} else if (n == N_MAX) {
r = FLT_MAX;
} else {
r = R_REF / ((((float)N_MAX) / ((float)n)) - 1.0);
if (n != 0xffff) {
averagingSum += n;
averagingCnt++;
}
float t = (r / PT1000_R0 - 1) / PT1000_Coeff;
uint8_t temperature = (uint8_t)t;
if (averagingCnt == AVERAGING_CYCLES) {
uint32_t nAvg = averagingSum / averagingCnt;
displaySetValue(temperature);
// displayMuxerSetValue(temperature, true, TEMPERATURE_MUX);
//gpioSetPin(TESTPIN2, LOW);
// process adcValue
// store result in variable temperature
float r = 0.0;
if (nAvg == 0) {
r = 0.0;
} else if (nAvg == N_MAX) {
r = FLT_MAX;
} else {
r = R_REF / ((((float)N_MAX) / ((float)nAvg)) - 1.0);
}
float t = (r / PT1000_R0 - 1) / PT1000_Coeff;
uint8_t temperature = (t < 0) ? 0 : ((uint8_t)t);
displaySetValue(temperature);
// displayMuxerSetValue(temperature, true, TEMPERATURE_MUX);
averagingCnt = 0;
averagingSum = 0;
}
}

View File

@ -12,9 +12,7 @@
const uint32_t MEASURE_CYCLE = 20;
const uint32_t MEASURE_FETCH_RESULT_DELAY = 5;
const uint8_t AVERAGING_COUNT = 100;
extern const uint32_t MEASURE_CYCLE;
void measureInit(void *handleArg);