Chapter 9
Microcontroller
Ground station/Satellite (Telemetry)
GPS
Servos for
Accelerometer control
UAV surfaces
Gyroscope Microcontroller
Motion Magnetometer
Servo(s) for
Engine(s)
Pitot tube
Figure 9.1. Microcontroller connections (inputs/outputs)
No Devices that provide input to Devices that microcontroller sends commands to
microcontroller M M
1 Receiver Elevator servo
2 GPS Aileron servo
3 Pitot-tube Rudder servo
4 Accelerometer Flap servo
5 Attitude gyroscope Engine
6 Rate gyroscope Landing gear
7 Magnetometer Display
8 Compass Transmitter
9 Camera Payload
10 Sensors Sensors
Table 9.1. Elements which sends/receive signals/commands to/from microcontroller
1
ROM
RAM
Processor
I/O
a. Microcontroller
Memory
Registers
Instruction I/O Peripherals
Decoder
ALU
Data Bus
Microprocessor
b. Microprocessor
Figure 9.2. The structures of a microcontroller and a microprocessor
Microcontrollers
2
Bits Memory/devices Instruction set Memory architecture
4 8 16 32 Embedded External CISC RISC Von Neumann
Harvard
Figure 9.3. Types of microcontroller
No Criterion Microprocessor Microcontroller
1 Cost High Low
2 Energy use Medium to high Very low to low
3 Applications Desktop computers, Laptops, notepads, Appliances, digital
Ipad, Cellphone camera, toys, robots
4 Speed Very fast Slow to fast
5 External parts Many Few
6 Manufacturers Intel, ARM, AMD, IBM, Samsung, Texas Instruments,
Motorola Microchip, Fujitsu, Silicon
Labs, Intel
7 Internal No Yes
Memory
8 Storage Hard disk (128 GB up to 2 TB) Flash memory (32 kB to 2
MB)
9 Typical form
Table 9.2. A comparison between a microprocessor and a microcontroller
No: 1 2 3
3
Sample
Pins 28 100 -
Name through-hole mount surface mount package chip-scale package
package (Quad flap) (CSP)
Figure 9.4. Microcontroller Packaging
Processor SRAM EEPROM/ Timer/
core Flash Counter
Internal bus
Digital I/O Serial interface Analog Interrupt
module module module controller
… …
Figure 9.5. Basic layout of a microcontroller
4
Figure 9.6. Atmel ATmega644P pinout
Digital signal Analog signal Electric motor
Microcontroller D/A converter
Actuator/servo
GPS
Analog Digital signal
signal
Altimeter A/D converter Microcontroller
Pitot-tube
Figure 9.7. The function of D/A converter and A/D converter
5
Figure 9.8. ISP output connections to an 40-lead PDIP
Elevator Rudder Ailerons
IMU
Antenna GPS
Arduino Transmitter
Receiver
Battery
Electric motor CAMERA
pack
Figure 9.9. Arduino wiring in an UAV
6
Verify Upload New Open Save
Figure 9.10. Arduino software and its main menu items
No Function group Example
1 Digital I/O digitalRead(); digitalWrite(); pinMode()
2 Analog I/O analogRead(); analogReference(); analogWrite()
3 Time delay(); delayMicroseconds(); micros(); millis()
4 Math abs(); constrain(); map(); max(); min(); pow(); sq(); sqrt()
5 Trigonometry cos(); sin(); tan()
6 Characters isAlpha(); isAscii(); isControl(); isDigit(); isGraph(); isPrintable()
7 Bits and Bytes bit(); bitClear(); bitRead(); bitSet(); bitWrite(); highByte(); lowByte()
8 Communication serial; stream
9 USB kyboard; Mouse
Table 9.3. Functions in Arduino programming
No Syntax group Example
1 Sketch loop(); setup()
2 Control Structure break; continue; do...while; else; for; goto; if...else; return; while
3 General #define (define); #include (include); /* */ (block comment); //
(single line comment); ; (semicolon); {} (curly braces)
4 Arithmetic % (remainder); * (multiplication); + (addition); - (subtraction); /
Operators (division); = (assignment operator)
5 Comparison != (not equal to); < (less than); <= (less than or equal to); == (equal
Operators to); > (greater than); >= (greater than or equal to)
6 Boolean ! (logical not); && (logical and); || (logical or)
Operators
7 Pointer Access & (reference operator); * (dereference operator)
Operators
Table 9.4. Elements to structure an Arduino program
7
14 13
12
1
11
10
3
7
4
6 8
5
Figure 9.11. Elements of an Arduino Uno board
Pilot force Arduino E
Stick Potentiometer Servomotor Elevator
board
Figure 9.12. Block diagram of the open-loop control of an elevator
8
Servo
USB connection
Signal
Battery
(5 V)
5V GND Potentiometer
Figure 9.13. Circuit, wiring, and schematic of the servo control system
#include <Servo.h> Create servo object to control a servo
Servo myservo;
int potpin = 0; Connects analog pin A0 to the potentiometer
int val;
void setup() Variable to read the value from the analog pin
{
myservo.attach(9); Attaches pin 9 to the servomotor
}
void loop() Reads the value of the potentiometer (value between 0 and 1023)
{
val = analogRead(potpin); Scale it to use it with the servo (value between 0 and
val = map(val, 0, 1023, 0, 180);
myservo.write(val); Sets the servo position according to the scaled value
delay(15);
} Waits for the servo to rotate
9
Figure 9.14. ArduPilot AMP 2.6
Figure 9.15. MP21283X MicroPilot’s triple redundant autopilot
No Parameters Value/features
1 Altimeter Max altitude: 12,000 m
2 Sensors - 2g, 3-axis accelerometers
- 3-axis rate gyro
- Max angular rate: 150 per sec
3 Supply voltage 4.2 to 26 V
4 Dimension 10 cm in length, 4 cm in width, 1.5 cm in height
5 Mass 28 grams (including GPS receiver, gyros and all sensors)
6 GPS Update rate: 1 Hz
Table 9.5. Characteristics of MicroPilot MP21283X autopilot
10
List the technical design requirements
Identify the features and number of signal receivers from microcontroller (e.g., engine, elevator)
Identify the features and number of signal transmitters to microcontroller (e.g., measurement devices)
Select the type of microcontroller
Design/build or order the microcontroller
Design the wiring and connections between microcontroller and other elements
Select programming language
Develop a flight
simulation code including Write the code
the controller design
Debug the code
Compile the code
Upload the compiled file into microcontroller
Install the microcontroller, and examine its performance Fail
Pass
Optimize, and Calculate power consumption
Figure 9.16. Microcontroller design/selection/development procedure
11
Ball Lidar
Beam
Servo
Figure 9.17. Beam balance mechanism
Wire to Servo Wire to range finder
Figure 9.18. Wiring of the Arduino Uno board
12
30
Distance (cm)
25
20
15
10
0 time (sec) 30
0 5 10 15 20 25
Figure 9.19. Variations of the ball location on the beam
13