9950 views|1 replies

50

Posts

0

Resources
The OP
 

Crazy Shell AI open source drone ADC (joystick control) [Copy link]

  • Joystick

1.1 Joystick Introduction

The joystick is ergonomic and easy to operate, so it is widely used in various toys, such as remote control airplanes, remote control cars, etc. The following figure shows a real picture of the joystick module.

1.2 Joystick Principle

The joystick is essentially two potentiometers, also known as sliding resistors. One potentiometer corresponds to the up and down directions of the joystick, while the other potentiometer corresponds to the left and right directions.

One end of the joystick pin is connected to power and the other end is connected to ground, and the other end is responsible for collecting the voltage change value to determine the direction in which the joystick is moved.

ADC

2.1 ADC Introduction

ADC (Analog-to-Digital Converter), analog-to-digital converter, A/D converter, or ADC for short, usually refers to an electronic component that converts analog signals into digital signals. A common analog-to-digital converter converts an input voltage signal into an output digital signal. Since the digital signal itself has no practical meaning, it only represents a relative size. Therefore, any analog-to-digital converter requires a reference analog quantity as a conversion standard. The more common reference standard is the maximum convertible signal size. The output digital quantity represents the size of the input signal relative to the reference signal.

So what are analog and digital quantities? Analog quantities refer to quantities whose variables change continuously within a certain range;

Digital quantity is a kind of physical quantity. Their changes are discontinuous in time and always occur in a series of discrete moments. This kind of physical quantity is called digital quantity. The following figure shows a comparison between digital quantity and analog quantity.

Then the process of converting analog signals into digital signals is called ADC analog-to-digital conversion.

There are many types of analog-to-digital converters, which can be divided into indirect ADC and direct ADC according to different working principles. Indirect ADC first converts the input analog voltage into time or frequency, and then converts these intermediate quantities into digital quantities. Commonly used ones are dual-integral ADCs. Direct ADC directly converts into digital quantities. Commonly used ones are parallel comparator ADCs and successive approximation ADCs.

Parallel comparison ADC: Each level is compared in parallel at the same time, and each output code is also generated in parallel at the same time, so the conversion speed is fast. The disadvantages of parallel comparison ADC are high cost and high power consumption.

Successive approximation ADC: It generates a series of comparison voltages VR, but it generates comparison voltages one by one, compares them with the input voltages one by one, and performs analog-to-digital conversion in a gradual approximation manner. It is slower than the parallel comparison ADC and much faster than the dual integration ADC, and is a medium-speed ADC device.

Dual-integral ADC: It first integrates the input sampling voltage and the reference voltage twice to obtain a time interval proportional to the average value of the sampling voltage, and uses a counter to count the standard clock pulses. Its advantages are strong anti-interference ability and good stability; its main disadvantage is low conversion speed.

Common technical indicators of ADC are:

(1) Sampling accuracy: that is, resolution, generally 8 bits, 10 bits, 12 bits, 16 bits, etc.;

(2) Conversion time: the time required for each sampling, which represents the conversion speed of the ADC and is related to the ADC clock frequency, sampling period, and conversion period;

(3) Operating voltage: You need to pay attention to the operating voltage range of the ADC and whether it can directly measure negative voltages.

(4) ADC type: As mentioned above, there are many types of ADCs, and different types of ADCs have different performance limits.

2.2 STM32 ADC

STM 32 has 1~3 ADCs, which can be used independently or in dual mode (increasing the sampling rate). The ADC of STM 32 is a 12-bit successive approximation analog-to-digital converter. It has 18 channels and can measure 16 external and 2 internal signal sources. The A/D conversion of each channel can be performed in single, continuous, scan or intermittent mode.

The result of the ADC can be stored in the 16-bit data register in a left-aligned or right-aligned manner. (Because the ADC is 12 bits here, there are four bits not used, so there is a left/right alignment method).

The corresponding relationship between the ADC external channels and pins of the STM32F103 series is shown in the figure below.

aisle

ADC1

ADC2

ADC3

Channel 0

PA0

PA0

PA0

Channel 1

PA1

PA1

PA1

Channel 2

PA2

PA2

PA2

Channel 3

PA3

PA3

PA3

Channel 4

PA4

PA4

PF6

Channel 5

PA5

PA5

PF7

Channel 6

PA6

PA6

PF8

Channel 7

PA7

PA7

PF9

Channel 8

PB0

PB0

PF10

Channel 9

PB1

PB1

none

Channel 10

PC0

PC0

PC0

Channel 11

PC1

PC1

PC1

Channel 12

PC2

PC2

PC2

Channel 13

PC3

PC3

PC3

Channel 14

PC4

PC4

none

Channel 15

PC5

PC5

none

Channel 16

Temperature Sensor

none

none

Channel 17

Internal reference voltage

none

none

2.3 ADC Registers

There are many ADC-related registers in STM32, and only a few important registers are discussed here.

(1) ADC_CR1: Analog-to-digital conversion control register 1, as shown in the following figure:

RES[1:0] is the resolution setting bit. When RES[1:0] is equal to 00, the ADC is set to 12 bits. When RES[1:0] is equal to 01, the ADC is set to 10 bits. When RES[1:0] is equal to 10, the ADC is set to 8 bits. When RES[1:0] is equal to 11, the ADC is set to 6 bits.

(2) ADC_CR2: Analog-to-digital conversion control register 2, as shown in the following figure:

ALIGN is the data alignment bit, which is 0 for right-aligned data and 1 for left-aligned data; CONT is the continuous conversion setting bit, which is 0 for single conversion and 1 for continuous conversion; ADON is the ADC conversion enable bit, which turns off ADC conversion and turns on ADC conversion when it is 1.

(3) ADC_DR: Analog-to-digital conversion data register. The AD conversion results in the regular sequence register will be stored in this register, and the conversion results of the injection register will be stored in ADC_DR, as shown in the following figure:

The converted data is stored in DATA[15:0].

2.4 ADC joystick control experiment

The content of this experiment is to use the left joystick on the remote controller to control the power indicator light, cocobit programming mode indicator light, drone connection indicator light and emergency landing indicator light on the remote controller.

The left joystick turns on the power indicator, turns on the cocobit programming indicator, turns on the left to light the emergency landing indicator, and turns on the right to light the drone connection indicator. Here, the ADC1 multi-channel regular DMA acquisition method is used. The ADC wiring schematic diagram of the left joystick is shown in the figure below.

LED will be used in the experiment. For its configuration, please refer to the "GPIO" section of the remote control development basic tutorial. The overall idea of writing code is shown in the following table:

Code ideas

1

Pin Configuration

  1. Define the structure;
  2. Enable clock (ADC+GPIO clock);
  3. Fill the structure;
  4. Load the structure.

2

DMA Configuration for ADC

  1. Define the structure;
  2. Fill the structure;
  3. Loading structure;

4. Enable DMA.

3

ADC initialization configuration

  1. Define the structure;
  2. Reset ADC;
  3. Enable internal voltage;
  4. Fill the structure;
  5. Loading structure;
  6. Configure ADC clock;
  7. Set ADC rule conversion channel;
  8. Enable DMA transfer of ADC;
  9. Calibrate ADC;
  10. Enable software triggering of ADC.

4

Logical Processing

1. Get ADC value and process ADC value.

The initialization code of ADC is as follows.

ADC processing is done in the main loop, the code of which is shown in the figure below.

As shown in the figure below, when the left joystick is moved to the left, the emergency landing indicator light comes on.

3.遥控器开发基础-【3】ADC(摇杆控制).pdf

984.94 KB, downloads: 4

This post is from Creative Market

Latest reply

Crazy shell AI open source drone Thanks to the host for sharing the entire xi series systematically. Thank you   Details Published on 2021-9-12 13:13
 
 

46

Posts

0

Resources
2
 

Crazy shell AI open source drone Thanks to the host for sharing the entire xi series systematically. Thank you

This post is from Creative Market
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list