diff --git a/flight/Modules/Battery/battery.c b/flight/Modules/Battery/battery.c index 78fa8f807..536323d28 100644 --- a/flight/Modules/Battery/battery.c +++ b/flight/Modules/Battery/battery.c @@ -55,15 +55,6 @@ // #define SAMPLE_PERIOD_MS 500 -//#define ENABLE_DEBUG_MSG - -#ifdef ENABLE_DEBUG_MSG -#define DEBUG_PORT PIOS_COM_GPS -#define DEBUG_MSG(format, ...) PIOS_COM_SendFormattedString(DEBUG_PORT, format, ## __VA_ARGS__) -#else -#define DEBUG_MSG(format, ...) -#endif - // Private types // Private variables @@ -101,8 +92,8 @@ static void onTimer(UAVObjEvent* ev) FlightBatterySettingsGet(&batterySettings); //calculate the battery parameters - flightBatteryData.Voltage = ((float)PIOS_ADC_PinGet(1)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_VOLTAGEFACTOR]; //in Volts - flightBatteryData.Current = ((float)PIOS_ADC_PinGet(0)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_CURRENTFACTOR]; //in Amps + flightBatteryData.Voltage = ((float)PIOS_ADC_PinGet(0)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_VOLTAGEFACTOR]; //in Volts + flightBatteryData.Current = ((float)PIOS_ADC_PinGet(1)) * batterySettings.SensorCalibrations[FLIGHTBATTERYSETTINGS_SENSORCALIBRATIONS_CURRENTFACTOR]; //in Amps flightBatteryData.ConsumedEnergy += (flightBatteryData.Current * 1000.0 * dT / 3600.0) ;//in mAh diff --git a/flight/PiOS/Boards/STM32F4xx_Revolution.h b/flight/PiOS/Boards/STM32F4xx_Revolution.h index 2b7763266..31aa9c380 100644 --- a/flight/PiOS/Boards/STM32F4xx_Revolution.h +++ b/flight/PiOS/Boards/STM32F4xx_Revolution.h @@ -247,7 +247,7 @@ extern uint32_t pios_com_vcp_id; /* which is annoying because this then determines the rate at which we generate buffer turnover events */ /* the objective here is to get enough buffer space to support 100Hz averaging rate */ #define PIOS_ADC_NUM_CHANNELS 4 -#define PIOS_ADC_MAX_OVERSAMPLING 10 +#define PIOS_ADC_MAX_OVERSAMPLING 2 #define PIOS_ADC_USE_ADC2 0 //------------------------- diff --git a/flight/PiOS/STM32F4xx/pios_adc.c b/flight/PiOS/STM32F4xx/pios_adc.c index 129fbe35a..ad2eb06e6 100644 --- a/flight/PiOS/STM32F4xx/pios_adc.c +++ b/flight/PiOS/STM32F4xx/pios_adc.c @@ -76,9 +76,9 @@ struct pios_adc_dev { volatile uint8_t adc_oversample; uint8_t dma_block_size; uint16_t dma_half_buffer_size; - int16_t fir_coeffs[PIOS_ADC_MAX_SAMPLES+1] __attribute__ ((aligned(4))); - volatile int16_t raw_data_buffer[PIOS_ADC_MAX_SAMPLES] __attribute__ ((aligned(4))); - float downsampled_buffer[PIOS_ADC_NUM_CHANNELS] __attribute__ ((aligned(4))); +// int16_t fir_coeffs[PIOS_ADC_MAX_SAMPLES+1] __attribute__ ((aligned(4))); +// volatile int16_t raw_data_buffer[PIOS_ADC_MAX_SAMPLES] __attribute__ ((aligned(4))); +// float downsampled_buffer[PIOS_ADC_NUM_CHANNELS] __attribute__ ((aligned(4))); enum pios_adc_dev_magic magic; }; @@ -108,7 +108,7 @@ struct adc_accumulator { }; #if defined(PIOS_INCLUDE_ADC) -static struct dma_config config[] = PIOS_DMA_PIN_CONFIG; +static const struct dma_config config[] = PIOS_DMA_PIN_CONFIG; #define PIOS_ADC_NUM_PINS (sizeof(config) / sizeof(config[0])) static struct adc_accumulator accumulator[PIOS_ADC_NUM_PINS]; @@ -117,8 +117,6 @@ static struct adc_accumulator accumulator[PIOS_ADC_NUM_PINS]; static uint16_t adc_raw_buffer[2][PIOS_ADC_MAX_SAMPLES][PIOS_ADC_NUM_PINS]; #endif -#define PIOS_ADC_TIMER TIM3 /* might want this to come from the config */ - #if defined(PIOS_INCLUDE_ADC) static void init_pins(void) @@ -176,6 +174,7 @@ init_dma(void) NVIC_Init(&NVICInit); } +#if 0 static void init_timer(void) { @@ -200,6 +199,7 @@ init_timer(void) TIM_SelectOutputTrigger(PIOS_ADC_TIMER, TIM_TRGOSource_Update); TIM_Cmd(PIOS_ADC_TIMER, ENABLE); } +#endif static void init_adc(void) @@ -432,15 +432,15 @@ void accumulate(uint16_t *buffer, uint32_t count) // XXX should do something with this if (pios_adc_dev->data_queue) { static portBASE_TYPE xHigherPriorityTaskWoken; - xQueueSendFromISR(pios_adc_dev->data_queue, pios_adc_dev->downsampled_buffer, &xHigherPriorityTaskWoken); +// xQueueSendFromISR(pios_adc_dev->data_queue, pios_adc_dev->downsampled_buffer, &xHigherPriorityTaskWoken); portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); } #endif #endif - if(pios_adc_dev->callback_function) - pios_adc_dev->callback_function(pios_adc_dev->downsampled_buffer); +// if(pios_adc_dev->callback_function) +// pios_adc_dev->callback_function(pios_adc_dev->downsampled_buffer); }