Lanqiao Cup Embedded-ADC
(1) Personal habits
A separate ADC.c and ADC.h will be created and placed under the HARAWARE folder
(2) Preparation
-
1. Basic features
- 1. It is a 12-bit ADC.
2. There are 3 controllers.
3. There are 16 external channels.
4. Interrupts can be generated.
5. Scan mode.
6. Sampling time can be programmed per channel.
7. Data memory (left-aligned) (right-aligned).
8. Conversion time (maximum 1us)
9. Mainly use independent mode
- 1. It is a 12-bit ADC.
-
Two, single and continuous and scan conversion
- Single: ADC is executed only once (the next conversion needs to be turned on manually)
multiple times: ADC will automatically start the next conversion
Scan: ADC scans all selected channels
(after one channel is converted, the EOC (conversion end) mark is Settings)
- Single: ADC is executed only once (the next conversion needs to be turned on manually)
-
Three, regular channel and injection channel
- 1. Up to 4 injection channels
2. Up to 16 regular channels
- 1. Up to 4 injection channels
-
4. ADC clock configuration: do not let the ADC clock exceed 14MHz, otherwise it may not be allowed
-
5. Conversion time = sampling time + 12.5,
so the minimum conversion time is 1us (ADC clock = 14MHz, sampling time is 1.5 cycles)
(3) Hardware connection
The other end of the variable resistor is connected to the PB0 pin. At the same time, we check the data sheet of stm32f103rbt6,It is found that the PB0 pin can be multiplexed into ADC_IN8.
We can set PB0 as ADC input pin through software, then the voltage data on PB0 pin can be collected.
(4) Write void ADC_init(void) initial function
(5) Write u16 Get_Adc(u8 channel) read function
(6) Write u16 Get_Adc(u8 channel) processing function
(7) Problem
Question one
The ADC clock exceeds 14MHz, otherwise it may be inaccurate.
The divide by 6 is exactly 12MHz = 72MHz / 6, which does not exceed 12MHz
Question two
The first entry parameter is the ADC of the selected configuration. The
second entry parameter is the channel to be configured. The
third entry parameter is to configure the ADC number (for example, if ADC1 is used, write 1). The
fourth entry parameter represents a single sampling. The number of clock cycles (the larger the number of cycles, the more accurate the sampled signal)
(8) Sampling time, sampling period, and sampling frequency calculation method
Sampling time, sampling period, sampling frequency calculation method