Chapter 10 - eZ430X

Download Report

Transcript Chapter 10 - eZ430X

Chapter 10 – eZ430X
+
Topics to Cover…









MSPF2274
eZ430X Development Board
Peripherals
Peripheral Devices
Low Pass Filter
Headers
Jumpers
Simon Lab
Coding Assembler
BYU CS/ECEn 124
Chapter 10 - eZ430X
2
MSP430F2274
MSP430 Typical Applications
Handheld Measurement
 Air Flow measurement
 Alcohol meter
 Barometer
 Data loggers
 Emission/Gas analyser
 Humidity measurement
 Temperature
measurement
 Weight scales
Medical Instruments
 Blood pressure meter
 Blood sugar meter
 Breath measurement
 EKG system
BYU CS/ECEn 124
Utility Metering
Home environment
 Gas Meter
 Air conditioning
 Water Meter
 Control unit
 Heat Volume Counter
 Thermostat
 Heat Cost Allocation
 Boiler control
 Electricity Meter
 Shutter control
 Meter reading system (RF)  Irrigation system
 White goods
Sports equipment
(Washing machine,..)
 Altimeter
 Bike computer
Misc
 Diving watches
 Smart card reader
 Taxi meter
Security
 Smart Batteries
 Glass break sensors
 Door control
 Smoke/fire/gas detectors
Chapter 10 - eZ430X
3
MSP430F2274
MSP430 Roadmap
BYU CS/ECEn 124
Chapter 10 - eZ430X
4
MSP430F2274
IMPORTANT!!!
Beware of static electricity, don't touch the components directly.
Never disconnect a target board from the USB programmer if still
plugged into the computer or from the battery unit with jumper on.
Otherwise you destroy the board!
BYU CS/ECEn 124
Chapter 10 - eZ430X
5
MSP430F2274
MSP430F2274
BYU CS/ECEn 124
Chapter 10 - eZ430X
6
eZ430X Development Board
eZ430X Development Board
USB Programmer
Ferrite RAM
Transponder
Servos
Thermistor
Configuration
Stakes
Accelerometer
MSP430F2274
Potentiometer
Battery Power
Speaker
BYU CS/ECEn 124
Push Buttons
Chapter 10 - eZ430X
LCD
LEDs
7
eZ430X Development Board
eZ430X Development Board
BYU CS/ECEn 124
Chapter 10 - eZ430X
8
eZ430X Development Board
Computrol Facilities
BYU CS/ECEn 124
Chapter 10 - eZ430X
9
eZ430X Development Board
Printed Circuit Boards
BYU CS/ECEn 124
Chapter 10 - eZ430X
10
eZ430X Development Board
Apply Solder Paste
BYU CS/ECEn 124
Chapter 10 - eZ430X
11
eZ430X Development Board
Robots Place Parts
BYU CS/ECEn 124
Chapter 10 - eZ430X
12
eZ430X Development Board
Discrete Parts Added
BYU CS/ECEn 124
Chapter 10 - eZ430X
13
eZ430X Development Board
Flow Soldered
BYU CS/ECEn 124
Chapter 10 - eZ430X
14
eZ430X Development Board
276 Solder Bath
BYU CS/ECEn 124
Chapter 10 - eZ430X
15
eZ430X Development Board
Final Inspection
BYU CS/ECEn 124
Chapter 10 - eZ430X
16
Peripherals
Peripherals




A/D Converter (ADC10)
Operational Amps (OA0-3) (Not covered)
Ports (P1-P4)
Power Module




Timers A/B
USCI A/B




Digitally Controlled Oscillator (DCO)
Very Low Frequency Oscillator (VLO)
USART – Universal Serial Asynchronous Rx/Tx
SPI – Serial Peripheral Interface
i2c – Inter-Integrated Circuit
Watchdog+
BYU CS/ECEn 124
Chapter 10 - eZ430X
17
Peripherals
ADC10
High-performance 10-bit
analog-to-digital conversions
• More than 200k samples/sec
• Programmable sample & hold
• Initiation by software or Timer_A
• 8 external input channels
• Selectable voltage reference
(1.5v or 2.5v)
• Internal storage
BYU CS/ECEn 124
Chapter 10 - eZ430X
18
Peripherals
Digital I/O
Independently programmable individual I/Os
Port1
Port3
Port2
Port4
Function Select Register PxSEL
yes
yes
Interrupt Edge Select Register PxIES
yes
no
Interrupt Enable Register PxIE
yes
no
Interrupt Flag Register PxIFG
yes
no
Direction Register PxDIR
yes
yes
Output Register PxOUT
yes
yes
yes
yes
• 4 ports (P1 – P4)
• Each has 8 I/O pins
• Each pin can be
configured as input or
output
• P1 and P2 pins can be
configured to assert an
interrupt request
BYU CS/ECEn 124
Input Register PxIN
7
6
5
4
Chapter 10 - eZ430X
3
2
1
0
19
Peripherals
Timer_A/B
Timer_A/B are 16-bit
timer/counters with three
capture/compare registers
• Capture external signals
• Compare PWM mode
• SCCI latch for
asynchronous
communication
BYU CS/ECEn 124
Chapter 10 - eZ430X
20
Peripherals
USART Serial Port
The Universal Synchronous/Asynchronous Receive/Transmit
peripheral interface supports
two serial modes with
one hardware module
• UART
• SPI (Synchronous Peripheral
Interface)
• I2C (Inter-Integrated Circuit)
• Double-buffered
• Baud-rate generator
BYU CS/ECEn 124
Chapter 10 - eZ430X
21
I2c – Inter-Integrated Circuit

Inter-Integrated Circuit




2-wire serial interface (Serial data SDA, Serial clock SCL)
master/slave (slaves have unique 7-bit address)
100-400 kbit/sec (relatively slow)
Slave
acknowledgment
Master provides clock
Stop
condition
Start
condition
BYU CS/ECEn 124
Read SDA
Write SDA
Chapter 10 - eZ430X
SDA stable
SDA may change
22
Watchdog Timer
WDT module performs a
controlled system restart
after a software problem
occurs
• Can serve as an interval timer
(generates interrupts)
• WDT Control register is
password protected
• Note: Powers-up active
BYU CS/ECEn 124
Chapter 10 - eZ430X
23
Peripheral Devices
Peripheral Devices









Switches (Push Buttons)
LED’s (2 + 4)
LCD (100 x 160 pixels)
FRAM (8 kb)
LCD Backlight
Potentiometers (Left & Right)
Thermistor (10k )
Accelerometer (3-axis ADXL345)
Sonar Transponder (Optional)
BYU CS/ECEn 124
Chapter 10 - eZ430X
24
Peripheral Devices
Switches

Switches



P2.0-3
Internal pull-ups
Require debouncing
BYU CS/ECEn 124
Chapter 10 - eZ430X
25
Peripheral Devices
LED’s

LED’s



P2.0-1, P3.3, P4.6
Use PWM for brightness
0 = OFF, 1 = ON
BYU CS/ECEn 124
Chapter 10 - eZ430X
26
Peripheral Devices
LCD



LCD - 100 x 160 pixels transflective
display
Transflective polarizers have both
reflecting and transmitting properties and
offer the most versatile viewing
characteristics.
They can be viewed in direct sunlight and
when combined with a backlight in low
light conditions.
BYU CS/ECEn 124
Chapter 10 - eZ430X
27
Peripheral Devices
LCD

LCD - 100 x 160 pixels display
Page 13
Page 12
Page 11
Page 10
Page 9
Page 8
Page 7
Page 6
Y (0-99) 
Page 5
BYU CS/ECEn 124
Page 4
Page 3
Page 2
Page 1
Page 0
X (0-159) 
Chapter 10 - eZ430X
28
Peripheral Devices
LCD

lcd.c Prototypes

int lcd_init(void);

void lcd_volume(int volume);

void lcd_backlight(int backlight);




int lcd_display(int mode);
void lcd_clear(int value);
void lcd_image(const unsigned char* image,
int column, int page);
void lcd_blank(int column, int page,
int width, int height);

void lcd_cursor(int column, int page);

char lcd_putchar(char c);

void lcd_printf(char* fmt, ...);
BYU CS/ECEn 124
Chapter 10 - eZ430X
29
Peripheral Devices
FRAM

FRAM





Ferroelectric Nonvolatile RAM
8192 x 8 bits
45 year retention
i2c serial bus
Unlimited R/W
cycles
Page 12
Page 11
99
98
97
96
95
94
93
92
91
90
89
88
3
2
1
0
7
6
5
4
3
2
1
0
M(1921)
M(1922)
M(1923)
M(1924)
M(2079)
M(1760)
M(1761)
M(1762)
M(1763)
M(1764)
M(1919)
M(320)
M(321)
M(322)
M(323)
M(324)
M(479)
M(160)
M(161)
M(162)
M(163)
M(164)
M(319)
M(0)
M(1)
M(2)
M(3)
M(4)
M(159)
0
1
2
3
4
159
24-87
Page 2
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Y
Page 1
Page 0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
X
BYU CS/ECEn 124
M(1920)
Chapter 10 - eZ430X
30
Peripheral Devices
LCD/FRAM - Graphics

graphics.c








int lcd_FRAM_init(void);
void lcd_circle(int x0, int y0, int r0);
unsigned char lcd_point(unsigned int x,
unsigned int y, int flag);
int FRAM_init(int size, int data);
unsigned char FRAM_read(unsigned int address);
int FRAM_write(unsigned int address,
unsigned char datum);
int read_FRAM_point(unsigned int x,
unsigned int y);
int write_FRAM_point(unsigned int x,
unsigned int y, int value);
BYU CS/ECEn 124
Chapter 10 - eZ430X
31
Peripheral Devices
LCD Backlight

LCD Backlight


P4.2 / TA2 (Jumper F)
Use PWM for dimming
// configure Timer_A: SMCLK, /1, up/down mode
#define BACKLIGHT_FREQUENCY
4
#define BL_INCREMENT
1
TAR = 0;
TACTL = TASSEL_2+ID_0+MC_1;
TACCTL2 = OUTMOD_3;
TACCR0 = BACKLIGHT_FREQUENCY;
TACCR2 = 1;
P2SEL |= 0x10;
BYU CS/ECEn 124
// reset TAR
//
//
//
//
output mode = set/reset
set frequency
set duty cycle
select TA2
Chapter 10 - eZ430X
32
Peripheral Devices
Potentiometers

Potentiometers



Use VREF+ (2.5v) internal reference and Vss (GND)
Linear potentiometers return 0-1023 values
ADC10 Channels:


12 = left potentiometer (P4.4, Jumper A1)
13 = right potentiometer (P4.3, Jumper G1)
int ADC_read(int channel)
{
ADC10CTL0 = SREF0 + ADC10SHT_2 +
P4DIR &= ~0x08;
P4SEL |= 0x08;
ADC10AE0 |= 0x00;
ADC10AE1 = 0x10;
ADC10CTL1 = channel << 12;
ADC10CTL0 |= ENC + ADC10SC;
while (!(ADC10CTL0 & ADC10IFG));
return ADC10MEM;
} // end ADC_sample
BYU CS/ECEn 124
ADC10ON + REFON + REF2_5V;
// P4.3
// A12
// A12 ADC10 function and enable
// sampling and conversion start
// wait until conversion
Chapter 10 - eZ430X
33
Peripheral Devices
Thermistor
Thermistor



1000
10k thermistor
Non-linear resistance
ADC10 Channels:


900
800
700
ADC Value

Thermistor Values
10 = internal temperature
15 = thermistor (Jumper C1)
600
500
400
300
200
100
int ADC_read(int channel)
{
ADC10CTL0 = SREF0 + ADC10SHT_2 +
P4DIR &= ~0x40;
P4SEL |= 0x40;
ADC10AE0 |= 0x00;
ADC10AE1 = 0x80;
ADC10CTL1 = channel << 12;
ADC10CTL0 |= ENC + ADC10SC;
while (!(ADC10CTL0 & ADC10IFG));
return ADC10MEM;
} // end ADC_sample
BYU CS/ECEn 124
212
194
176
158
140
122
104
86
68
50
32
0
Temperature
ADC10ON + REFON + REF2_5V;
// A15 = P4.6
// A15 ADC10 function and enable
// sampling and conversion start
// wait until conversion
Chapter 10 - eZ430X
34
Peripheral Devices
Accelerometer

ADXL345 Accelerometer




3-axis acceleration, 2 g, 4 g, 8 g, or 16 g
Dynamic acceleration (motion)
Static acceleration (gravity)
Polysilicon surface-micromachined structure
BYU CS/ECEn 124
Chapter 10 - eZ430X
35
Peripheral Devices
Sonar Transponder

MaxBotix EZ0/1 Sonar Transponder


Sonar range from 6 to 254 inches (1 inch resolution)
Analog/serial digital output
BYU CS/ECEn 124
Chapter 10 - eZ430X
36
Filters
Low Pass Filter

Digital equivalent of an analog low pass RC filter
unsigned int lowpass_filter(unsigned int input, unsigned int* delay)
{
// Update filter with current sample.
*delay += input - (*delay >> FILTER_SHIFT);
// Scale output for unity gain.
return *delay >> FILTER_SHIFT;
}
BYU CS/ECEn 124
Chapter 10 - eZ430X
37
Headers
J1 Header
Primary (L)
Pin
Signal
Secondary (R)
3
P2.0 (ACLK/A0)
SW_1
H
SW_2
4
P2.1 (SMCLK/A1)
EZ0_TX
D
ADXL345 INT1/2
5
P2.2 (TA0/A2)
SW_3
E
SW_4
6
P2.3 (TA1/A3)
Servo #3
F
LCD Backlight
7
P2.4 (TA2/A4)
Servo #4
13
P2.6
LED_1
14
P2.7
LED_2
17
P3.0 (UCB0STE/A5)
LCD RST
18
P3.1 (UCB0SDA)
LCD SDA / ADXL345 SDA / FM24CL64 SDA
15
P3.2 (UCB0SCL)
LCD SCL / ADXL345 SCL / FM24CL64 SCL
EZ0_RX
16
P3.3 (UCB0CLK)
LED_3
G
Right Potentiometer
8
P4.3 (TB0/A12)
EZ0_AN
A
Left Potentiometer
9
P4.4 (TB1/A13)
Servo #1
B
Buzzer (PWM)
10
P4.5 (TB2/A14)
Servo #2
C
Thermistor
11
P4.6 (TBOUTH/A15)
LED_4
BYU CS/ECEn 124
Chapter 10 - eZ430X
38
Jumpers
Jumpers
1 (Left Jumper)
Signal
2 (Right Jumper)
A
Left Potentiometer
P4.4 (TB1/A13)
Servo #1
B
Buzzer (PWM)
P4.5 (TB2/A14)
Servo #2
C
Thermistor
P4.6 (TBOUTH/A15)
LED_4
D
ADXL345 INT1/2
P2.2 (TA0/A2)
SW_3
E
SW_4
P2.3 (TA1/A3)
Servo #3
F
LCD Backlight
P2.4 (TA2/A4)
Servo #4
G
Right Potentiometer
P4.3 (TB0/A12)
EZ0_AN
H
SW_2
P2.1 (SMCLK/A1)
EZ0_TX
BYU CS/ECEn 124
Chapter 10 - eZ430X
39
Simon Lab
"Write a MSP430 assembly language program to play the game of Simon.
Each round of the game is started by flashing the LEDs several times.
The colored LEDs (along with the associated tones) are then flashed one
at a time in a random sequence.
Sample the push button switches and count the number of colors (tones)
correctly entered in the same order as the original sequence.
Continue until the end of the sequence is reached or a mistake is made.
Play some congratulatory tune if the sequence is correct or some
raspberry sound if a mistake is made.
If the sequence is successfully reproduced, restart the game adding one
more color/tone to the sequence. Otherwise, restart a new sequence.
Use Timer_B output (TB2) for hardware PWM of the magnetic buzzer."
BYU CS/ECEn 124
Chapter 10 - eZ430X
40
Coding Assembler
How To Code Assembler…


Understand the problem (obviously)
Until you are comfortable in assembly, (and
even afterwards), write out your solution in
something familiar





English
Flowchart
Pseudo-code
Java, C, Ruby – the pseudo-code doesn’t really
matter!
Then, translate to assembler
BYU CS/ECEn 124
Chapter 10 - eZ430X
41
Coding Assembler
Three Basic Constructs
Task
True
False
Test
condition
Subtask 1
Test
condition
False
True
Subtask 1
Subtask 2
Subtask 2
Sequential
BYU CS/ECEn 124
Subtask
Conditional
Chapter 10 - eZ430X
Iterative
42
Coding Assembler
if-then-else Translation

if-then-else
cmp.w
jne
xor.b
bis.b
jmp
myElse:
bic.b
myNext:
BYU CS/ECEn 124
#1,&buzzerON
myElse
#0x20,&P4OUT
#0x02,&P1OUT
myNext
#0x02,&P1OUT
;
;
;
;
;
;
;
;
;
if (buzzerON == 1)
{
pulse_buzzer();
turn_on_LED();
}
else
{
turn_off_LED();
}
Chapter 10 - eZ430X
43
Coding Assembler
while Translation

while loop…
while_loop:
bis.w #Z,SR
jnz while_done
call #LED_ON
call #delay
call #LED_OFF
call #delay
jmp
while_loop
; #define TRUE 1
;
; while (TRUE)
;{
; LED_ON();
; delay();
; LED_OFF();
; delay();
;}
while_done:
;
BYU CS/ECEn 124
Chapter 10 - eZ430X
44
Coding Assembler
switch/case Translation

switch/case
cmp.w
jne
call
jmp
sw_01:
cmp.w
jne
call
jmp
sw_end:
BYU CS/ECEn 124
#DOT,&myByte
sw_01
#do_dot
sw_end
; switch (myByte)
;{
; case DOT:
do_dot();
;
break;
#DASH,&myByte
sw_end
#do_dash
sw_end
; case DASH:
do_dash();
;
break;
;
;
; default:
;}
Chapter 10 - eZ430X
45
Coding Assembler
for-loop Translation

for-loop
.bss
mov.w
fl_ck: cmp.w
jge
call
call
call
call
add.w
jmp
for_done:
BYU CS/ECEn 124
i,2
; int i;
#0,&i
#10,&i
for_done
#do_dot
#delay
#do_dash
#delay
#1,&i
fl_ck
; for(i=0; i<10; i++)
; {
;
do_dot();
;
delay();
;
do_dash();
;
delay();
;
;
; }
;
Chapter 10 - eZ430X
46
BYU CS/ECEn 124
Chapter 10 - eZ430X
47
Pulse Width Modulation (H/W)
TxCCTLx Control Register
15
14
13
12
11
10
9
8
7
Capture Configuration
Bit
OUTMODx
5
4
3
2
1
0
CCIE
CCI
OUT
COV
CCIFG
Description
15-8
7-5
6
Capture Configuration (Set to 0)








OUTMODx
Output mode:
4
CCIE
Capture/compare interrupt enable when CCIE = 1.
3
CCI
Capture/compare input
2
OUT
Output state
1
COV
Capture overflow when COV = 1
0
CCIFG
Capture/compare interrupt flag CCIFG = 1 when interrupt pending
BYU CS/ECEn 124
000
001
010
011
100
101
110
111
bit OUT
Set
Toggle/Reset
Set / Reset
Toggle
Reset
Toggle / Set
Reset / Set
Chapter 10 - eZ430X
48
Pulse Width Modulation (H/W)
Timer_A/B Output modes
BYU CS/ECEn 124
Chapter 10 - eZ430X
49
Pulse Width Modulation (H/W)
Timer_B PWM Example

Use PWM w/Timer B for transducer tones:
;
reset TimerB
clr.w &TBR
;
SMCLK, /1, up mode (no interrupts)
mov.w #TBSSEL_2+ID_0+MC_1,&TBCTL
;
TB2 output mode = set/reset
mov.w #OUTMOD_3,&TBCCTL2
;
load tone (frequency)
mov.w &DO,&TBCCR0
;
load volume (duty cycle)
mov.w #DO/2,&TBCCR2
BYU CS/ECEn 124
Chapter 10 - eZ430X
50
Pulse Width Modulation (H/W)
Step 12a: Use Timer Output PWM

First, eliminate a lot of code!!
.bss
.bss
.bss
duty_cycle_high,2
duty_cycle_low,2
duty_cycle_toggle,1
; high part of cycle
; low part of cycle
; duty cycle flag
mov.w
bis.w
mov.w
mov.w
#DO/2,&TBCCR0
#TBIE,&TBCTL
#DO/2,&duty_cycle_high
#DO/2,&duty_cycle_low
; start clock
; enable timer B interrupts
; set duty cycles
; << adjust volume here >>
;
rra.w
r4
;
mov.w
r4,r5
mov.b
volume,r5
mov.w
duty(r5),r5
sub.w
r5,r4
cmp.w
#0,r5
jne
WD04
mov.w
#0,r4
WD04:
; 50% duty cycle
;
;
;
;
;
;
get volume
r5 = duty cycle
subtract from frequency
turn off?
n
y, high=low=0
mov.w
mov.w
mov.w
r4,&TBCCR0
r4,&duty_cycle_high
r5,&duty_cycle_low
bic.w
xor.b
xor.b
jeq
mov.w
jmp
; timer B ISR
#TBIFG,&TBCTL
; acknowledge interrupt
#0x20,&P4OUT
; pulse buzzer
#1,&duty_cycle_toggle
; high?
TB02
; n
&duty_cycle_high,&TBCCR0 ; y, set high duty cycle
TB04
TB02:
mov.w
&duty_cycle_low,&TBCCR0 ; set low duty cycle
TB04:
reti
TB_isr:
.sect
.word
; start clock (if necessary)
; set high duty cycle
; set low duty cycle
; return from interrupt
".int12"
TB_isr
BYU CS/ECEn 124
; timer B section
; timer B isr
Chapter 10 - eZ430X
51
Pulse Width Modulation (H/W)
Step 12b: Use Timer Output PWM

Put transducer (P4.5) as secondary function
bis.b
mov.w
mov.w

#0x20,&P4SEL
#OUTMOD_3,&TBCCTL2
#DO/2,&TBCCR2
; P4.5 transducer output
; output mode = set/reset
; use TBCCR2 as volume
Change WD ISR to just put the duty cycle in TBCCR2
; << adjust timer b tone here >>
push
r5
add.w
r4,r4
mov.w
scale(r4),r4
mov.w
r4,&TBCCR0
mov.b
volume,r5
add.w
r5,r5
mov.w
duty(r5),r5
mov.w
r5,&TBCCR2
pop
r5
BYU CS/ECEn 124
;
;
;
;
;
;
;
;
save r5
(word index)
r4 = tone (frequency)
start clock (if necessary)
get volume
(word index)
r5 = duty cycle
start clock (if necessary)
Chapter 10 - eZ430X
52