//ADC3 INP2温度 10毫秒采集一次,100毫秒DMA中断触发,取平均计算。
//ADC2 INP18 电流, 100微秒采集一次,500毫秒触发DMA中断,计算电流。
-__attribute__ ((section("dma_ram"))) ALIGN_32BYTES (static uint16_t adc1_raw[10*2] ); //2路采集10次, 0.1秒
-__attribute__ ((section("dma_ram"))) ALIGN_32BYTES (static uint16_t adc2_raw[5000] ); //采集5000次,电流采样率10Khz 0.5秒
-__attribute__ ((section("dma_ram"))) ALIGN_32BYTES (static uint16_t adc3_raw[100] ); //采集100次 1秒
+ALIGN_32BYTES (static uint16_t adc1_raw[10*2] ); //2路采集10次, 0.1秒
+ALIGN_32BYTES (static uint16_t adc2_raw[5000] ); //采集5000次,电流采样率10Khz 0.5秒
+ALIGN_32BYTES (static uint16_t adc3_raw[100] ); //采集100次 1秒
#define SECTION_DMA_RAM
#define ARRAY_SIZE( arr ) ( sizeof( arr )/sizeof( arr[0] ) )
HAL_ADCEx_Calibration_Start( &hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED );
HAL_ADCEx_Calibration_Start( &hadc2, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED );
HAL_ADCEx_Calibration_Start( &hadc3, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED );
+
+
osDelay(100);
-
- HAL_TIM_Base_Start_IT( &htim1);
- HAL_TIM_Base_Start_IT( &htim2);
-
- //ADC1 用TIM2 10毫秒触发采集,dma采集10次0.1秒产生中断
- //ADC2 用TIM1 100微秒触发采集,dma采集5000次0.5秒产生中断
- //ADC3 用TIM2 10毫秒触发采集,dma采集10次0.1秒产生中断
+
HAL_ADC_Start_DMA( &hadc1, (uint32_t*)&adc1_raw[0], ARRAY_SIZE( adc1_raw) );
HAL_ADC_Start_DMA( &hadc2, (uint32_t*)&adc2_raw[0], ARRAY_SIZE( adc2_raw) );
HAL_ADC_Start_DMA( &hadc3, (uint32_t*)&adc3_raw[0], ARRAY_SIZE( adc3_raw) );
-
+ HAL_TIM_Base_Start( &htim1);
+ HAL_TIM_Base_Start( &htim2);
+
uint32_t last_tick = xTaskGetTickCount();
while(1){
volatile static uint32_t t0, t1;
t1 = HAL_GetTick() - t0;
t0 = HAL_GetTick();
- HAL_ADC_Start_DMA( &hadc1, (uint32_t*)&adc1_raw[0], ARRAY_SIZE(adc1_raw) );
+
+ if( HAL_ADC_Start_DMA( &hadc1, (uint32_t*)&adc1_raw[0], ARRAY_SIZE(adc1_raw) ) != HAL_OK){
+ DBG_PRINTF( "start DMA fail\r\n" );
+ }
pressure_sum = 0;
flowrate_sum = 0;