Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Elliot Williams
Make: AVR Programming
Preface
Why This Book?
Software Type or Hardware Type?
Manifesto!
You Will Need…
The Basic Kit
For the Basic Projects
For the Intermediate Projects
For the Motors and H-Bridge Chapters
Deluxe and Frills
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
I. The Basics
1. Introduction
What Is a Microcontroller? The Big Picture
A Computer on a Chip…
…But a Very Small Computer
What Can Microcontrollers Do?
Hardware: The Big Picture
The Core: Processor, Memory, and I/O
Peripherals: Making Your Life Easier
2. Programming AVRs
Programming the AVR
Toolchain
Toolchain overview
The Software Toolchain
Linux Setup
Windows Setup
Mac Setup
Arduino Setup
Make and Makefiles
AVR and the Arduino
Arduino Pros
Arduino Cons
The Arduino: Hardware or Software? Both!
The Arduino Is an AVR
Writing C in the Arduino IDE
Flashing the Arduino as target
The Arduino Is an AVR Programmer
Wiring your Arduino as a flash programmer
Flashing AVR chips using the Arduino as a programmer
Using Arduino as hardware programmer without the Arduino IDE
Other Hardware Programmers
Flash Programmers I Have Known and Loved
Getting Started: Blinking LEDs
Hookup
ISP Headers
AVRDUDE
AVRDUDE errors
Configuring Your Makefile
Flash
Troubleshooting
3. Digital Output
blinkLED Redux
The Structure of AVR C Code
Hardware Registers
Hardware registers: the bottom line
The three most important hardware registers
Configuring output: DDRs, PORTs
blinkLED Summary
POV Toy
Building the Circuit
Blinkenlights
Simplest POV Toy
MOSFET trickery
Pretty Patterns: The POV Toy Code
Experiment!
4. Bit Twiddling
Working Through the Code: Cylon Eyes
Bit Twiddling and Cylon Eyes
Bit Shifting
Advanced Bit Twiddling: Above and Beyond Cylon Eyes
Setting Bits with OR
Toggling Bits with XOR
Clearing a Bit with AND and NOT
Showing Off
Summary
5. Serial I/O
Serial Communication
Implementing Serial Communication on the AVR: Loopback Project
Setup: Configuring the AVR
Setup: Your Computer
Setup: USB-Serial Adapter
Putting It All Together: Test Out Your Loopback
Troubleshooting Serial Connections
Configuring USART: The Nitty-Gritty Details
AVR Square-Wave Organ
Making Music with Your Micro
Amplification
The Organ Library
The Code
Extra Goodies
Summary
6. Digital Input
Pushbuttons, Switches, Etc.
Configuring Input: DDRs, PORTs, and PINs
Interpreting Button Presses
Testing bits with AND
GCC convenience macros
simpleButton demo code
Changing State
Debouncing
Debounce Example
AVR Music Box
The Code
Boss Button
Desktop-side Scripting
Extensions
7. Analog-to-Digital Conversion I
ADC Hardware Overview
Light Meter
The Circuit
ADC power pins
LDR alternative: potentiometer
The Code
ADC Initialization
Extensions
Slowscope
The AVR Code
The Desktop Code
Synergies
AVR Night Light and the Multiplexer
Multiplexing
Setting the Mux Bits
The Circuit
The Code
Summary
II. Intermediate AVR
8. Hardware Interrupts
External Interrupts 101: Real-time Button Pressing Examples
External Interrupt 0 Example
Pin-Change Interrupt Example
Capacitive Sensor
The Sensor
The Code
Global, Volatile Variables
The volatile keyword
Aside: volatile in for loops
Debugging the Circuit
9. Introduction to the Timer/Counter Hardware
Timer/Counters: Why and How?
Test Your Reaction Time
Using Timer 0 for a Better 8-Bit Organ
AM Radio
The Circuit
CPU Speed
Setting fuse bits
Setting CPU speed in code
AM Radio: The Code
Summary
10. Pulse-Width Modulation
Bright and Dim LEDs: PWM
Brute-Force PWM Demo
Timers PWM Demo
Initializing Timers for PWM Mode
PWM on Any Pin
PWM on Any Pin Demo
Closing: Alternatives to PWM and a Timer Checklist
11. Driving Servo Motors
Servos
The Secret Life of Servos
The Circuit
The Code
Servo Sundial
The Build
Ready the Lasers!
The Code
Main and the servo
The header
The clock
Serial I/O
Servo Sundial Calibration
12. Analog-to-Digital Conversion II
Voltage Meter
The Circuit
Voltage scaling in general
The Code
Sleep mode
Oversampling
The Footstep Detector
The Circuit
The Theory
Exponentially Weighted Moving Averages
The Code
Summary
III. Advanced AVR Topics
13. Advanced PWM Tricks
Direct-Digital Synthesis
Making a Sine Wave
Next Steps: Mixing and Volume
Mixing
Dynamic Volume Control
Polling USART
ADSR Envelope
Auxiliary Files
14. Switches
Controlling Big Loads: Switches
Bipolar-Junction Transistors
MOSFETs
Power MOSFETs
Relays
Triacs and SSRs
Switches: Summary
DC Motors
15. Advanced Motors
Going in Reverse: H-Bridges
Code: Taking Your H-Bridge Out for a Spin
Experts-Only H-Bridge
PWM and the H-Bridge
Drive Modes: Sign-Magnitude
Drive Modes: Locked Anti-phase
Drive Modes: Comparison
Stepper Motors
Kinds of Stepper Motors
Full Stepping and Half Stepping
Identification of Stepper Motor Wires
Too Many Wires!
Dual H-Bridge Chips: The SN754410
The Code
Acceleration Control
Microstepping
16. SPI
How SPI Works
Bit Trading Example
Shift Registers
EEPROM External Memory
External Memory
SPI Demo Hookup
SPI Demo Code
SPI EEPROM Library Header
SPI EEPROM Library C Code
initSPI
SPI_tradeByte
Convenience Functions
Summary
17. I2C
How I2C Works
I2C Demo Hookup
I2C Demo Library
I2C Thermometer Demo
SPI and I2C Data Logger
Pointers in EEPROM
The UART Serial Menu
The Logger’s Event Loop
18. Using Flash Program Memory
Using Flash Program Memory
Memory Addresses
The Address-Of Operator: &
Pointers
Pointers in Brief
Pointers as Arguments to Functions
Summary
Optional: Dereferencing Pointers
Talking Voltmeter
PROGMEM Data Structures and the Header File
Indexing arrays: arrays of pointers in PROGMEM
Sound Playback and Voltage Reading: The .c File
The ISR
main()
Generating the Audio Data
Differential Pulse-Code Modulation
Encoding Two-bit DPCM
Encoding DPCM: wave2DPCM.py
19. EEPROM
Using EEPROM
Storing in Memory
AVRDUDE and EEPROM
Reading from Memory
Saving and Loading EEPROM
Organizing Data in EEPROM
Initializing EEPROM
Project: Vigenère Cipher Encoder/Decoder
20. Conclusion, Parting Words, and Encouragement
Learning AVR: The Missing Chapters
The Watchdog Timer
Power Savings
Crystals and Alternate Clock Sources
Bootloaders
Analog Comparator
Debugging
Put This Book Down and Build!
Index
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Make: AVR Programming
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset