Microcontrollers Introduction

Microcontrollers Introduction

EE 308: Microcontrollers Introduction Aly El-Osery Electrical Engineering Department New Mexico Institute of Mining and Technology Socorro, New Mexico, USA January 17, 2019 Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 1 / 25 What are microcontrollers? A microcontroller is a processor with memory and several other components integrated on a a single chip making it perfect for a variety of applications covering a wide range, e.g., coffee machines, automotive industry, communications, defense systems, satellites, etc. Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 2 / 25 Differences between microcontrollers and microprocessor Microcontroller Microprocessor EEPROM/ Timer/ CPU SRAM Flash Counter EEPROM/ Timer/ CPU SRAM Flash Counter Digital I/O Serial Other Serial Digital I/O ADC ADC module interface peripherals General Purpose interface module Microprocessor Microcontroller Contains a processor Processor is standalone, memory and I/O Has memory and I/O modules integrated on modules are seperate the same chip Designer can choose components for memory Compact and I/O Cheap High processing power Small power consumption General purpose Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 3 / 25 Variety of microcontroller manufacturers 68HC11/12 — Freescale Semiconductors’s (Formerly Motorola) 8051 — Intel AVR — Atmel Z8 — Zilog PIC — Microchip Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 4 / 25 Evaluation boards BigAVR6 Dragon12 Plus ATtiny85 Zilog Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 5 / 25 Embedded systems Control unit performed by a microcontroller is integrated into the system. Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 6 / 25 Mechatronics Integration for mechanical systems with electronics and information processing. Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 7 / 25 Factors to consider Capability of meeting the specification of the task at hand Speed Packaging Power consumption Amount of memory Number of I/O pins Upgradability Cost Development tools Availability Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 8 / 25 CISC vs RISC Complex Instruction Set Computer (CISC) Larger architecture Variable code size Powerful instruction set Requires several clock cycles to execute instructions Reduced Instruction Set Computer (RISC) Simple architecture Small set of instructions One or few clock cycles to execute instructions Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 9 / 25 Von Neumann vs Harvard Von Neumann Harvard Code Data data bus data bus memory memory Code Data data bus CPU memory control bus control bus memory address bus CPU control bus address bus address bus Harvard architecture Von Neumann architecture Separate buses for accessing code and Code and data are accessed through the data same bus Faster Results in a bottle neck since we can’t Less delays access code and data at the same time Requires more hardware More delays Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 10 / 25 AVR Core RISC with Harvard architecture Code ROM Data RAM Data EEPROM Timers I/O ports ADC PWM Communication interfaces: USART, SPI, I2C (TWI), CAN, USB Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 11 / 25 Atmega1284 RISC architecture 131 instructions (most executes in single clock cycle) 128K bytes code ROM 4K bytes EEPROM 16K bytes SRAM JTAG Timers/counters, PWM, 8-channel 10bit ADC Watchdog timer USART, SPI, I2C Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 12 / 25 Atmega1284 PDIP Package This will be the chip used through out the semester. Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 13 / 25 Reasons for using assembly More efficient use of computing power and memory Closer to the hardware If mass production is the goal, then there will be money saving by going to smaller cheaper parts Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 14 / 25 Assembly language Assembly language consists of, instructions referred to as mnemonics, directives and labels. .INCLUDE "M1284DEF.INC" LDI R16, hi8(RAMEND) OUT SPH, R16 LDI R16, lo8(RAMEND) 5 OUT SPL, R16 ;initialize stack pointer SBIDDRC, 0 ;set bit0 of DDRC HERE: SBIPORTC, 0 10 CALLDELAY ;call DELAY subroutine CBIPORTC, 0 CALLDELAY RJMPHERE 15 DELAY: LDI R20, 255 DL1 :DEC R20 BRNE DL1 RET Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 15 / 25 Assembly language Assembly language consists of, instructions referred to as mnemonics, directives and labels. .INCLUDE "M1284DEF.INC" Directive LDI R16, hi8(RAMEND) OUT SPH, R16 LDI R16, lo8(RAMEND) 5 OUT SPL, R16 ;initialize stack pointer SBIDDRC, 0 ;set bit0 of DDRC HERE: Label SBIPORTC, 0 10 CALLDELAY ;call DELAY subroutine CBIPORTC, 0 CALLDELAY RJMPHERE Comment 15 DELAY: LDI R20, 255 DL1 :DEC R20 Instruction BRNE DL1 RET Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 15 / 25 Software tools GNU AVR toolchain (will be used in lectures) Free Open source Linux and Windows (WinAVR) Arduino IDE is based on it Requires a bit more effort to make it work Atmel Studio (mostly used in the lab) Free Supports all their products Runs only on Windows Has and additional assembler (used by default): avrasm2 Can’t handle mixed C and assembly, and relies on GCC to do that Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 16 / 25 What to download on the microcontroller Assembler — replaces mnemonics by their opcodes, resolves include directives, translates register names to addresses, removes comments, etc. avr-as -mmcu=atmega1284 -o ex.o ex.s Linker — links multiple files avr-ld -mavr51 -o ex.elf ex.o Translate object files avr-objcopy -j .text -j .data -O ihex -o ex.hex ex.elf Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 17 / 25 Intel Hex vs S19 Motorola S19 Intel Hex S01100006578616D706C65345F332E686578C9 :1000000000E40EBF0FEF0DBF389A409A0E940C001B S113000000E40EBF0FEF0DBF389A409A0E940C0017 :1000100040980E940C00F9CF4FEF4A95F1F70895F0 S113001040980E940C00F9CF4FEF4A95F1F70895EC :00000001FF S9030000FC Start code (:) Record type (2 characters) Byte count data only (2 characters) S0 Block header Address (4 characters) S1-3 Data records Record type (2 characters) S5 Record count 00 data record S7-9 End of block 01 end of file Byte count (2 characters) Address + Data + Checksum Data (2k characters) Address (4 characters) Checksum (2 characters) Data (2k characters) Checksum (2 characters) Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 18 / 25 Downloading the hex file Using Dragon Board avrdude -v -c dragon_jtag -p m1284 -Pusb -U flash:w:ex.hex Using ArduinoISP avrdude -v -c arduino -p m1284 -Pusb -b 19200 -U flash:w:ex.hex Overview Choosing a Microcontroller Microcontroller Architectures AVR Microcontroller Atmega1284 Assembly vs C Toolchain Aly El-Osery (NMT) EE 308: Microcontrollers January 17, 2019 19 / 25 avr-as vs avrasm2 There are differences between the GCC assembler and the one used by Atmel. For full list you need to consult the documentation but below are some of the frequently used ones. avr-as avrasm2 .equ DDRA, 0x01 .equ DDRA = 0x01 .asciz “hello” .db “hello”,0 .section .data .dseg .section .text .cseg hi8 high lo8 low Overview Choosing a Microcontroller

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    28 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us