0% found this document useful (0 votes)
31 views43 pages

Programming Embedded Systems Seminar 2: Hardware Foundations

The document provides an outline for a seminar on programming embedded systems using the MSP430 microcontroller. The seminar objectives are to understand how to build the hardware for an embedded system using the MSP430G2452 microcontroller, understand issues of stability, and write programs to access inputs and control outputs. The document discusses the oscillator circuit, reset circuit, controlling outputs using LEDs, and reading inputs from switches. It provides details on the features of the MSP430G2452 microcontroller and sample code exercises for students.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views43 pages

Programming Embedded Systems Seminar 2: Hardware Foundations

The document provides an outline for a seminar on programming embedded systems using the MSP430 microcontroller. The seminar objectives are to understand how to build the hardware for an embedded system using the MSP430G2452 microcontroller, understand issues of stability, and write programs to access inputs and control outputs. The document discusses the oscillator circuit, reset circuit, controlling outputs using LEDs, and reading inputs from switches. It provides details on the features of the MSP430G2452 microcontroller and sample code exercises for students.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

Programming embedded systems

Seminar 2

HARDWARE FOUNDATIONS
Dr. Tran Thanh Hung
Department of Automation Technology,
College of Engineering, Can Tho University
Email: [email protected]

Outline
How to build the first embedded system
with MSP430?
Oscillator circuit
Reset circuit
Controlling outputs (LEDs)
Reading inputs (SWs)

Seminar objectives
At the end of this seminar, by referring the
lecture notes, students will be able to:
know how to build the hardware for an
embedded system, based on MSP430G2452
understand issue of stability
write programs to access inputs and control
outputs

MSP430G2452 Features
Low Supply-Voltage Range: 1.8 V to 3.6 V
Ultra-Low Power Consumption:
Active Mode: 220 A at 1 MHz, 2.2 V
Standby Mode: 0.5 A
Off Mode (RAM Retention): 0.1 A

Five Power-Saving Modes


Many Clock Module Configurations:
Internal High Frequencies (HF)
Internal Very Low Power Low-Frequency (LF)
32,768 Hz Crystal
External Digital Clock Source

MSP430G2452 Features
1x 16-Bit Timer
Universal Serial Interface (USI) Supporting SPI, I2C
10-Bit 200-ksps A/D Converter
On-Chip Comparator for Analog
16 I/O pins, Touch-Sense
Serial Onboard Programming
8K Bytes of In-System Programmable (ISP) Flash
Memory (10,000 Write/Erase Cycles )
256 Bytes Internal RAM

MSP430G2452 Pinout

MSP430G2452 Block Diagram

Oscillator circuit
Why oscillator circuit is needed for embedded
systems?
- It provides clock to drive embedded systems
- It is the heartbeat of the system. All operations
of the system follow this beat
What happen if the oscillator fails or run incorrectly?
- If the oscillator fails: the system will stop working
- If the oscillator run incorrectly: any timing calculations
done by the system will be inaccuracy

Oscillator circuit
Most of microcontrollers use
Pierce oscillator, a very popular
oscillator, because it requires a
minimum of components.
Most the components required for
the oscillator were integrated on
the microcontroller.
You need 1 crystal and 2 small
capacitors to form an oscillator.

Oscillator circuit
There are many options for
oscillator circuit:
Crystal oscillator
Ceramic resonator oscillator
RC oscillator
Which one do you want to
choose?

Stability issues
The key factor in selecting an oscillator for an
embedded system is the issue of oscillator
stability (how much of error).
Frequency tolerance of an:
- crystal oscillator: 0.001%
- ceramic resonator oscillator: 0.5%
- RC oscillator: 20%
What is the practical meaning of these
numbers?

Stability issue
If the oscillator runs for 1 year, how many
minutes may it gain or lose?

Which oscillator do you want to choose?

Oscillator frequency selection


The maximum frequency that MSP430 can run is
16 MHz (16 MIPS: Million Instructions Per Second)
Which frequency do you want to chose for your
embedded system?
Do you know that:
- Many applications do not require high speed
- More speed, more power consumption
- Accessing to low-speed peripherals (LED, LCD) is much
easier if microcontroller runs at low speed, low cost

Keep the clock frequency as low as possible!

MSP430G2452 clock modules


VLOCLK: Internal very Low Power, Low Frequency oscillator (12 kHz)

- XTS = 0: Low frequency


- XTS = 1: High frequency

LFXT1CLK: Low-Frequency/high-frequency oscillator

MSP430G2452 clock modules


XT2CLK: optional high-frequency oscillator

MSP430G2452 clock modules


DCOCLK: Internal digitally controlled oscillator (DCO)

Reset circuit

Why do you need to reset the microcontroller?


To put the hardware to its initial state
To start a program at the beginning
What happen if the microcontroller do not reset
correctly?
- The hardware is not in its initial state
- The microcontroller may run anywhere, not
only your program, but also random codes

Reset circuit
The MSP430 has many sources of reset:
- Power On Reset (POR) (Hardware)
Power up
Active reset pin (low)
Low signal at Supervisory Voltage System (PORON = 1)
Brownout reset

- Power Up Reset (PUR) (Software)


Active POR signal
Expiry of watchdog timer

Controlling DC loads
The MSP430 port pins can be set to 0V or Vcc

P1OUT ^= 0x01;

Each pin can sink or source a current up to 30 mA


How about controlling larger loads (current > 30 mA)?

Controlling large DC loads


Need a buffer between port pin and the load
The buffer supports current for the load
Buffer selection: depend on required current

Digital I/O Port 1


- Select output:
P1DIR.y = 1
- Select input:
P1DIR.y = 0
Default:
P1SEL.y = 0
ADC10AE.y = 0
Note: y = 0..7

Digital I/O Port 2


- Select output:
P2DIR.y = 1
P2SEL.y = 0
- Select input:
P2DIR.y = 0
P2SEL.y = 0
Default:
P2SEL.y = 1
Note: y = 1..7

Bi tp 2.1
Kho st nh hng ca vic thay i tc xung clock

To project Baitap2_1
To source file baitap2_1.c, copy ni dung trong baitap1_1.c
Bin dch v Debug chng trnh
Chy chng trnh lin tc, quan st LED, ch tc chp tt
Tm dng chng trnh
Trn menu, chn View\Registers, trong System_Clock\BCSCTL1,
t tt c cc bit RSEL v 0
Chy li chng trnh. Tc chp tt LED th no?
Tm dng chng trnh. Ghi li gi tr cc thanh ghi v I/O
Bm vo biu tng reset chng trnh . iu g xy ra vi I/O,
cc thanh ghi, im bt u thc hin chng trnh?
Chy li chng trnh. Tc chp tt LED th no?

Bi tp 2.2
Vit chng trnh bt v tt tng LED
trn Port P1. Ghi ch li th t bit iu
khin ng vi tng LED.
(gn trc tip gi tr cho P1OUT,
V d:
P1OUT = 1
P1OUT = 0)

Bi tp 2.3
Vit chng trnh:
- Bt tt c cc LED
- Tt v bt tng LED m khng nh
hng n cc LED khc. (Dng php
AND (&) v OR (|) vi mt n tt v
bt bit)

Reading switches
Why do you need to read switches?
- Embedded systems usually use switches as their user
interface, to know what users want
- Same rule applied for any system, from very simple to
very complex one

Reading switches
How to connect switches to the microcontroller?

If SW pressed, pin = 0
If SW not pressed, pin = ?
Need a pull-up resistor

- If SW pressed, pin = 0

- If SW not pressed, pin = 1

Digital I/O Port 1


- Select input:
P1DIR.y = 0
-Enable pull-up/
pull-down
P1REN.y = 1
- Set pull-up
P1OUT.y = 1
Note: y = 0..7

Digital I/O Port 2


- Select input:
P2DIR.y = 0
P2SEL.y = 0
-Enable pull-up/
pull-down
P2REN.y = 1
- Set pull-up
P2OUT.y = 1
Note: y = 0..7

Reading switches
How to read the switch status?
unsigned char Port_Data;
P1DIR = 0;
// set Port 1 as input
Port_Data = P1IN; // read Port 1 pins

How to how which switch pressed?


if (P1IN.0 == 0) //switch connected to P1.0 pressed?
{
//your code
}

Problem?

Reading switches

How to how which switch pressed?


if (!(P1IN & 0x1)) //switch connected to P1.0 pressed?
{
//your code
}

Mch m rng (thc tp)

Bi tp 2.4
Vit chng trnh m s ln SW ni vi chn P2.0 (c
th l SW0) c bm, xut kt qu ra cc LED trn
Port P1.
Kim tra xem mi ln bm SW, chng trnh m
c my ln?
Lu : Do cu to ca board m rng, SW0 c ni vi
P2.0 v P2.4. nhn bit c phm c bm hay
khng, cn cho 1 chn (v d P2.4) xung mc 0, xt
chn cn li.

Dealing with switch bounce


In practice, all mechanical switch contacts bounce after
the switch is closed and opened

Ideal SW

press

release

Real SW

Counting the number of times that a SW is pressed


becomes extremely difficult.

Dealing with switch bounce


By hardware:

Use RS latch

Use RC

Dealing with switch bounce


By software:
1. Read the relevant port pin
2. If a switch depression is detected, wait for 20ms and
then read again
3. If the second reading confirms the first reading,
assume that the switch was pressed

1st read

2nd read

Dealing with switch long depression


What happen if the user press a switch for too long?

1. Read the relevant port pin


2. If a switch depression is detected, wait for 20ms and then
read again
3. If the second reading confirms the first reading, wait until
the switch is released, assume that the switch was
pressed

Bi tp 2.4 (tt)
Vit chng trnh m s ln SW ni vi chn P1.0
c bm, xut kt qu ra cc LED trn Port P1.
Kim tra xem mi ln bm SW, chng trnh m
c my ln?
Thay i chng trnh mi ln bm SW, chng
trnh ch m 1.

Keypad interface
If a system has many SWs, how to interface with SWs?

Keypad 4x4
Keypad is a matrix of SWs or keys
How to know which SW/key is pressed?

Algorithm

Set Columns as inputs, Rows as outputs


Set a Row x to low, read Columns y
If Column y is low, delay 20ms to debounce
If Column y is still low, wait until Column y go high
Assume corresponding key was pressed

Bi tp 2.5
Vit chng trnh:
- c ma trn phm 4x4
- Hin th th t phm c
bm ra cc LED

T hc
c file msp430g2452 Datasheet:
- ch cu hnh cc port v cch t cu
hnh
- tn s DCO
c chng 4, Embedded C

You might also like