Temp: faster cycles in continuous mode.
Thermistors and AD595 can be faster in that mode. The new stategy is: 1. read the value 2. start the adc 3. return the result - next cycle instead of: 1. start the adc - wait 10ms 2. read the value 3. return the result - next cycle Review changes by Traumflug: fixed the warnings appearing in some configurations (case NEEDS_START_ADC undefined and case NEEDS_START_ADC defined, but TEMP_READ_CONTINUOUS == 0)
This commit is contained in:
parent
66f06d20a2
commit
efb781bed5
37
temp.c
37
temp.c
|
|
@ -268,17 +268,31 @@ static uint16_t temp_read_max6675(temp_sensor_t i) {
|
||||||
|
|
||||||
#ifdef TEMP_THERMISTOR
|
#ifdef TEMP_THERMISTOR
|
||||||
static uint16_t temp_read_thermistor(temp_sensor_t i) {
|
static uint16_t temp_read_thermistor(temp_sensor_t i) {
|
||||||
|
// Needs to be 'static', else GCC diagnostics emits a warning "'result' may
|
||||||
|
// be used uninitialized". No surprise about this warning, it's part of the
|
||||||
|
// logic that in some configurations temp_sensors_runtime[i].active never
|
||||||
|
// reaches more than 1.
|
||||||
|
static uint16_t result;
|
||||||
|
|
||||||
switch (temp_sensors_runtime[i].active++) {
|
switch (temp_sensors_runtime[i].active++) {
|
||||||
case 1: // Start ADC conversion.
|
case 1: // Start ADC conversion.
|
||||||
#ifdef NEEDS_START_ADC
|
#ifdef NEEDS_START_ADC
|
||||||
|
#if TEMP_READ_CONTINUOUS
|
||||||
|
result = analog_read(i);
|
||||||
|
#endif
|
||||||
start_adc();
|
start_adc();
|
||||||
return TEMP_NOT_READY;
|
#if ! TEMP_READ_CONTINUOUS
|
||||||
|
return TEMP_NOT_READY;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// else fall through to conversion
|
// If not in continuous mode or no need for start_adc() fall through.
|
||||||
|
|
||||||
case 2: // Convert temperature values.
|
case 2: // Convert temperature values.
|
||||||
|
#if ! defined NEEDS_START_ADC || ! TEMP_READ_CONTINUOUS
|
||||||
|
result = analog_read(i);
|
||||||
|
#endif
|
||||||
temp_sensors_runtime[i].active = 0;
|
temp_sensors_runtime[i].active = 0;
|
||||||
return temp_table_lookup(analog_read(i), i);
|
return temp_table_lookup(result, i);
|
||||||
}
|
}
|
||||||
return TEMP_NOT_READY;
|
return TEMP_NOT_READY;
|
||||||
}
|
}
|
||||||
|
|
@ -326,19 +340,30 @@ static uint16_t temp_read_mcp3008(temp_sensor_t i) {
|
||||||
|
|
||||||
#ifdef TEMP_AD595
|
#ifdef TEMP_AD595
|
||||||
static uint16_t temp_read_ad595(temp_sensor_t i) {
|
static uint16_t temp_read_ad595(temp_sensor_t i) {
|
||||||
|
// Needs to be 'static', see comment in temp_read_thermistor().
|
||||||
|
static uint16_t result;
|
||||||
|
|
||||||
switch (temp_sensors_runtime[i].active++) {
|
switch (temp_sensors_runtime[i].active++) {
|
||||||
case 1: // Start ADC conversion.
|
case 1: // Start ADC conversion.
|
||||||
#ifdef NEEDS_START_ADC
|
#ifdef NEEDS_START_ADC
|
||||||
|
#if TEMP_READ_CONTINUOUS
|
||||||
|
result = analog_read(i);
|
||||||
|
#endif
|
||||||
start_adc();
|
start_adc();
|
||||||
return TEMP_NOT_READY;
|
#if ! TEMP_READ_CONTINUOUS
|
||||||
|
return TEMP_NOT_READY;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// else fall through to conversion
|
// If not in continuous mode or no need for start_adc() fall through.
|
||||||
|
|
||||||
case 2: // Convert temperature values.
|
case 2: // Convert temperature values.
|
||||||
|
#if ! TEMP_READ_CONTINUOUS
|
||||||
|
result = analog_read(i);
|
||||||
|
#endif
|
||||||
temp_sensors_runtime[i].active = 0;
|
temp_sensors_runtime[i].active = 0;
|
||||||
// Convert >> 8 instead of >> 10 because internal temp is stored as
|
// Convert >> 8 instead of >> 10 because internal temp is stored as
|
||||||
// 14.2 fixed point.
|
// 14.2 fixed point.
|
||||||
return (analog_read(i) * 500L) >> 8;
|
return (result * 500L) >> 8;
|
||||||
}
|
}
|
||||||
return TEMP_NOT_READY;
|
return TEMP_NOT_READY;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue