Make: AVR Programming

Book description

Atmel's AVR microcontrollers are the chips that power Arduino, and are the go-to chip for many hobbyist and hardware hacking projects. In this book you'll set aside the layers of abstraction provided by the Arduino environment and learn how to program AVR microcontrollers directly. In doing so, you'll get closer to the chip and you'll be able to squeeze more power and features out of it.

Each chapter of this book is centered around projects that incorporate that particular microcontroller topic. Each project includes schematics, code, and illustrations of a working project.

Publisher resources

View/Submit Errata

Table of contents

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

Product information

  • Title: Make: AVR Programming
  • Author(s):
  • Release date: February 2014
  • Publisher(s): Make: Community
  • ISBN: 9781449355784