cps 310 intro to arduino

Course Overview

  • Course: CPS 310 - Computer Organization II

  • Instructor: Prof. Alex Ufkes, Toronto Metropolitan University

  • Required Kit:

    • ELEGOO UNO Project Super Starter Kit

    • Arduino UNO-3 with Atmega328p microcontroller

  • Platform: Check D2L for announcements and options.

Understanding Microprocessor and Microcontroller

Microprocessor
  • Definition: A processor packaged in a single Integrated Circuit (IC).

  • Characteristics:

    • No integrated memory; requires external memory.

    • No built-in I/O; needs peripheral chips/protocols for interfacing devices.

    • Not compact; leads to limitations in design shrinks.

  • Categories by Scale of Integration (SI):

    • SSI (Small Scale Integration): < 100 components

    • MSI (Medium Scale Integration): 100 - 3K components

    • LSI (Large Scale Integration): 3K - 100K components

    • VLSI (Very Large Scale Integration): 100K - 1M components

    • ULSI (Ultra Large Scale Integration): > 1M components

Microcontroller
  • Definition: A microprocessor with integrated memory and I/O. Compact computer in a single VLSI chip.

  • I/O Characteristics:

    • Specific pins for reading/writing signals.

    • Integrated features like ADCs, serial communication, but not peripherals like keyboard or GPUs.

AVR Microcontrollers

  • Origin: Developed since 1996 by students Alf-Egil Bogen and Vegard Wollan at the Norwegian Institute of Technology.

  • Common Knowledge:

    • AVR is often thought to stand for "Alf and Vegard's RISC processor."

    • Notably used onboard flash memory instead of PROM/EEPROM storage.

  • Architecture:

    • Uses Modified Harvard Architecture, where data and instructions may share the same memory space, allowing dual access.

ATMega328p Microcontroller
  • Usage: Found in Arduino boards; vital specifications can be referenced from its datasheet.

  • Key Features:

    • Dual Inline Package (DIP) version available for easy mounting on breadboards.

    • Caution: Exchanging MCU may require soldering skills if damaged.

  • Performance:

    • 8-bit RISC architecture capable of handling 20 MIPS throughput at 20 MHz, with multiple types of non-volatile and volatile memory.

    • I/O Ports:

    • 3 ports (B, C, D) providing flexibility for interaction with hardware components.

Instruction Set

AVR Instruction Set Overview
  • Contains 131 powerful instructions, most executing in a single clock cycle.

  • Registers:

    • 32 General Purpose Working Registers (R0-R31).

    • Only R16-R31 can load immediate constants via the LDI instruction.

Status Register (SREG)
  • Provides critical information about the result of recent operations with specific flags (C, Z, N, V, H, S, T, and I) for control processing and interrupts.

Addressing Modes
  • Direct Register Addressing: Hardcoded addresses for direct access.

  • Data Indirect Addressing: Uses X, Y, or Z registers for indirect addressing; includes pre/post increment/decrement varieties for ease of access.

Using the Arduino IDE

  • Basic Structure:

    • setup(): Initializes settings and runs once.

    • loop(): Runs continuously.

  • Inline Assembly in Arduino: Allows control hardware directly through assembly instructions wrapped in asm().

  • Example of Controlling an LED:

void setup() {
  asm("sbi 0x04, 5");  // Set PORTB5 as output
}
void loop() {
  asm("sbi 0x05, 5");   // Set LED pin high
  delay(1000);
  asm("cbi 0x05, 5");   // Set LED pin low
  delay(1000);
}

Practical Application

  • LED Project:

    • Connect an LED on a breadboard to the Arduino and control it through the respective GPIO pin (e.g., PB5).

    • Ensure correct connections and resistor values to avoid overloads that could damage components.

Summary of Key Topics

  • Microprocessor vs Microcontroller

  • ATMega328p features and configuration

  • AVR Instruction Set and addressing modes

  • Inline assembly usage in Arduino

Learning & Additional Resources

  • Familiarize with data sheets and instruction sets as tools to enhance practical programming and hardware interaction skills.

  • Check online resources and forums for help with specific assembly instructions or circuit designs.