analog-arm.c: read not by ADC channel number, but by Teacup number.

Analog reading should be complete by now :-)
This commit is contained in:
Markus Hitter 2015-08-06 20:01:14 +02:00
parent 708289714f
commit 7805e741cd
3 changed files with 23 additions and 14 deletions

View File

@ -68,7 +68,7 @@ void analog_init() {
/** Read analog value.
\param channel Channel to be read.
\param channel Channel to be read. Channel numbering starts at zero.
\return Analog reading, 10-bit right aligned.
@ -76,7 +76,13 @@ void analog_init() {
there's no need to hold them in a copy.
*/
uint16_t analog_read(uint8_t index) {
return (LPC_ADC->DR[index] & 0xFFC0) >> 6;
uint16_t result = 0;
if (index < sizeof(adc_channel) && adc_channel[index] < 8) {
result = (LPC_ADC->DR[adc_channel[index]] & 0xFFC0) >> 6;
}
return result;
}
#endif /* defined TEACUP_C_INCLUDE && defined __ARMEL__ */

View File

@ -12,18 +12,10 @@
static uint8_t adc_counter;
static volatile uint16_t BSS adc_result[NUM_TEMP_SENSORS];
#undef DEFINE_TEMP_SENSOR
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) \
((type == TT_THERMISTOR) || (type == TT_AD595)) ? (pin ## _ADC) : 255,
static uint8_t adc_channel[NUM_TEMP_SENSORS] =
{
#include "config_wrapper.h"
};
#undef DEFINE_TEMP_SENSOR
//! Configure all registers, start interrupt loop
void analog_init() {
if (analog_mask > 0) {
if (analog_mask) { // At least one temp sensor uses an analog channel.
// clear ADC bit in power reduction register because of ADC use.
#ifdef PRR
PRR &= ~MASK(PRADC);
@ -56,7 +48,7 @@ void analog_init() {
// now we start the first conversion and leave the rest to the interrupt
ADCSRA |= MASK(ADIE) | MASK(ADSC);
} /* analog_mask > 0 */
} /* analog_mask */
}
/*! Analog Interrupt
@ -65,7 +57,7 @@ void analog_init() {
*/
ISR(ADC_vect, ISR_NOBLOCK) {
// emulate free-running mode but be more deterministic about exactly which result we have, since this project has long-running interrupts
if (analog_mask > 0) { // at least one temp sensor uses an analog channel
if (analog_mask) {
// store next result
adc_result[adc_counter] = ADC;

View File

@ -22,6 +22,17 @@
;
#undef DEFINE_TEMP_SENSOR
/**
A map of the ADC channels of the defined sensors.
*/
#undef DEFINE_TEMP_SENSOR
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) \
((type == TT_THERMISTOR) || (type == TT_AD595)) ? (pin ## _ADC) : 255,
static uint8_t adc_channel[NUM_TEMP_SENSORS] = {
#include "config_wrapper.h"
};
#undef DEFINE_TEMP_SENSOR
#define TEACUP_C_INCLUDE
#include "analog-avr.c"
#include "analog-arm.c"