Microcontrollers

Cards (43)

  • A microcontroller (MCU) is a small computer on a single integrated circuit consisting of a relatively simple central processing unit (CPU) combined with peripheral devices such as memories, I/o devices, and timers.
  • A microprocessor incorporates the functions of a computer’s central processing unit (CPU) on a single integrated circuit.
  • Things that matter:
    • Peripherals
    • Concurrency & Timing
    • Clock Rates
    • Memory sizes (SRAM & flash)
    • Package sizes
  • Types of Microcontrollers:
    • Bits
    • Memory/devices
    • Instruction set
    • Memory Architecture
  • Bits - 4 / 8 /16/ 32
  • Memory/devices - Embedded/External
  • Instruction set - CISC/RISC
  • Memory architecture - Princeton/Harvard
  • Metrics we need to consider:
    • power consumption
    • Clock frequency
    • IO pins
    • Memory
    • Internal functions
    • Others
  • Power Consumption - We cannot afford mA MCU because the power budget of the system is 3.47 mA.
  • Clock Frequency - (speed that instructions are executed)
    kHz is too slow…
    100MHz is over kill…
  • IO pins (interface for external peripherals) - Interfacing sensors, UART debugger, LEDs, Bluetooth. Analog pins (input/output analog signal e.g., audio). Digital pins (input/output digital signal e.g., busses, GPIOS)
  • Program (non-volatile) - logic to read from sensors, communicate
  • Stack - functions calls are now expensive (no recursion)
  • Data - constants (time periods), Sensor history, Communication state.
  • Memory - We need to have sufficient memory to store: Program (non-volatile), Stack, Data
  • Internal Functions - Migrating data from the sensor to the radio (DMA)
  • Memory - Store accelerometer history data.
  • Internal Memory (MCU) - RAM 0.5 - 128 kBytes
  • External Memory (MCU) - Flash, high power consumption, 5mA for read and ~10mA for erase.
  • Components of Microcontroller:

    • Program memory
    • RAM
    • A/D Converter
    • Microprocessor
    • Oscillator
  • I/O Devices (Sensors)
    • Keyboard
    • Mouse
    • Microphone
    • Scanner
    • Video/Photo Camera
  • Large Diversity - Many widely differing device types. Devices within each type also differs.
  • Speed - varying, often slow access & transfer compared to CPU. Some device-types require very fast access & transfer.
  • Access - Sequential VS random, read, write, read & write.
  • What operations does software need to perform on peripherals?
    • Get and set parameters
    • Receive and transmit data
    • Enable and disable functions
  • How can we imagine providing an interface to hardware from software?
    • Specialized CPU instructions (x86 in/out)
    • Treating devices like they are memory (MMIO)
  • Port I/O - Devices registers mapped onto “ports”; a separate address space. Use special I/O instructions to read/write ports.
  • Memory Mapped I/O - Device registers mapped into regular address space. Use regular move (assignment) instructions to read/ write a device’s hardware “registers”.
  • Microcontroller Families:
    • 8051
    • Motorola
    • PIC
    • Texas
    • National
    • ARM
    • Others
  • Family under 8051:
    • Intel
    • Atmel
    • Dallas
    • Philips
    • Siemens
  • Sketches - Arduino programs are called sketches and are written using the Arduino Integrated Development Environment (IDE).
  • Two Main Functions of Sketch:
    • setup()
    • loop()
  • setup() - this function is called once when the arduino board starts up. It is used to initialize variables, pin modes, and other configurations.
  • loop() - this function runs repeatedly after setup () is executed. It contains the main code that controls the behavior of the arduino board.
  • Variables - In arduino used to store and manipulate data. They must be declared with a specific data type before use.
  • Common Data Types
    int - integer
    float - floating-point number
    bool - boolean
    char - character
  • Comments - used to explain code logic to make it more readable. Single line comments starts with // and multi-line comments are enclosed between /* and /*
  • Libraries - collections of pre-written code that provide additional functionality. It can be included in arduino sketches to simplify the implementation of complex features and interact with various sensors, actuators, and other components.
  • Control Structures:
    • if statement - executes a block of code if a certain condition is true
    • else statement - executes a block of code if a certain condition is false
    • for loop - repeats a block of code a specific number of times
    • while loop - repeats a block of code while a certain condition is true
    • do-while loop - repeats a block of code at least once and continues while a certain condition is true.
    • switch-case statement - executes different blocks of code based on the value of a variable.