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
Memorysizes (SRAM & flash)
Packagesizes
Types of Microcontrollers:
Bits
Memory/devices
Instruction set
MemoryArchitecture
Bits - 4 / 8 /16/ 32
Memory/devices - Embedded/External
Instruction set - CISC/RISC
Memory architecture - Princeton/Harvard
Metrics we need to consider:
powerconsumption
Clockfrequency
IO pins
Memory
Internal functions
Others
PowerConsumption - We cannot afford mA MCU because the power budget of the system is 3.47 mA.
ClockFrequency - (speed that instructions are executed)
kHz is too slow…
100MHz is over kill…
IOpins (interfaceforexternalperipherals) - 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
InternalFunctions - Migrating data from the sensor to the radio (DMA)
Memory - Store accelerometer history data.
Internal Memory (MCU) - RAM0.5 - 128kBytes
External Memory (MCU) - Flash, high power consumption, 5mA for read and ~10mA for erase.
Components of Microcontroller:
Programmemory
RAM
A/DConverter
Microprocessor
Oscillator
I/O Devices (Sensors)
Keyboard
Mouse
Microphone
Scanner
Video/PhotoCamera
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?
Getandsetparameters
Receiveandtransmitdata
Enableanddisablefunctions
How can we imagine providing an interface to hardware from software?
SpecializedCPUinstructions (x86in/out)
Treatingdevicesliketheyarememory (MMIO)
PortI/O - Devices registers mapped onto “ports”; a separate address space. Use special I/O instructions to read/write ports.
Memory MappedI/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:
ifstatement - executes a block of code if a certain condition is true
elsestatement - executes a block of code if a certain condition is false
forloop - repeats a block of code a specific number of times
whileloop - repeats a block of code while a certain condition is true
do-whileloop - repeats a block of code at least once and continues while a certain condition is true.
switch-casestatement - executes different blocks of code based on the value of a variable.