Seminar 1
-
Upload
thanh-nguyen -
Category
Documents
-
view
18 -
download
0
Transcript of Seminar 1
-
5/24/2018 Seminar 1
1/32
Programming embedded systems
Seminar 1
INTRODUCTION
Dr. Tran Thanh Hung
Department of Automation Technology,
College of Engineering, Can Tho University
Email: [email protected]
-
5/24/2018 Seminar 1
2/32
Outline
Seminar objectives
Embedded system: What is it?
Course overview
Why C?
Why MSP430?
Hardware & Software required
Simple software architecture
Examples
Software delay
-
5/24/2018 Seminar 1
3/32
Seminar objectives
At the end of this seminar, by referring the lecture
notes, students will be able to:
know the course objectives
identify the requirements for an embedded system explain why MSP430 and C are chosen for embedded
system development
explain the relationship between C, assembly, and
machine languages know the basic features of MSP430
write a simple software to run a task
-
5/24/2018 Seminar 1
4/32
What is an embedded system?
An embedded systemis a computer systemdesigned for one or few application.
Which components does an embeddedsystem consist of?
http://en.wikipedia.org/wiki/Computer_systemhttp://en.wikipedia.org/wiki/Computer_system -
5/24/2018 Seminar 1
5/32
Core of embedded system
MCU = MicroController Unit
-
5/24/2018 Seminar 1
6/32
Applications of embedded system
Mobile phone systems
Automotive applications
Domestic appliances Aerospace applications
Medical equipment
Defence systems
-
5/24/2018 Seminar 1
7/32
Course overview
This course will introduce the principles of
programming for embedded systems.
By the end of this course, you will be able to:
Know how to build an embedded system
Design embedded software for a simpleapplication
Implement and test designed software
Understand issues of reliability and safety
-
5/24/2018 Seminar 1
8/32
Textbooks
1. Embedded C by Michael J. Pont
2. MSP-EXP430G2 LaunchPad Experimenter
Users Guide3. Code Composer Studio Users Guide
4. MSP430G2435 Datasheet
-
5/24/2018 Seminar 1
9/32
How computers were built?
-
5/24/2018 Seminar 1
10/32
Which programming language
should you use?
Remember:
CPU/MCU can only understand programs in machinelanguage
All programs need to be translated to machine code Need a good translator software: translate correctly
what you write
Power and memory of MCU are limited: language must
be efficient For programming embedded system, you need low-
level access to hardware
-
5/24/2018 Seminar 1
11/32
Why C?
A mid-level:- support functions
- access hardware
Independent to device High efficient
Popular
Easy to understand Good compilers
-
5/24/2018 Seminar 1
12/32
Can we build CPU/MCUs that can
understand high-level language?
-
5/24/2018 Seminar 1
13/32
Can we build CPU/MCUs that can
understand high-level language?
Thats means:
-
5/24/2018 Seminar 1
14/32
Why MSP430?
How to chose MCU for an embedded system?
Some famous MCUs:
+ Z80 (8bit) designed by Zilog from 1976: needs too
many clock periods to run an instruction
+ 8051 (8bit) series (or MSC-51) developed by Intel
from1980: one of the first single chip microcontrollers,
needs 12 clock periods to run an instruction
+ AVR (8bit-RISC) developed by Atmel in 1996,
integrates ADC and many other components, most
instructions run in 1 clock period
+ MSP430 (16bit-RISC) developed by Texas Instrument
from 1990s
-
5/24/2018 Seminar 1
15/32
Why MSP430?
In this course, MSP430 family is chosen,because:
- Price: very cheap- Available: very famous, easy to find
- Performance: powerful, ultra low-power,
suitable for many embedded systems- Wide range: many MCUs to choseSee http://www.ti.com/msp430
-
5/24/2018 Seminar 1
16/32
Hardware & Software required
MSP430 LaunchPad
-
5/24/2018 Seminar 1
17/32
Hardware & Software required
Software required:
- Code Composer Studio (CCS)
- Or IAR Embedded Workbench
See http://focus.ti.com/docs/toolsw/folders/print/msp-exp430g2.html#0
-
5/24/2018 Seminar 1
18/32
MSP430 Block Diagram
-
5/24/2018 Seminar 1
19/32
MSP430 Characteristics
16 bit RISC CPU, up to 25 Mhz Clock
Ultra low power consumption:
0.1 A for RAM data retention
0.8 A for real-time clock mode operation
250 A/MIPS during active operation
Low operation voltage: 1.8V3.6 V
Up to 256K Bytes of In-System Programmable(ISP) Flash Memory
-
5/24/2018 Seminar 1
20/32
MSP430 Characteristics
Pin-outs from 14 pins up to 100 pins
Most pins have multiple features (pinmultiplexing)
On-chip analogue devices: ADC, DAC
Embedded Debug/Emulation capability (JTAG)
Many 16-bit Timer/Counters Many Interrupt Sources
Serial Interface: SPI, I2C
-
5/24/2018 Seminar 1
21/32
Simple software architecture
What is the minimum software environmentyou need to run a task X()?
void main (void){
X_Init() ; //Prepare for Task X()
while(1) //super loop
{
X(); //Perform task X()
}
}
-
5/24/2018 Seminar 1
22/32
Simple software architecture
What are strengths of super loops ?
- Very simple, easy to build, debug, test, and maintain
- High efficient: use minimum hardware
- Highly portable
BUT: What are the weakness ?
- Not suitable for applications required accurate timing
- Full power consumption
-
5/24/2018 Seminar 1
23/32
Example 1.1: Flashing a LED
#include msp430g2452.h
void main(void)
{WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
while(1)
{
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
}
}
How to write a software to turn on/off a LED connected to P1.0?
Can you see the LED blink? Why?
-
5/24/2018 Seminar 1
24/32
Example 1.2: LED runs
#include msp430g2452.h
void main(void)
{ unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0xFF; // Set P1 to output directionwhile(1)
{
for (i = 0;i
-
5/24/2018 Seminar 1
25/32
Software delay
void loop_delay(void)
{
unsigned int x;
for (x = 0; x
-
5/24/2018 Seminar 1
26/32
Software delay
What are strengths of software delay ?
- Can be used to create very sort delays
- Require no hardware
- Will work on any microcontroller
BUT: What are the weakness ?
- Very difficult to create precisely time delays
- Need to be re-tuned if you change microcontroller, or
clock frequency, or compiler optimization settings
-
5/24/2018 Seminar 1
27/32
Conclusion
Seminar objectives
Embedded system: What is it?
Course overview
Why C?
Why MSP430?
Hardware & Software required
Simple software architecture
Examples: Central heating system; access input,output
Software delay
-
5/24/2018 Seminar 1
28/32
Bi tp 1.0
1. Ci t phn mm Code Composer Studio V.4
2. Tm hiu phn mm Code Composer Studio:
- Cc menu, ca s
- Cch to project, bin dch (build), debug (tronghelp contents)
- Common Debug Actions
-
5/24/2018 Seminar 1
29/32
Bi tp 1.1
To project Baitap1_1
Chn thit b MSP430G2452 cho DeviceVariant
To source file baitap1_1.c, nh li ni dungtrong Example 1.1
Bin dch v Debug chng trnh
Chy tng lnh chng trnh, quan st LED Chy chng trnh lin tc, quan st LED
Thay i chng trnh LED chp tt 1
ln/giy
-
5/24/2018 Seminar 1
30/32
Bi tp 1.2
To project Baitap1_2
Chn thit b MSP430G2452 cho DeviceVariant
To source file baitap1_2.c, nh li ni dungtrong Example 1.2
Bin dch v Debug chng trnh
Chy tng lnh chng trnh, quan st LED Chy chng trnh lin tc, quan st LED
Thay i chng trnh thy c LED chy
ui
-
5/24/2018 Seminar 1
31/32
Bi kim tra 1.1
1. Lit k cc thnh phn chnh ca mt h thng nhng.
2. Ti sao MSP430 v C c chn pht trin hthng nhng?
3. Mi quan h gia C, hp ng v ngn ng my thno?
4. Dng Code Composer Studio, tm on m tngng bng hp ng v m my ca 1 vng for trong
hm delay.
5. Ti sao chng ta cn dng siu vng lp thc hinmt cng vic?
-
5/24/2018 Seminar 1
32/32
T hc (5G)
Khm ph cc tnh nng cn li ca CCS
c file Code Composer Studio Users
Guide