STM32 multi-channel ADC rule conversion is realized

Publisher:科技创客Latest update time:2016-06-30 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
vu16 ADC_RCVTab[160] ; // add it yourself

 

/*******************************************************************************
* 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 ----------------------------------------------*/

 

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //Enable DMA clock


  DMA_DeInit(DMA1_Channel1);
  DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//Peripheral address
  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_RCVTab;//Memory address
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//dma transmission direction unidirectional
  DMA_InitStructure.DMA_BufferSize = 160;//Set the length of the DMA buffer during transmission word
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//Set the peripheral increment mode of DMA, one peripheral
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//Set the memory increment mode of DMA,
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//Peripheral data word
  lengthDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//Memory data word
  lengthDMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//Set DMA transfer mode: continuous circular modeDMA_InitStructure.DMA_Priority
  = DMA_Priority_High;//Set DMA priority levelDMA_InitStructure.DMA_M2M
  = DMA_M2M_Disable;//Set variables in 2 DMA memories to access each otherDMA_Init
  (DMA1_Channel1, &DMA_InitStructure);
  
  /* Enable DMA1 channel1 */
  DMA_Cmd(DMA1_Channel1, ENABLE);

  /* ADC1 configuration ------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//Independent working modeADC_InitStructure.ADC_ScanConvMode
  = ENABLE;//Scan modeADC_InitStructure.ADC_ContinuousConvMode = ENABLE
  ;//Continuous conversionADC_InitStructure.ADC_ExternalTrigConv
  = ADC_ExternalTrigConv_None;//External trigger disabledADC_InitStructure.ADC_DataAlign
  = ADC_DataAlign_Right;//Data right
  alignmentADC_InitStructure.ADC_NbrOfChannel = 8;//Number of channels used for conversionADC_Init
  (ADC1, &ADC_InitStructure);

  /* ADC1 regular channels configuration [规则模式通道配置]*/ 
  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(RESET==DMA_GetFlagStatus(DMA1_FLAG_TC1));   //自己添加
  
    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();
  }
}

 

u16 average(vu16 ADCDataTab[], u16 nChannel) //Add by yourself

   u16 averagevalue=0, maxvalue=0, minvalue=0xFFFF, i;

   for (i=0;i<20;i++) 
   { 
     averagevalue += *(ADCDataTab+nChannel+i*8);

  if(*(ADCDataTab+nChannel+i*8)>maxvalue)   
  maxvalue=*(ADCDataTab+nChannel+i*8);
    
  if(*(ADCDataTab+nChannel+i*8)   minvalue=*(ADCDataTab+nChannel+i*8);
 }

 return ((averagevalue-maxvalue-minvalue)/18); //This will take time and is not advisable. It is best to use >>
 
}

Keywords:STM32 Reference address:STM32 multi-channel ADC rule conversion is realized

Previous article:STM32 Development Board Basic Tutorial (Ten) - An Introduction to RTC
Next article:How to debug stm32 in ram under ulink

Recommended ReadingLatest update time:2024-11-16 17:47

STM32 Keil simulation cannot enter the Main() function
The STM32 simulation cannot enter the Main() function. The operation will always be stuck in the startup function or the clock configuration function. The reason is that Keil simulation only supports 5 breakpoints at most. If there are more than or equal to 5 power-off points, this problem will occur! ! ! ! ! ! !
[Microcontroller]
Using printf function in STM32+Keil
Keil does not support the Host-semi mechanism, that is, it does not support printing strings directly in the IDE. Then you can only send data to the hardware serial port through the program. In this way, you can use a custom function when calling, which is also very convenient. For example: void send_char_to_usart(u
[Microcontroller]
A management method when STM32 uses Flash to store data
When using stm32f3xx, it is necessary to store some calibration information that will not be lost when the power is off. According to the manual: 1. The length of stm32 flash write is fixed at 16 bits; 2. When erasing, the entire block (2Kbytes) must be erased. Give the address in a flash block and execute the erase co
[Microcontroller]
STM32 study notes - external interrupt EXTI
Study Notes for      STM32F103C8 redesigned  by  zhang  bin 2012-10-30 versions:V-0.1 All  Rights  Reserved   main.c is as follows, with detailed comments. You can basically use it after understanding the following examples and instructions:           //A high preemption level will interrupt
[Microcontroller]
Personal suggestions for getting started with stm32 from the library function direction
Necessary tools: stm32 development board, a book on library functions; (1) After selecting a development board, pay attention to the STM32 model corresponding to the board. Generally, F103ZET6 is selected. There is a lot of information online. Check the size of the flash it corresponds to. You will use it to set the
[Microcontroller]
STM32 boot process complete solution
This article mainly explains the comprehensive analysis of the STM32 startup process, including the introduction of the startup process, the display of the startup code, and in-depth analysis.   Compared with the mainstream ARM7/ARM9 core architecture of the previous generation of ARM, the startup method of the new ge
[Analog Electronics]
STM32 boot process complete solution
Detailed explanation of IIC application of STM32 2
IIC Brief Introduction The editor’s ability is limited, so I hope you guys can point out any mistakes I made!       IIC communication usually refers to the IIC simulated by two I/O ports of the microcontroller. The real IIC is actually a hardware circuit, which is the patent of Philips. If you want to use it, you
[Microcontroller]
Design and implementation of digitally controlled sinusoidal wave inverter power supply based on STM32 series microcontroller
    Inverter power supplies are widely used, especially precision instruments have higher performance requirements for inverter power supplies. High-performance inverter power supplies not only require stable operation, high inverter efficiency, good output waveform characteristics, and complete protection functions, b
[Microcontroller]
Design and implementation of digitally controlled sinusoidal wave inverter power supply based on STM32 series microcontroller
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号