调整ADC1 DMA启动代码( 避免ADC1启动偶现异常问题 )
authorkyz <kyz@kyz.pub>
Fri, 15 Mar 2024 06:07:07 +0000 (14:07 +0800)
committerkyz <kyz@kyz.pub>
Fri, 15 Mar 2024 06:07:07 +0000 (14:07 +0800)
MDK-ARM/welding_controller_v2.uvprojx
user/user_adc.c

index 8888bef05b52e01889a0e5cc631daf9d9273c6e8..a5bc8a2cc83108a65cb3b8ebfc6372f9c57a1f59 100644 (file)
           </ArmAdsMisc>
           <Cads>
             <interw>1</interw>
-            <Optim>3</Optim>
+            <Optim>1</Optim>
             <oTime>0</oTime>
             <SplitLS>0</SplitLS>
             <OneElfS>1</OneElfS>
index 447dc790875cc5bda9c5b321540e8f2a6493a137..fabece87d1c7aaf8620ee1961e622d9a0d3fbbcb 100644 (file)
@@ -6,9 +6,9 @@ void user_adc_task( void* unused );
 //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] ) ) 
@@ -178,19 +178,17 @@ void user_adc_task( void* unused )
     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){
@@ -207,7 +205,10 @@ void user_adc_task( void* unused )
              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;