高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-10-22
|
本帖最后由 contemplator 于 2017-3-30 11:30 编辑
搞了三天了都没有头绪,求大神帮助,使用的是野火V2开发板
在μC/OSIII的例程里加入ADC(操作系统+ADC+串口),串口浮点数输出不正确;
没加入ADC时(操作系统+串口)一切正常,
ADC的库函数工程(ADC+串口)也一切正常
以下是任务函数:
- static void AppTaskLed1 ( void * p_arg )
- {
- OS_ERR err;
- __IO uint16_t i,j,k,middle,x=96,y=10;
- float total1,total2,After_filter[10],ceshi1=1.234678;//′æ·ÅÔËËãoóμÄ16½øÖÆμçÑ1Öμ
- (void)p_arg;
- /*Task body, always written as an infinite loop. */
- while (DEF_TRUE) {
- /*macLED1_TOGGLE ();
- OSTimeDly ( 1000, OS_OPT_TIME_DLY, & err ); */
- ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- OSTimeDlyHMSM(0, 0,0,100,OS_OPT_TIME_HMSM_STRICT,&err);
- ADC_SoftwareStartConvCmd(ADC1, DISABLE);
- //count(96,10,&ADC_Conver[0][0]);
- for(j=0;j<y;j++)
- {
- if(j<y-2)//¼ÆËãÇ°n-2áDμÄÕæóDD§Öμ
- {
- total1=0;//′æ·Å¾ù·½¸ùÖμ
- total2=0;//′æ·Åƽ¾ùÖμ
- for(i=0;i<x;i++)
- { middle=ADC_Conver[i][j];
- total1=total1+middle*middle;
- total2=total2+middle;
- }
- After_filter[j]=sqrt(total1/x-(total2/x)*(total2/x));//¼ÆËãÕæóDD§Öμ
- }
- if(j==y-2)//¼ÆËãμún-1áDμÄƽ¾ùÖμ
- {
- total2=0;//′æ·Åƽ¾ùÖμ
- for(i=0;i<x;i++)
- { middle=ADC_Conver[i][j];
- total2=total2+middle;
- }
- After_filter[j]=total2/x;
- }
- if(j==y-1)//×îoóò»áD£¬Çóƽ¾ùÖμ
- {
- total2=0;//′æ·Åƽ¾ùÖμ
- for(i=0;i<x;i++)
- {
- middle=ADC_Conver[i][j];
- total2=total2+middle;
- }
- After_filter[j]=total2/x;
- }
-
- }
- //½«¼ÆËã½á1û×a»ˉÎaêμ¼êÖμ
- for(k=0;k<y;k++)
- {
- ADC_Value[k]=After_filter[k]/4096*3.3;
- }
- //ADC_ConvertedValueLocal =(float) ADC_ConvertedValue/4096*3.3; // ?????AD?
- for(j=0;j<10;j++)
- { printf("\r\n ADC_ConvertedValue[%d] = %d\r\n",j,ADC_Conver[50][j]);
- printf("\r\n ADC_ConvertedValueLocal[%d] = %f V \r\n",j, ADC_Value[j]);
- printf("\r\n ceishi1,yaoshihaibudui,qnmd = %f V \r\n", ceshi1);
- }
- OSTimeDlyHMSM(0, 0,0,200,OS_OPT_TIME_HMSM_STRICT,&err);
-
- }
-
- }
复制代码
以下是ADC配置:
- /*************DÅoÅ2é¼ˉoˉêy*******************/
- /*
- **oˉêy1|Äü:ADCDÅoÅμÄ2é¼ˉoí′|àí
- **¸÷DÅoÅí¨μà:
- **
- ** 1ü½Å í¨μà DÅoÅ
- ** PA1 ADC123_IN1 Vol_A AÏàμçÑ1
- ** PA2 ADC123_IN2 Vol_B BÏàμçÑ1
- ** PA3 ADC123_IN3 Vol_C CÏàμçÑ1
- ** PB1 ADC123_IN9 áãDòμçÑ1
- ** PC0 ADC123_IN10 Cir_A AÏàμçá÷
- ** PC1 ADC123_IN11 Cir_B BÏàμçá÷
- ** PC2 ADC123_IN12 Cir_C CÏàμçá÷
- ** PC3 ADC123_IN13 áãDòμçá÷
- ** PC4 ADC12 _IN14 Ö±á÷μçá÷Öμ
- ** PC5 ADC12 _IN15
- **
- **
- ***********/
- #include "adc.h"
- #include "Usart.h"
- #include "math.h"
- //o궨òå
- // #define N 95// ÿ¸öí¨μà¾ù·ÖμÄ·Yêy
- // #define M 10 //í¨μàêy
- #define ADC1_DR_Address ((u32)0x40012400+0x4c)
- //2é¼ˉêy¾Y′æ·ÅμÄêy×é
- __IO uint16_t ADC_Conver[96][10];//uint16_t ADC_Conver[96][10];
- //float ADC_Value[10];//¼ÆËãμÄꮽøÖÆμÄμçÑ1Öμ
- /*
- * oˉêyÃû:ADC1_GPIO_Config
- * 1|Äü :ÅäÖÃADC1μÄDMA1′«êä,¿aÆôÏàó|μÄIO¿ú
- * êäèë : ÎT
- * êä3ö : ÎT
- * μ÷óÃ :Äú2¿μ÷óÃ
- */
- static void ADC1_GPIO_Ceshi_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Enable DMA clock */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
- /* Enable ADC1 and GPIOC clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOA| RCC_APB2Periph_GPIOB| RCC_APB2Periph_GPIOC, ENABLE);
- /* Configure PA1/PA2/PA3 as analog input */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //PB1ÅäÖÃÎaÄ£ÄaêäèëÄ£ê½
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- //ÅäÖÃPC0-PC5ÎaÄ£ÄaêäèëÄ£ê½
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- }
- /* oˉêyÃû:ADC1_Mode_Config
- * 1|Äü :¿aÆôADC1μÄDMA′«êä
- * êäèë : ¡¡ÎT
- * êä3ö :ÎT
- * μ÷óÃ :Äú2¿μ÷óÃ
- */
- static void ADC1_Mode_Ceshi_Config(void)
- {
- DMA_InitTypeDef DMA_InitStructure;
- ADC_InitTypeDef ADC_InitStructure;
-
- /* DMA channel1 configuration */
- DMA_DeInit(DMA1_Channel1);
- DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //ADCÔ′μØÖ·
- DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_Conver;//êy¾Y×a»»oóμÄ′æ·ÅμØÖ·
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
- DMA_InitStructure.DMA_BufferSize =960 ;
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//íaéèÔö3¤Ä£ê½1رÕ
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //′æêyÇøÔö3¤Ä£ê½ê1Äü
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //°ë¸ö×Ö½úêy¾Y′«êä
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //¿aÆôDMAÑ-»·Ä£ê½
- DMA_InitStructure.DMA_Priority = DMA_Priority_High;
- DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
- DMA_Init(DMA1_Channel1, &DMA_InitStructure);
-
- /* ADC1 configuration */
- ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ÅäÖÃADCÎa¶àá¢Ä£ê½
- ADC_InitStructure.ADC_ScanConvMode = ENABLE ; //ê1óöà¸öí¨μà2é¼ˉ£¬ê1Äüé¨ÃèÄ£ê½
- ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //Dèòa¶Ô¶à¸öí¨μà½øDDá¬Dø2é¼ˉêy¾Y,¿aÆôADCμÄá¬Dø×a»»Ä£ê½
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //Ôú×a»»êÇê1óÃèí¼t′¥·¢
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //2é¼ˉêy¾Yóò¶ÔÆë
- ADC_InitStructure.ADC_NbrOfChannel = 10; //2éÑùμÄí¨μàêy10
- ADC_Init(ADC1, &ADC_InitStructure);
- /*?ÅäÖÃADCê±Öó,ÎaPCLK2μÄ6·ÖÆμ,¼′12MHz*/
- RCC_ADCCLKConfig(RCC_PCLK2_Div6);
- /*ÅäÖÃADC1¸öí¨μà2éÑùÖüÆúÎa237.5. 5¸öÖüÆú, */
- ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 4, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 5, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 6, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 7, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 8, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 9, ADC_SampleTime_239Cycles5);
- ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 10, ADC_SampleTime_239Cycles5);
- /* Enable ADC1 DMA */
- ADC_DMACmd(ADC1, ENABLE);
- /* Enable ADC1 */
- ADC_Cmd(ADC1, ENABLE);
- /*ÖØÖÃADCμÄD£Ñéλ */
- ADC_ResetCalibration(ADC1);
- /*μè′yADCD£Ñé¿aÆô */
- while(ADC_GetResetCalibrationStatus(ADC1));
- /* ADCD£Ñé */
- ADC_StartCalibration(ADC1);
- /* μè′yADCD£Ñé½áêø*/
- while(ADC_GetCalibrationStatus(ADC1));
- /* Æô¶ˉADCD£Ñé */
- DMA_Cmd(DMA1_Channel1, ENABLE);
- // ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- }
- /*
- * oˉêyÃû:ADC1_Init
- * êäèë :ÎT
- * êä3ö :ÎT
- * ·μ»Ø :ÎT
- * μ÷óÃ :ía2¿μ÷óÃ
- */
- void ADC1_Ceshi_Init(void)
- {
- ADC1_GPIO_Ceshi_Config();
- ADC1_Mode_Ceshi_Config();
- }
复制代码
|
|