[MCU] Lecture1 - Introduction.pptx
[MCU] Lecture1 - Introduction.pptx
LÊ TRỌNG NHÂN
trongnhanle@hcmut.edu.vn
trongnhanle85@gmail.com
Zalo Group [KSTN]
▪ 15 weeks for Lectures
▪ 6 weeks for Labs (30%)
▪ MCQs for Mid-term (20%)
▪ MCQs for Final-term (50%)
▪ Final project: +1 maximum
https://zalo.me/g/yhlqbv805
2
Zalo Group [CLC]
▪ 15 weeks for Lectures
▪ 6 weeks for Labs (30%)
▪ MCQs for Mid-term (20%)
▪ MCQs for Final-term (50%)
▪ Final project: +2 maximum
3
Course Information
▪ 15 weeks for Lectures
▪ 6 weeks for Labs (30%)
▪ MCQs for Mid-term (20%)
▪ MCQs for Final-term (50%)
▪ Final project: +2 maximum
https://zalo.me/g/wwicvv724
4
15 Weeks for Lectures
▪ Understand microcontroller basics including all common
interfaces:
▫ General Input/Output GPIO (LEDs, Buttons)
▫ Interrupts: Timer Interrupt
▫ Serial communications: UART, I2C, SPI
▪ Final projects:
▫ Validate on hardware platforms
▫ Group of 3 students
▫ Presentations and Demos
5
6 Weeks for Labs
▪ Software requirements:
▫ STMCubeIDE
▫ Proteus simulations
▫ Github
6
24h Project for Midterm
▪ A project is given and students have 24 hour to submit
▪ The format is similar to the LAB:
▫ Project description
▫ Project manual
▫ 5 – 10 steps to finalize the project
▪ Programing on STM32CubeIDE
▪ Simulate on Proteus
▪ Submit the Report for evaluation
7
Microcontroller and Microprocessor Applications
▪ Networking & communications
▪ phones, modems, switches, routers, signal processors
▪ Many more.
8
Microprocessor vs Microcontroller
MPU MCU
Stand-alone CPU, RAM, ROM CPU, RAM, ROM and IO (and
and IO (and Timer) are Timer) are all on a single chip
separated
ROM, RAM and IO can be ROM, RAM and IO are fixed
customized
Expensive, versatility and Low cost, power and
general purpose single-purpose
(control-oriented)
High resource of power, Low resource of power,
processing and memory (for AI processing and memory (for
inferences) device controller)
Normal Operating System (32 Real Time Operating System (8
or 64 bits) or 16 bit)
9
Micro-Controller Platform
▪ Micro-Controller Unit (MCU) contains
RAM, ROM and IO
▪ Micro-Processor Unit (MPU) only
contains the CPU
▪ System on Chip (SoC) refers to MCUs
with a greater number of onboard
peripherals and functionality
http://www.ti.com http://www.microchip.com
10
Program on MPU vs MCU
11
Warm up Exercises
▪ LED turns on and off every second (LED Blinky)
12
C Language: Header and C++ Files
#include “led.h”
#ifndef __LED_H_
#define __LED_H_
int T_on;
int T_off;
#include <system_lib.h>
int counter;
#include “user_lib.h”
#include “UserFolder/lib.h”
void setOn(long duration){
//TODO: set LED on here
extern int T_on;
}
extern int T_off;
void setoff(long duration){
//TODO: set LED off here
void setOn(long duration);
}
void setoff(long duration);
void delay(long duration){
//TODO: set delay here
#endif
}
13
C Language: Main File
#include “led.h” ▪ Modules/ Libraries
#include “timer.h” are included
#include “gpio.h”
#include “button.h”
void main(){
LED
initGPIO(); ▪ Modules/ Libraries
initTimer(); are initiated
initButton();
initLED();
TIMER
….
….
while(1){};
GPIO }
void timer_isr(){ ▪ System operations are
} implemented in
interrupt functions
BUTTON void ext_isr(){
}
14
Finite State Machine (FSM)
▪ Finite-State Machine (FSM) or Deterministic Finite
Automata (DFA), finite automaton, or simply a state
machine, is a mathematical model of computation
Current State Input Next State
Locked Coin Unlocked
Push Locked
Unlocked Coin Unlocked
Push Locked A turnstile
15
Finite State Machine Programming
while(1){
switch(status){
case LOCKED:
lock_turnstile(); //operation in a state
if(Coin == true) //transition condition
status = UNLOCKED; //next state
break;
case UNLOCKED:
unlock_turnstile(); //operation in a state
if(Push == true) //transition condition
status = LOCKED; //next state
break;
default:
break;
}
}
16
Example
▪ Given an LED turns on for T_on and then turns off for
T_off.
▫ Design an DFA for this LED
▫ Implement the DFA in Arduino
17
Answer
timer_flag == 1
18
Answer (Arduino Code)
void loop(){
switch(status){ void timer_run() {
case INIT:
pinMode(13, OUTPUT); if(timer_counter > 0)
setTimer(T_on); timer_counter--;
status = LED_ON;
digitalWrite(13, HIGH);
if(counter_timer == 0)
break; timer_flag =1;
case LED_ON: }
if(timer_flag == 1){
status = LED_OFF; void setTimer (long duration){
setTimer(T_off); timer_counter = duration;
digitalWrite(13, LOW);
} timer_flag = 0;
break; }
case LED_OFF:
if(timer_flag == 1){
status = LED_ON;
setTimer(T_on);
digitalWrite(13, HIGH);
}
break;
default:
break;
}
delay(10);
}
19