修改轮询
This commit is contained in:
@ -62,24 +62,16 @@ void adc_11_int(void)
|
||||
HAL_ADC_Start(&g_adc_handle); /* <20><><EFBFBD><EFBFBD>ADC */
|
||||
HAL_ADC_PollForConversion(&g_adc_handle, 10);
|
||||
|
||||
// if (HAL_ADC_PollForConversion(&g_adc_handle, 10) == HAL_OK)
|
||||
// {
|
||||
//
|
||||
// return HAL_ADC_GetValue(&g_adc_handle); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ADC1<43><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
// }
|
||||
// else{
|
||||
// return 0xFFFF;
|
||||
// }
|
||||
}
|
||||
uint32_t adc_get_result(uint32_t ch)
|
||||
{
|
||||
|
||||
if (HAL_ADC_PollForConversion(&g_adc_handle, 5) == HAL_OK) {
|
||||
if (HAL_ADC_PollForConversion(&g_adc_handle, 10) == HAL_OK) {
|
||||
|
||||
return HAL_ADC_GetValue(&g_adc_handle); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ADC1<43><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
}else{
|
||||
return 0xffffffff;
|
||||
|
||||
}
|
||||
else{
|
||||
return 0xffff;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -94,16 +94,15 @@ extern ADC_HandleTypeDef g_adc_handle; /* ADC
|
||||
uint16_t adc_value;
|
||||
int enc1,enc0=6000;
|
||||
int enc2;
|
||||
uint8_t buf[2900];
|
||||
uint8_t buf[2500];
|
||||
|
||||
int adc_array_size= 1520;
|
||||
int average_value[100][400];
|
||||
int enc3[100][400];
|
||||
int average_value[100][300];
|
||||
int enc3[100][300];
|
||||
//uint16_t adc_array[1520];
|
||||
//uint16_t ev_co[1520];
|
||||
int measure_f=0;
|
||||
//int track_array[400];
|
||||
uint16_t value[400];//ջ<><D5BB><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>
|
||||
int track_array[300];
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -168,66 +167,18 @@ int main(void)
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
long averagelast=0;
|
||||
long averagenow=0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
measure_f=0;
|
||||
|
||||
enc1 = __HAL_TIM_GET_COUNTER(&htim2);//<2F><>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ֵ
|
||||
enc2 = enc1;
|
||||
|
||||
while(abs(enc2-enc1)==0)
|
||||
{
|
||||
value[measure_f]=adc_get_result(ADC_CHANNEL_11);
|
||||
enc3[0][measure_f] = __HAL_TIM_GET_COUNTER(&htim2);//<2F><>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ֵ
|
||||
enc2=enc3[0][measure_f];
|
||||
measure_f++;
|
||||
if(measure_f>=300)
|
||||
{
|
||||
measure_f=300;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
averagenow=calculateMean(value,measure_f);
|
||||
|
||||
if (abs(averagenow-averagelast)>=150)
|
||||
{
|
||||
averagelast = averagenow; //<2F><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>ֵ
|
||||
int k=measure_f;
|
||||
for(int i=0;i<8*measure_f;i+=8)//Ҫ*8<>ٳ<EFBFBD>8
|
||||
{
|
||||
|
||||
int j=i;
|
||||
buf[j] = (uint8_t)(value[(i+1)/8] & 0xFF);
|
||||
buf[j+1] = (uint8_t)((value[(i+1)/8] >> 8) & 0xFF);
|
||||
buf[j+2] = (uint8_t)(enc3[0][(i+1)/8] & 0xFF);
|
||||
buf[j+3] = (uint8_t)((enc3[0][(i+1)/8] >> 8) & 0xFF);
|
||||
buf[j+4] = (uint8_t)((enc3[0][(i+1)/8] >> 16) & 0xFF);
|
||||
buf[j+5] = (uint8_t)((enc3[0][(i+1)/8] >> 24) & 0xFF);
|
||||
buf[j+6] = 0x0D;
|
||||
buf[j+7] = 0xFF;
|
||||
|
||||
|
||||
}
|
||||
CDC_Transmit_HS(buf, 8*measure_f);
|
||||
//HAL_Delay(2);
|
||||
}
|
||||
//HAL_Delay(2);
|
||||
|
||||
/*
|
||||
|
||||
|
||||
for(int j=0;j<200;j++){
|
||||
for(int j=0;j<100;j++){
|
||||
|
||||
measure_f=0;
|
||||
enc1 = __HAL_TIM_GET_COUNTER(&htim2);//<2F><>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ֵ
|
||||
|
||||
enc2 = enc1;
|
||||
while(abs(enc2-enc1)==0)
|
||||
{
|
||||
@ -236,7 +187,7 @@ int main(void)
|
||||
enc3[j][measure_f] = __HAL_TIM_GET_COUNTER(&htim2);//<2F><>ȡ<EFBFBD><C8A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ֵ
|
||||
enc2=enc3[j][measure_f];
|
||||
measure_f++;
|
||||
if(measure_f>300)
|
||||
if(measure_f>=300)
|
||||
{
|
||||
measure_f=300;
|
||||
}
|
||||
@ -244,7 +195,7 @@ int main(void)
|
||||
}
|
||||
track_array[j]=measure_f;
|
||||
}
|
||||
for(int k=0;k<200;k++){
|
||||
for(int k=0;k<100;k++){
|
||||
for(int i=0;i<8*track_array[k];i+=8)
|
||||
{
|
||||
|
||||
@ -252,18 +203,9 @@ int main(void)
|
||||
|
||||
}
|
||||
CDC_Transmit_HS(buf, 8*track_array[k]);
|
||||
HAL_Delay(2);
|
||||
HAL_Delay(1);
|
||||
}
|
||||
*/
|
||||
// HAL_Delay(2);
|
||||
|
||||
// if(enc2-enc0>1000)
|
||||
// {
|
||||
//// HAL_Delay(5000);
|
||||
//// HAL_Delay(5000);
|
||||
//// enc0=6000;
|
||||
//// CDC_Transmit_HS(buf1, 8);
|
||||
// }
|
||||
HAL_Delay(2);
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user