找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 2669|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

STM32F373的ADC采樣問題,必須采樣轉(zhuǎn)換2次才有數(shù)據(jù),什么原因?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:588726 發(fā)表于 2019-7-23 15:42 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
本帖最后由 abnsl 于 2019-7-23 15:45 編輯

STM32F373的ADC采樣問題,必須采樣轉(zhuǎn)換2次才有數(shù)據(jù),什么原因?

void AI_ADCInit(void)
{

GPIO_InitTypeDef GPIO_InitStruct;
ADC_InitTypeDef ADC_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//72M/6=12, ADC²ÉÑù×î¸ßƵÂÊ14MHz      
   
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AN;
//GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
//GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
//GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//=======================================

ADC_DeInit(ADC1);   
ADC_StructInit(&ADC_InitStruct);

/* initialize the ADC_ScanConvMode member */
  ADC_InitStruct.ADC_ScanConvMode = DISABLE;
  /* Initialize the ADC_ContinuousConvMode member */
  ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
  /* Initialize the ADC_ExternalTrigConv member */
  ADC_InitStruct.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T19_TRGO;
  /* Initialize the ADC_DataAlign member */
  ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
  /* Initialize the ADC_NbrOfChannel member */
  ADC_InitStruct.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1,&ADC_InitStruct);   


void AI_excute(void)
{
    uint16_t i=0,j=0,num=0;

    if((num=Order[1]&0x02))
    {
        printf("AI2 in !\r\n");
        ADC_RegularChannelConfig(ADC1,ADC_Channel_3,1,ADC_SampleTime_239Cycles5);
   
    ADC_Cmd(ADC1,ENABLE);
   
    ADC_ResetCalibration(ADC1);
  while(ADC_GetResetCalibrationStatus(ADC1));
  ADC_StartCalibration(ADC1);
  while(ADC_GetCalibrationStatus(ADC1));
        
    ADC_Cmd(ADC1,ENABLE);//使能第二次
   
    ADC_ClearFlag(ADC1,ADC_FLAG_STRT);
    ADC_SoftwareStartConv(ADC1);
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_STRT));
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
    Aivalue=ADC_GetConversionValue(ADC1);
    delay_nms(200);
   
    Aivalue=(Aivalue/4096)*3.3;
    ADC_ClearFlag(ADC1,ADC_FLAG_EOC);//ADC_FLAG_EOC/ADC_FLAG_STR

    printf("AI2 value is %f !\r\n",Aivalue);//--------------到這里輸出還是0 ,這一次采樣值為0


ADC_ClearFlag(ADC1,ADC_FLAG_STRT);
    ADC_SoftwareStartConv(ADC1);
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_STRT));
    while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
    Aivalue=ADC_GetConversionValue(ADC1);
    delay_nms(200);
   
    Aivalue=(Aivalue/4096)*3.3;//-------------------到這里采樣就正常了,考慮過是否是采樣時間延時不夠,但好像不是這個問題。




}
   


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

地板
ID:588726 發(fā)表于 2019-11-25 21:48 | 只看該作者
還沒有解決
回復(fù)

使用道具 舉報

板凳
ID:588726 發(fā)表于 2019-8-9 16:12 | 只看該作者
沒有人回答?
回復(fù)

使用道具 舉報

沙發(fā)
ID:588726 發(fā)表于 2019-7-23 15:44 | 只看該作者
void AI_ADCInit(void)
{

GPIO_InitTypeDef GPIO_InitStruct;
ADC_InitTypeDef ADC_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//72M/6=12, ADC²ÉÑù×î¸ßƵÂÊ14MHz         
       
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AN;
//GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
//GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
//GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//=======================================

ADC_DeInit(ADC1);       
ADC_StructInit(&ADC_InitStruct);

/* initialize the ADC_ScanConvMode member */
  ADC_InitStruct.ADC_ScanConvMode = DISABLE;
  /* Initialize the ADC_ContinuousConvMode member */
  ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
  /* Initialize the ADC_ExternalTrigConv member */
  ADC_InitStruct.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T19_TRGO;
  /* Initialize the ADC_DataAlign member */
  ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
  /* Initialize the ADC_NbrOfChannel member */
  ADC_InitStruct.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1,&ADC_InitStruct);       

這是初始化內(nèi)容
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表