mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Updated ADC to use the 3 auxillary inputs on the OpenPilot board.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@312 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
e1504dafc6
commit
f75fa5e567
@ -134,6 +134,7 @@ SRC += $(PIOSSTM32F10X)/pios_pwm.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_debug.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_gpio.c
|
||||
|
||||
## PIOS Hardware (Common)
|
||||
SRC += $(PIOSCOMMON)/pios_sdcard.c
|
||||
|
@ -310,66 +310,51 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
|
||||
// PIOS_ADC_PinGet(1) = Power Sensor (Current)
|
||||
// PIOS_ADC_PinGet(2) = Power Sensor (Voltage)
|
||||
// PIOS_ADC_PinGet(3) = On-board 5v Rail Sensor
|
||||
// PIOS_ADC_PinGet(4) = Auxiliary Input 1
|
||||
// PIOS_ADC_PinGet(5) = Auxiliary Input 2
|
||||
// PIOS_ADC_PinGet(6) = Auxiliary Input 3
|
||||
//-------------------------
|
||||
//#define PIOS_ADC_OVERSAMPLING_RATE 1 // (1 to 16)
|
||||
//#define PIOS_ADC_OVERSAMPLING_RATE 1
|
||||
#define PIOS_ADC_USE_TEMP_SENSOR 1
|
||||
#define PIOS_ADC_TEMP_SENSOR_ADC ADC1
|
||||
#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1
|
||||
|
||||
#define PIOS_ADC_PIN1_GPIO_PORT GPIOA // PA1 (Power Sense - Voltage)
|
||||
#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // ADC123_IN1
|
||||
#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_1
|
||||
#define PIOS_ADC_PIN1_ADC ADC1
|
||||
#define PIOS_ADC_PIN1_ADC_NUMBER 2
|
||||
|
||||
#define PIOS_ADC_PIN2_GPIO_PORT GPIOC // PC3 (Power Sense - Current)
|
||||
#define PIOS_ADC_PIN2_GPIO_PIN GPIO_Pin_3 // ADC123_IN13
|
||||
#define PIOS_ADC_PIN2_GPIO_CHANNEL ADC_Channel_13
|
||||
#define PIOS_ADC_PIN2_ADC ADC2
|
||||
#define PIOS_ADC_PIN2_ADC_NUMBER 1
|
||||
|
||||
#define PIOS_ADC_PIN3_GPIO_PORT GPIOC // PC5 (Onboard 5v Sensor) PC5
|
||||
#define PIOS_ADC_PIN3_GPIO_PIN GPIO_Pin_5 // ADC12_IN15
|
||||
#define PIOS_ADC_PIN3_GPIO_CHANNEL ADC_Channel_15
|
||||
#define PIOS_ADC_PIN3_ADC ADC2
|
||||
#define PIOS_ADC_PIN3_ADC_NUMBER 2
|
||||
|
||||
#if 1
|
||||
#define PIOS_ADC_NUM_PINS 3
|
||||
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT, PIOS_ADC_PIN2_GPIO_PORT, PIOS_ADC_PIN3_GPIO_PORT }
|
||||
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN, PIOS_ADC_PIN2_GPIO_PIN, PIOS_ADC_PIN3_GPIO_PIN }
|
||||
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL, PIOS_ADC_PIN2_GPIO_CHANNEL, PIOS_ADC_PIN3_GPIO_CHANNEL }
|
||||
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC, PIOS_ADC_PIN2_ADC, PIOS_ADC_PIN3_ADC }
|
||||
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER, PIOS_ADC_PIN2_ADC_NUMBER, PIOS_ADC_PIN3_ADC_NUMBER }
|
||||
#else
|
||||
#define PIOS_ADC_PIN4_GPIO_PORT GPIOC // PC0 (AUX 1)
|
||||
#define PIOS_ADC_PIN4_GPIO_PIN GPIO_Pin_0 // ADC123_IN10
|
||||
#define PIOS_ADC_PIN4_GPIO_CHANNEL ADC_Channel_10
|
||||
#define PIOS_ADC_PIN4_ADC ADC1
|
||||
#define PIOS_ADC_PIN4_ADC_NUMBER 3
|
||||
|
||||
#define PIOS_ADC_PIN5_GPIO_PORT GPIOC // PC1 (AUX 2)
|
||||
#define PIOS_ADC_PIN5_GPIO_PIN GPIO_Pin_1 // ADC123_IN11
|
||||
#define PIOS_ADC_PIN5_GPIO_CHANNEL ADC_Channel_11
|
||||
#define PIOS_ADC_PIN5_ADC ADC1
|
||||
#define PIOS_ADC_PIN5_ADC_NUMBER 4
|
||||
|
||||
#define PIOS_ADC_PIN6_GPIO_PORT GPIOC // PC2 (AUX 3)
|
||||
#define PIOS_ADC_PIN6_GPIO_PIN GPIO_Pin_2 // ADC123_IN12
|
||||
#define PIOS_ADC_PIN6_GPIO_CHANNEL ADC_Channel_12
|
||||
#define PIOS_ADC_PIN6_ADC ADC2
|
||||
#define PIOS_ADC_PIN6_ADC_NUMBER 3
|
||||
|
||||
#define PIOS_ADC_NUM_PINS 6
|
||||
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT, PIOS_ADC_PIN2_GPIO_PORT, PIOS_ADC_PIN3_GPIO_PORT, PIOS_ADC_PIN4_GPIO_PORT, PIOS_ADC_PIN5_GPIO_PORT, PIOS_ADC_PIN6_GPIO_PORT }
|
||||
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN, PIOS_ADC_PIN2_GPIO_PIN, PIOS_ADC_PIN3_GPIO_PIN, PIOS_ADC_PIN4_GPIO_PIN, PIOS_ADC_PIN5_GPIO_PIN, PIOS_ADC_PIN6_GPIO_PIN }
|
||||
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL, PIOS_ADC_PIN2_GPIO_CHANNEL, PIOS_ADC_PIN3_GPIO_CHANNEL, PIOS_ADC_PIN4_GPIO_CHANNEL, PIOS_ADC_PIN5_GPIO_CHANNEL, PIOS_ADC_PIN6_GPIO_CHANNEL }
|
||||
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC, PIOS_ADC_PIN2_ADC, PIOS_ADC_PIN3_ADC, PIOS_ADC_PIN4_ADC, PIOS_ADC_PIN5_ADC, PIOS_ADC_PIN6_ADC }
|
||||
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER, PIOS_ADC_PIN2_ADC_NUMBER, PIOS_ADC_PIN3_ADC_NUMBER, PIOS_ADC_PIN4_ADC_NUMBER, PIOS_ADC_PIN5_ADC_NUMBER, PIOS_ADC_PIN6_ADC_NUMBER }
|
||||
#endif
|
||||
|
||||
#define PIOS_ADC_PIN4_GPIO_PORT GPIOC // PC0 (AUX 1)
|
||||
#define PIOS_ADC_PIN4_GPIO_PIN GPIO_Pin_0 // ADC123_IN10
|
||||
#define PIOS_ADC_PIN4_GPIO_CHANNEL ADC_Channel_10
|
||||
#define PIOS_ADC_PIN4_ADC ADC1
|
||||
#define PIOS_ADC_PIN4_ADC_NUMBER 3
|
||||
#define PIOS_ADC_PIN5_GPIO_PORT GPIOC // PC1 (AUX 2)
|
||||
#define PIOS_ADC_PIN5_GPIO_PIN GPIO_Pin_1 // ADC123_IN11
|
||||
#define PIOS_ADC_PIN5_GPIO_CHANNEL ADC_Channel_11
|
||||
#define PIOS_ADC_PIN5_ADC ADC2
|
||||
#define PIOS_ADC_PIN5_ADC_NUMBER 3
|
||||
#define PIOS_ADC_PIN6_GPIO_PORT GPIOC // PC2 (AUX 3)
|
||||
#define PIOS_ADC_PIN6_GPIO_PIN GPIO_Pin_2 // ADC123_IN12
|
||||
#define PIOS_ADC_PIN6_GPIO_CHANNEL ADC_Channel_12
|
||||
#define PIOS_ADC_PIN6_ADC ADC1
|
||||
#define PIOS_ADC_PIN6_ADC_NUMBER 4
|
||||
#define PIOS_ADC_NUM_PINS 6
|
||||
#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT, PIOS_ADC_PIN2_GPIO_PORT, PIOS_ADC_PIN3_GPIO_PORT, PIOS_ADC_PIN4_GPIO_PORT, PIOS_ADC_PIN5_GPIO_PORT, PIOS_ADC_PIN6_GPIO_PORT }
|
||||
#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN, PIOS_ADC_PIN2_GPIO_PIN, PIOS_ADC_PIN3_GPIO_PIN, PIOS_ADC_PIN4_GPIO_PIN, PIOS_ADC_PIN5_GPIO_PIN, PIOS_ADC_PIN6_GPIO_PIN }
|
||||
#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL, PIOS_ADC_PIN2_GPIO_CHANNEL, PIOS_ADC_PIN3_GPIO_CHANNEL, PIOS_ADC_PIN4_GPIO_CHANNEL, PIOS_ADC_PIN5_GPIO_CHANNEL, PIOS_ADC_PIN6_GPIO_CHANNEL }
|
||||
#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC, PIOS_ADC_PIN2_ADC, PIOS_ADC_PIN3_ADC, PIOS_ADC_PIN4_ADC, PIOS_ADC_PIN5_ADC, PIOS_ADC_PIN6_ADC }
|
||||
#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER, PIOS_ADC_PIN2_ADC_NUMBER, PIOS_ADC_PIN3_ADC_NUMBER, PIOS_ADC_PIN4_ADC_NUMBER, PIOS_ADC_PIN5_ADC_NUMBER, PIOS_ADC_PIN6_ADC_NUMBER }
|
||||
#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR)
|
||||
|
||||
#define PIOS_ADC_NUM_ADC_CHANNELS 2
|
||||
#define PIOS_ADC_USE_ADC2 1
|
||||
#define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE)
|
||||
@ -379,6 +364,26 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
|
||||
#define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH
|
||||
|
||||
//-------------------------
|
||||
// GPIO
|
||||
//-------------------------
|
||||
#define PIOS_GPIO_1_PORT GPIOC
|
||||
#define PIOS_GPIO_1_PIN GPIO_Pin_0
|
||||
#define PIOS_GPIO_1_GPIO_CLK RCC_APB2Periph_GPIOC
|
||||
#define PIOS_GPIO_2_PORT GPIOC
|
||||
#define PIOS_GPIO_2_PIN GPIO_Pin_1
|
||||
#define PIOS_GPIO_2_GPIO_CLK RCC_APB2Periph_GPIOC
|
||||
#define PIOS_GPIO_3_PORT GPIOC
|
||||
#define PIOS_GPIO_3_PIN GPIO_Pin_2
|
||||
#define PIOS_GPIO_3_GPIO_CLK RCC_APB2Periph_GPIOC
|
||||
#define PIOS_GPIO_4_PORT GPIOD
|
||||
#define PIOS_GPIO_4_PIN GPIO_Pin_2
|
||||
#define PIOS_GPIO_4_GPIO_CLK RCC_APB2Periph_GPIOD
|
||||
#define PIOS_GPIO_PORTS { PIOS_GPIO_1_PORT, PIOS_GPIO_2_PORT, PIOS_GPIO_3_PORT, PIOS_GPIO_4_PORT }
|
||||
#define PIOS_GPIO_PINS { PIOS_GPIO_1_PIN, PIOS_GPIO_2_PIN, PIOS_GPIO_3_PIN, PIOS_GPIO_4_PIN }
|
||||
#define PIOS_GPIO_CLKS { PIOS_GPIO_1_GPIO_CLK, PIOS_GPIO_2_GPIO_CLK, PIOS_GPIO_3_GPIO_CLK, PIOS_GPIO_4_GPIO_CLK }
|
||||
#define PIOS_GPIO_NUM 4
|
||||
|
||||
//-------------------------
|
||||
// USB
|
||||
//-------------------------
|
||||
#define PIOS_USB_ENABLED 1
|
||||
|
@ -48,6 +48,7 @@
|
||||
#define PIOS_INCLUDE_SDCARD
|
||||
#define PIOS_INCLUDE_SETTINGS
|
||||
#define PIOS_INCLUDE_FREERTOS
|
||||
#define PIOS_INCLUDE_GPIO
|
||||
|
||||
|
||||
/* Defaults for Logging */
|
||||
|
@ -42,7 +42,7 @@ static const uint32_t ADC_CHANNEL_MAPPING[PIOS_ADC_NUM_PINS] = PIOS_ADC_CHANNEL_
|
||||
|
||||
/* The following two arrays are word aligned, so that DMA can transfer two hwords at once */
|
||||
static uint16_t adc_conversion_values[PIOS_ADC_NUM_CHANNELS] __attribute__((aligned(4)));
|
||||
static uint16_t adc_conversion_values_sum[PIOS_ADC_NUM_CHANNELS] __attribute__((aligned(4)));
|
||||
//static uint16_t adc_conversion_values_sum[PIOS_ADC_NUM_CHANNELS]; __attribute__((aligned(4)));
|
||||
|
||||
static uint16_t adc_pin_values[PIOS_ADC_NUM_CHANNELS];
|
||||
|
||||
@ -56,8 +56,8 @@ void PIOS_ADC_Init(void)
|
||||
|
||||
/* Clear arrays and variables */
|
||||
for(i = 0; i < PIOS_ADC_NUM_CHANNELS; ++i) {
|
||||
adc_conversion_values[i] = 0;
|
||||
adc_conversion_values_sum[i] = 0;
|
||||
adc_conversion_values[i] = 55;
|
||||
//adc_conversion_values_sum[i] = 0;
|
||||
}
|
||||
for(i = 0; i < PIOS_ADC_NUM_CHANNELS; ++i) {
|
||||
adc_pin_values[i] = 0;
|
||||
@ -96,7 +96,7 @@ void PIOS_ADC_Init(void)
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||
ADC_InitStructure.ADC_NbrOfChannel = PIOS_ADC_NUM_ADC_CHANNELS;
|
||||
ADC_InitStructure.ADC_NbrOfChannel = ((PIOS_ADC_NUM_CHANNELS + 1) >> 1);
|
||||
ADC_Init(ADC1, &ADC_InitStructure);
|
||||
|
||||
#if (PIOS_ADC_USE_ADC2)
|
||||
@ -135,7 +135,7 @@ void PIOS_ADC_Init(void)
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;
|
||||
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&adc_conversion_values;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
|
||||
DMA_InitStructure.DMA_BufferSize = PIOS_ADC_NUM_ADC_CHANNELS; /* Number of conversions depends on number of used channels */
|
||||
DMA_InitStructure.DMA_BufferSize = ((PIOS_ADC_NUM_CHANNELS + 1) >> 1); /* Number of conversions depends on number of used channels */
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
|
||||
@ -197,7 +197,6 @@ void DMA1_Channel1_IRQHandler(void)
|
||||
for(i = 0; i < PIOS_ADC_NUM_CHANNELS; ++i) {
|
||||
/* Takeover new value */
|
||||
adc_pin_values[i] = *src_ptr;
|
||||
|
||||
++src_ptr;
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,7 @@
|
||||
#include <pios_usb.h>
|
||||
#include <pios_usb_hid.h>
|
||||
#include <pios_debug.h>
|
||||
#include <pios_gpio.h>
|
||||
|
||||
/* PIOS Hardware Includes (Common) */
|
||||
#include <pios_settings.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user