久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

STM32 多路AD采樣 DMA使用方法

 denvice 2012-11-20

比畫了很多天,終于今天下狠心把多通道ADC轉(zhuǎn)換逼出來了,一直就看著ADC多通道的多種用法和DMA的用法眼暈,找了很多例子最多是3通道而且用的不是一個(gè)AD.終于靠自己的力量弄出來了,長(zhǎng)出了一口氣啊.我這里用的ADC的通道8~15共8個(gè)通道,采用自動(dòng)連續(xù)轉(zhuǎn)換模式,轉(zhuǎn)換完一個(gè)通道的數(shù)據(jù)由DMA送到內(nèi)存中,主程序中把每個(gè)通道的數(shù)據(jù)分檢出來經(jīng)過"去極值取平均值濾波"后送給LCD顯示,在萬利的開發(fā)板上顯示的值比萬利的例子穩(wěn)定多了.

/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
  debug();
#endif

  /* System clocks configuration ---------------------------------------------*/
  RCC_Configuration();

  /* NVIC configuration ------------------------------------------------------*/
  NVIC_Configuration();

  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();

  LcdShow_Init();

  /* DMA1 channel1 configuration ----------------------------------------------*/
  DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//外設(shè)地址
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_RCVTab;//內(nèi)存地址
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//dma傳輸方向單向
  DMA_InitStructure.DMA_BufferSize = 160;//設(shè)置DMA在傳輸時(shí)緩沖區(qū)的長(zhǎng)度 word
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//設(shè)置DMA的外設(shè)遞增模式,,一個(gè)外設(shè)
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//設(shè)置DMA的內(nèi)存遞增模式,
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//外設(shè)數(shù)據(jù)字長(zhǎng)
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//內(nèi)存數(shù)據(jù)字長(zhǎng)
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//設(shè)置DMA的傳輸模式:連續(xù)不斷的循環(huán)模式
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;//設(shè)置DMA的優(yōu)先級(jí)別
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//設(shè)置DMA的2個(gè)memory中的變量互相訪問
  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
 
  /* Enable DMA1 channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);

  /* ADC1 configuration ------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//獨(dú)立工作模式
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;//掃描方式
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//連續(xù)轉(zhuǎn)換
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//外部觸發(fā)禁止
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//數(shù)據(jù)右對(duì)齊
  ADC_InitStructure.ADC_NbrOfChannel = 8;//用于轉(zhuǎn)換的通道數(shù)
  ADC_Init(ADC1, &ADC_InitStructure);

  /* ADC1 regular channels configuration [規(guī)則模式通道配置]*/
  ADC_RegularChannelConfig(ADC1, ADC_Channel_8 , 1, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_9 , 2, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 3, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 4, ADC_SampleTime_239Cycles5); 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 5, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 6, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 7, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 8, ADC_SampleTime_239Cycles5); 

  /* Enable ADC1 DMA [使能ADC1 DMA]*/
  ADC_DMACmd(ADC1, ENABLE);
 
  /* Enable ADC1 [使能ADC1]*/
  ADC_Cmd(ADC1, ENABLE); 

  /* Enable ADC1 reset calibaration register */  
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
 
  /* Start ADC1 Software Conversion */
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
 
    while(1)
  {
    vu16 value1 = 0;
    vu16 value2 = 0;
    vu16 value3 = 0;
    vu16 value4 = 0;
    vu16 value5 = 0;
    vu16 value6 = 0;
    vu16 value7 = 0;
    vu16 value8 = 0;
 value1 = average(ADC_RCVTab,0);
 value2 = average(ADC_RCVTab,1);
 value3 = average(ADC_RCVTab,2);
 value4 = average(ADC_RCVTab,3);
 value5 = average(ADC_RCVTab,4);
 value6 = average(ADC_RCVTab,5);
 value7 = average(ADC_RCVTab,6);
 value8 = average(ADC_RCVTab,7);
 
    u8 num1 = value3 % 10;
    u8 num2 = (value3 / 10) % 10;
    u8 num3= (value3 / 100) % 10;
    u8 num4 = value3 / 1000;
    if (num1 > 9)
      display[3] = num1 + (65 - 10);
    else
      display[3] = num1 + (48-0);

    if (num2 > 9)
      display[2] = num2 +(65 - 10);
    else
      display[2] = num2 + (48 - 0);

    if (num3>9)
      display[1]=num3+(65-10);
    else
      display[1]=num3+(48-0);

    if (num4>9)
      display[0]=num4+(65-10);
    else
      display[0]=num4+(48-0);

    write_string(display);
    delay();
  }
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多