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:
parent
708289714f
commit
7805e741cd
10
analog-arm.c
10
analog-arm.c
|
|
@ -68,7 +68,7 @@ void analog_init() {
|
||||||
|
|
||||||
/** Read analog value.
|
/** 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.
|
\return Analog reading, 10-bit right aligned.
|
||||||
|
|
||||||
|
|
@ -76,7 +76,13 @@ void analog_init() {
|
||||||
there's no need to hold them in a copy.
|
there's no need to hold them in a copy.
|
||||||
*/
|
*/
|
||||||
uint16_t analog_read(uint8_t index) {
|
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__ */
|
#endif /* defined TEACUP_C_INCLUDE && defined __ARMEL__ */
|
||||||
|
|
|
||||||
16
analog-avr.c
16
analog-avr.c
|
|
@ -12,18 +12,10 @@
|
||||||
static uint8_t adc_counter;
|
static uint8_t adc_counter;
|
||||||
static volatile uint16_t BSS adc_result[NUM_TEMP_SENSORS];
|
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
|
//! Configure all registers, start interrupt loop
|
||||||
void analog_init() {
|
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.
|
// clear ADC bit in power reduction register because of ADC use.
|
||||||
#ifdef PRR
|
#ifdef PRR
|
||||||
PRR &= ~MASK(PRADC);
|
PRR &= ~MASK(PRADC);
|
||||||
|
|
@ -56,7 +48,7 @@ void analog_init() {
|
||||||
|
|
||||||
// now we start the first conversion and leave the rest to the interrupt
|
// now we start the first conversion and leave the rest to the interrupt
|
||||||
ADCSRA |= MASK(ADIE) | MASK(ADSC);
|
ADCSRA |= MASK(ADIE) | MASK(ADSC);
|
||||||
} /* analog_mask > 0 */
|
} /* analog_mask */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Analog Interrupt
|
/*! Analog Interrupt
|
||||||
|
|
@ -65,7 +57,7 @@ void analog_init() {
|
||||||
*/
|
*/
|
||||||
ISR(ADC_vect, ISR_NOBLOCK) {
|
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
|
// 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
|
// store next result
|
||||||
adc_result[adc_counter] = ADC;
|
adc_result[adc_counter] = ADC;
|
||||||
|
|
||||||
|
|
|
||||||
11
analog.c
11
analog.c
|
|
@ -22,6 +22,17 @@
|
||||||
;
|
;
|
||||||
#undef DEFINE_TEMP_SENSOR
|
#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
|
#define TEACUP_C_INCLUDE
|
||||||
#include "analog-avr.c"
|
#include "analog-avr.c"
|
||||||
#include "analog-arm.c"
|
#include "analog-arm.c"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue