Change analog driver to use extra ADCs

This commit is contained in:
Gautier Hattenberger
2010-03-02 17:52:49 +00:00
parent b2faa4a5d0
commit add89ceb33
5 changed files with 151 additions and 20 deletions
+118 -3
View File
@@ -23,12 +23,19 @@
#include "booz2_analog.h"
#include "armVIC.h"
#include "sys_time.h"
#include "booz2_analog_baro.h"
#include "booz2_battery.h"
#ifndef USE_EXTRA_ADC
/* Default mode
* Bust OFF
* Only one ADC can be read on each bank
* Baro and Bat are read on interrupt
*/
#include "armVIC.h"
#include "sys_time.h"
void ADC0_ISR ( void ) __attribute__((naked));
void ADC1_ISR ( void ) __attribute__((naked));
@@ -112,3 +119,111 @@ void ADC1_ISR ( void ) {
ISR_EXIT(); // recover registers and return
}
#else // USE_EXTRA_ADC
/* Extra ADCs are read
* Bust ON
* Baro and Bat values are updated by hand
* Four ADCs can be configured
* ADC_1 is available on the cam connector
*/
#include "LPC21xx.h"
#include "sys_time.h"
uint16_t booz2_adc_1;
uint16_t booz2_adc_2;
uint16_t booz2_adc_3;
uint16_t booz2_adc_4;
void booz2_analog_init_hw( void ) {
/* AD0 */
/* PCLK/4 ( 3.75MHz) - BURST - ON */
AD0CR = 0x03 << 8 | 1 << 16 | 1 << 21;
/* disable global interrupt */
ClearBit(AD0INTEN,8);
/* AD1 */
/* PCLK/4 ( 3.75MHz) - BURST - ON */
AD1CR = 0x03 << 8 | 1 << 16 | 1 << 21;
/* disable global interrupt */
ClearBit(AD1INTEN,8);
/* select P0.29 as AD0.2 for bat meas*/
PINSEL1 |= 0x01 << 26;
/* sample AD0.2 */
AD0CR |= 1 << 2;
/* select P0.10 as AD1.2 for baro*/
ANALOG_BARO_PINSEL |= ANALOG_BARO_PINSEL_VAL << ANALOG_BARO_PINSEL_BIT;
/* sample AD1.2 */
AD1CR |= 1 << 2;
/* turn on DAC pins */
PINSEL1 |= 2 << 18;
#ifdef USE_ADC_1
/* select P0.13 as AD1.4 adc 1 */
PINSEL0 |= 0x03 << 26;
AD1CR |= 1 << 4;
#endif
#ifdef USE_ADC_2
/* select P0.4 as AD0.6 adc 2 */
PINSEL0 |= 0x03 << 8;
AD0CR |= 1 << 6;
#endif
#ifdef USE_ADC_3
/* select P0.5 as AD0.7 adc 3 */
PINSEL0 |= 0x03 << 10;
AD0CR |= 1 << 7;
#endif
#ifdef USE_ADC_4
/* select P0.6 as AD1.0 adc 4 */
PINSEL0 |= 0x03 << 12;
AD1CR |= 1 << 0;
#endif
booz2_adc_1 = 0;
booz2_adc_2 = 0;
booz2_adc_3 = 0;
booz2_adc_4 = 0;
}
void booz2_analog_baro_read(void) {
uint32_t tmp = AD1DR2;
uint16_t tmp2 = (uint16_t)(tmp >> 6) & 0x03FF;
Booz2BaroISRHandler(tmp2);
}
void booz2_analog_bat_read(void) {
uint32_t tmp = AD0DR2;
uint16_t tmp2 = (uint16_t)(tmp >> 6) & 0x03FF;
Booz2BatteryISRHandler(tmp2);
}
void booz2_analog_extra_adc_read(void) {
uint32_t tmp,tmp2;
#ifdef USE_ADC_1
tmp = AD1DR4;
tmp2 = (uint16_t)(tmp >> 6) & 0x03FF;
booz2_adc_1 = tmp2;
#endif
#ifdef USE_ADC_2
tmp = AD0DR6;
tmp2 = (uint16_t)(tmp >> 6) & 0x03FF;
booz2_adc_2 = tmp2;
#endif
#ifdef USE_ADC_3
tmp = AD0DR7;
tmp2 = (uint16_t)(tmp >> 6) & 0x03FF;
booz2_adc_3 = tmp2;
#endif
#ifdef USE_ADC_4
tmp = AD1DR0;
tmp2 = (uint16_t)(tmp >> 6) & 0x03FF;
booz2_adc_4 = tmp2;
#endif
}
#endif
+12
View File
@@ -23,6 +23,8 @@
#include "booz2_analog.h"
#include "std.h"
// battery on AD0.3 on P0.30
// baro on AD0.1 on P0.28
@@ -36,3 +38,13 @@ void booz2_analog_init( void ) {
}
#ifdef USE_EXTRA_ADC
// Read manually baro (100Hz) and bat (10Hz)
void booz2_analog_periodic( void ) {
// baro
RunOnceEvery(5,booz2_analog_baro_read());
// bat
RunOnceEvery(50,booz2_analog_bat_read());
}
#endif
+16
View File
@@ -26,6 +26,22 @@
extern void booz2_analog_init( void );
#ifdef USE_EXTRA_ADC
#include "std.h"
extern uint16_t booz2_adc_1;
extern uint16_t booz2_adc_2;
extern uint16_t booz2_adc_3;
extern uint16_t booz2_adc_4;
extern void booz2_analog_periodic( void );
extern void booz2_analog_baro_read(void);
extern void booz2_analog_bat_read(void);
extern void booz2_analog_extra_adc_read(void);
#endif
#include "booz2_analog_hw.h"
#endif /* BOOZ2_ANALOG_H */
+3 -15
View File
@@ -57,10 +57,6 @@
#include "booz2_pwm_hw.h"
#endif
#ifdef BOOZ2_SONAR
#include "booz2_sonar.h"
#endif
#include "booz2_main.h"
#ifdef SITL
@@ -127,16 +123,12 @@ STATIC_INLINE void booz2_main_init( void ) {
booz2_gps_init();
#endif
#ifdef BOOZ2_SONAR
booz2_sonar_init();
#endif
int_enable();
#ifdef USE_MODULES
modules_init();
#endif
int_enable();
#if defined BOOZ_START_DELAY && ! defined SITL
delay_done = FALSE;
init_done_time = T0TC;
@@ -192,7 +184,7 @@ STATIC_INLINE void booz2_main_periodic( void ) {
booz_gps_periodic();
#endif
#ifdef BOOZ2_SONAR
#ifdef USE_EXTRA_ADC
booz2_analog_periodic();
#endif
@@ -218,10 +210,6 @@ STATIC_INLINE void booz2_main_event( void ) {
Booz2AnalogBaroEvent(on_baro_event);
#ifdef BOOZ2_SONAR
Booz2SonarEvent(booz_ins_update_sonar);
#endif
#ifdef USE_GPS
Booz2GpsEvent(on_gps_event);
#endif
+2 -2
View File
@@ -729,9 +729,9 @@ extern uint8_t telemetry_mode_Main_DefaultChannel;
); \
}
//TODO replace by BOOZ_EXTRA_ADC
#ifdef BOOZ2_SONAR
#include "booz2_sonar.h"
#define PERIODIC_SEND_BOOZ2_SONAR(_chan) DOWNLINK_SEND_BOOZ2_SONAR(_chan,&booz2_sonar_1,&booz2_sonar_2,&booz2_sonar_3,&booz2_sonar_4);
#define PERIODIC_SEND_BOOZ2_SONAR(_chan) DOWNLINK_SEND_BOOZ2_SONAR(_chan,&booz2_adc_1,&booz2_adc_2,&booz2_adc_3,&booz2_adc_4);
#else
#define PERIODIC_SEND_BOOZ2_SONAR(_chan) {}
#endif