You are on page 1of 29

Programming embedded systems

Seminar 1

INTRODUCTION


Dr. Tran Thanh Hung
Department of Automation Technology,
College of Engineering, Can Tho University
Email: tthung@ctu.edu.vn

Outline
Seminar objectives
Embedded system: What is it?
Course overview
Why C?
Why MSP430?
Hardware & Software required
Simple software architecture
Example: Central heating system
Software delay

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

What is an embedded system?
An embedded system is a computer system
designed for one or few application.
Which components does an embedded
system consist of?

Core of embedded system

MCU = MicroController Unit
Applications of embedded system
Mobile phone systems
Automotive applications
Domestic appliances
Aerospace applications
Medical equipment
Defence systems
Course overview
This course will introduce the principles of
programming embedded system.
By the end of this course, you will be able to:
Know how to build an embedded system
Design embedded software for a simple
application
Implement and test designed software
Understand issues of reliability and safety
Textbooks
1. Embedded C by Michael J. Pont
2. MSP-EXP430G2 LaunchPad Experimenter
Users Guide
3. Code Composer Studio Users Guide
4. MSP430G2x21 MSP430G2x31 Mixed Signal
Microcontroller Datasheet
How computers were built?
Which programming language
should you use?
Remember:
CPU/MCU can only understand programs in machine
language
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



Why C?
A mid-level:
- support functions
- access hardware
Independent to device
High efficient
Popular
Easy to understand
Good compilers

Can we build CPU/MCUs that can
understand high-level language?
Can we build CPU/MCUs that can
understand high-level language?
Thats means:
Why MSP430?
How to chose MCU for an embedded system?
Some famous MCUs:
+ Z80 (8bit) designed by Zilog from1976: 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



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 chose
See http://www.ti.com/msp430


Hardware & Software required



MSP430 LaunchPad
Hardware & Software required
Software required:
- Code Composer Studio
- Or IAR Embedded Workbench

See http://focus.ti.com/docs/toolsw/folders/print/msp-exp430g2.html#0

MSP430 Block Diagram
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.8V 3.6 V
Up to 256K Bytes of In-System Programmable
(ISP) Flash Memory

MSP430 Characteristics
Pin-outs from 14 pins up to 100 pins
Most pins have multiple features (pin
multiplexing)
On-chip analogue devices: ADC, DAC
Embedded Debug/Emulation capability (JTAG)
Many 16-bit Timer/Counters
Many Interrupt Sources
Serial Interface: SPI, I2C

Simple software architecture
What is the minimum software environment
you need to run a task X()?

void main (void)
{
X_Init() ; //Prepare for Task X()
while(1) //super loop
{
X(); //Perform task X()
}
}

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
Example1.1: Central heating system
void main(void)
{
C_HEAT_Init(); // Init the system
while(1) // 'for ever' (Super Loop)
{
// Find out what temperature the user requires
C_HEAT_Get_Required_Temperature();
// Find out what the current room temperature is
C_HEAT_Get_Actual_Temperature();
// Adjust the gas burner, as required
C_HEAT_Control_Boiler();
}
}
Example 1.2: Flashing a LED
#include "msp430f2101.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?
Software delay
void loop_delay(void)
{
unsigned int x;
for (x = 0; x <65535; x++);
}
How to create a delay without using any hardware resource ?
void longer_loop_delay(void)
{
unsigned int x, y;
for (x = 0; x <65535; x++)
for (y = 0; y <65535; y++);
}
void delay(unsigned int ms)
{ unsigned int x, y;
for (x = 0; x <= ms; x++)
for (y = 0; y <= 120; y++);

}
How to create a useful delay?
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
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




Exercise 1.1
1. Read information on:
http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_(MSP-EXP430G2)#Included_MSP430G2xx_Device_Features
2. Load and install Code Composer Studio V.4
3. Read Code Composer Studio Users Guide

Test 1.1
1. List of components needed to build a core of an
embedded system.
2. Why MSP430 and C are chosen for embedded
system development?
3. What is relationship between C, assembly, and
machine languages?
4. Use Code Composer Studio, find the program in
assembly and machine code corresponding to a loop
delay
do i--; while (i != 0);
5. Why do we use a super loop to run a task?

You might also like