0
votes

I am trying to program an adc in stm32f4. I want to know what are the roles of these five instructions?

  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right
1
Have you read the reference manual of the CPU? - The Independent mode refers to conversion mode. - The ADC_Prescaler_Div2 set the Clock of the ADC to be the half of BUS clock - The ADC_DMAA... disables the DMA - The ADC_TwoSampling... Set the sampling cycles duration of the ADC - And the ADC_DataAligh set the alignment of result data in ADC_DR data register - hoo2
Download the RM, read up on the peripheral, try it out either using HAL or bit bashing and see what it does. Also look in the HAL docs and in the code libraries - single step to see what is being done and how. Yes it might appear easier if someone else reads it and explains, but you wil then never learn. Lots of reading ahead... - ChrisR

1 Answers

2
votes

ADC_Mode_Independent The ADC functions independently of others. Other modes allow two ADC to be read at exactly the same time (for power measurement) or interleaved (2 or 3 ADC cooperate to read the same channel more often)

ADC_Prescaler_Div2 - How fast the ADC works its SAR algorithm

ADC_DMAAccessMode_Disabled - DMA provides the ability to take a number of readings and have them automatically put into a table in memory

ADC_TwoSamplingDelay_5Cycles - There are two registers, this one one is a delay between successive readings, the other is the sampling time, the time taken to physically sense the voltage on the pin. You must have a low impedance source to use shorter sampling. explained in the manual. Some processors can read the same pin more than once before stepping to the next pin, hence the delay read the ADC accuracy appnotes.

ADC_DataAlign_Right