问答

汇集网友智慧,解决技术难题

发顺丰顺丰

TA的家园币:26  

  • N32G031 ADC采样50Hz正弦波有效值波动严重、

    现象:芯片计算出来的有效值波动较大,最大最小值偏差59%。抓了ADC输入信号是稳定的。均方根算法验证过是正确的,带入固定数据算得也是对的。采样方式:软件触发,0.625ms使能1次,共采集16次,在定时器中使能ADC_EnableSoftwareStartConv(ADC,ENABLE);AD读取方式:AD中断里读取ADC_GetDat(ADC);初始化:voidADC_Initial(void){ErrorStatusHSIStartUpStatus;ADC_InitTypeADC_InitStructure;NVIC_InitTypeNVIC_InitStructure;/*ConfigureandenableADCinterrupt*/NVIC_InitStructure.NVIC_IRQChannel=ADC_IRQn;NVIC_InitStructure.NVIC_IRQChannelPriority=1;NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;NVIC_Init(&NVIC_InitStructure);/*EnableADCclocks*/RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC,ENABLE);/*enableADC1Mclock*/RCC_EnableHsi(ENABLE);/*Waittil1HSIisready*/HSIStartUpStatus=RCC_WaitHsiStable();if(HSIStartUpStatus==SUCCESS){}else{/*IfHSIfailstostart-up,theapplicationwillhavewrongclockconfiguration.Usercanaddheresomecodetodealwiththiserror*//*Gotoinfinitel1oop*/while(1){}}RCC_ConfigAdc1mClk(RCC_ADC1MCLK_SRC_HSI,RCC_ADC1MCLK_DIV8);/*RCC_ADCHCLK_DIV16*/ADC_ConfigClk(ADC_CTRL3_CKMOD_AHB,RCC_ADCHCLK_DIV16);/*ADCconfiguration------------------------------------------------------*/ADC_InitStructure.MultiChEn=ENABLE;ADC_InitStructure.ContinueConvEn=DISABLE;ADC_InitStructure.ExtTrigSelect=ADC_EXT_TRIGCONV_NONE;ADC_InitStructure.DatAlign=ADC_DAT_ALIGN_R;ADC_InitStructure.ChsNumber=1;ADC_Init(ADC,&ADC_InitStructure);/*ADCregularchannelsconfiguration*/ADC_ConfigRegularChannel(ADC,ADC_CH_4_PA4,1,ADC_SAMP_TIME_29CYCLES5);//ADC_ConfigRegularChannel(ADC,ADC_CH_5_PA5,2,ADC_SAMP_TIME_29CYCLES5);/*Regulardiscontinuousmodechannelnumber

    ADC 国民技术 N32G031

    2022-10-31 0