Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X...

52
Chapter 10 – eZ430X +

Transcript of Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X...

Page 1: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

Chapter 10 – eZ430X

+

Page 2: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 2

Topics to Cover…

MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass Filter Headers Jumpers Simon Lab Coding Assembler

Page 3: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 3

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

Home environment Air conditioning Control unit Thermostat Boiler control Shutter control Irrigation system White goods (Washing machine,..)

Misc Smart card reader Taxi meter Smart Batteries

Utility Metering Gas Meter Water Meter Heat Volume Counter Heat Cost Allocation Electricity Meter Meter reading system (RF)

Sports equipment Altimeter Bike computer Diving watches

Security Glass break sensors Door control Smoke/fire/gas detectors

MSP430 Typical ApplicationsMSP430F2274

Page 4: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 4

MSP430 RoadmapMSP430F2274

Page 5: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 5

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!

MSP430F2274

Page 6: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 6

MSP430F2274MSP430F2274

Page 7: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 7

eZ430X Development Board

Servos

Thermistor

Potentiometer

LEDsPush ButtonsSpeaker

Battery Power

ConfigurationStakes

MSP430F2274

USB Programmer Ferrite RAM

Accelerometer

LCD

eZ430X Development Board

Transponder

Page 8: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 8

eZ430X Development BoardeZ430X Development Board

Page 9: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 9

Computrol FacilitieseZ430X Development Board

Page 10: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 10

Printed Circuit BoardseZ430X Development Board

Page 11: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 11

Apply Solder PasteeZ430X Development Board

Page 12: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 12

Robots Place PartseZ430X Development Board

Page 13: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 13

Discrete Parts AddedeZ430X Development Board

Page 14: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 14

Flow SolderedeZ430X Development Board

Page 15: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 15

276 Solder BatheZ430X Development Board

Page 16: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 16

Final InspectioneZ430X Development Board

Page 17: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 17

Peripherals

A/D Converter (ADC10) Operational Amps (OA0-3) (Not covered) Ports (P1-P4) Power Module

Digitally Controlled Oscillator (DCO) Very Low Frequency Oscillator (VLO)

Timers A/B USCI A/B

USART – Universal Serial Asynchronous Rx/Tx SPI – Serial Peripheral Interface i2c – Inter-Integrated Circuit

Watchdog+

Peripherals

Page 18: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 18

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

Peripherals

Page 19: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 19

Digital I/O

Independently programmable individual I/Os

• 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

01234567

Input Register PxIN

Output Register PxOUT

Direction Register PxDIR

Interrupt Flag Register PxIFG

Interrupt Enable Register PxIE

Interrupt Edge Select Register PxIES

Function Select Register PxSEL

Port1

Port2

Port3

Port4

yes yes

yes no

yes no

yes no

yesyes

yesyes

yesyes

Peripherals

Page 20: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 20

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

Peripherals

Page 21: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 21

USART Serial Port

The Universal Synchronous/Asynchronous Receive/Transmitperipheral interface supportstwo serial modes with one hardware module

• UART

• SPI (Synchronous Peripheral Interface)

• I2C (Inter-Integrated Circuit)

• Double-buffered

• Baud-rate generator

Peripherals

Page 22: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 22

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) Master provides clock

Start condition

Slaveacknowledgment

Read SDA Write SDA SDA stable SDA may change

Stopcondition

Page 23: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 23

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

Page 24: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 24

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)

Peripheral Devices

Page 25: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 25

Switches

Switches P2.0-3 Internal pull-ups Require debouncing

Peripheral Devices

Page 26: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 26

LED’s

LED’s P2.0-1, P3.3, P4.6 Use PWM for brightness 0 = OFF, 1 = ON

Peripheral Devices

Page 27: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 27

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.

Peripheral Devices

Page 28: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 28

LCD

LCD - 100 x 160 pixels display

X (0-159)

Y (

0-9

9)

Page 10

Page 9

Page 8

Page 7

Page 6

Page 5

Page 4

Page 3

Page 2

Page 1

Page 0

Page 12

Page 11

Page 13

Peripheral Devices

Page 29: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 29

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, ...);

Peripheral Devices

Page 30: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 30

FRAM

FRAM Ferroelectric Non-

volatile RAM 8192 x 8 bits 45 year retention i2c serial bus Unlimited R/W

cycles

Peripheral Devices

Page 12

99 3

M(1920) M(1921) M(1922) M(1923) M(1924) M(2079)98 297 196 0

Page 11

95 7

M(1760) M(1761) M(1762) M(1763) M(1764) M(1919)

94 693 592 491 390 289 188 0

24-87

Page 2

23 7

M(320) M(321) M(322) M(323) M(324) M(479)

22 621 520 419 318 217 116 0

Page 1

15 7

M(160) M(161) M(162) M(163) M(164) M(319)

14 613 512 411 310 29 18 0

Page 0

7 7

M(0) M(1) M(2) M(3) M(4) M(159)

6 65 54 43 32 21 10 0

0 1 2 3 4 159

X

Y

Page 31: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 31

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);

Peripheral Devices

Page 32: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 32

LCD Backlight

LCD Backlight P4.2 / TA2 (Jumper F) Use PWM for dimming

Peripheral Devices

// configure Timer_A: SMCLK, /1, up/down mode#define BACKLIGHT_FREQUENCY 4#define BL_INCREMENT 1

TAR = 0; // reset TARTACTL = TASSEL_2+ID_0+MC_1;TACCTL2 = OUTMOD_3; // output mode = set/resetTACCR0 = BACKLIGHT_FREQUENCY; // set frequencyTACCR2 = 1; // set duty cycleP2SEL |= 0x10; // select TA2

Page 33: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 33

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)

Peripheral Devices

int ADC_read(int channel){

ADC10CTL0 = SREF0 + ADC10SHT_2 + ADC10ON + REFON + REF2_5V;P4DIR &= ~0x08; // P4.3P4SEL |= 0x08; // A12ADC10AE0 |= 0x00;ADC10AE1 = 0x10; // A12 ADC10 function and enableADC10CTL1 = channel << 12;ADC10CTL0 |= ENC + ADC10SC; // sampling and conversion startwhile (!(ADC10CTL0 & ADC10IFG)); // wait until conversionreturn ADC10MEM;

} // end ADC_sample

Page 34: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 34

Thermistor

Thermistor 10k thermistor Non-linear resistance ADC10 Channels:

10 = internal temperature 15 = thermistor (Jumper C1)

Peripheral Devices

int ADC_read(int channel){

ADC10CTL0 = SREF0 + ADC10SHT_2 + ADC10ON + REFON + REF2_5V;P4DIR &= ~0x40; // A15 = P4.6P4SEL |= 0x40;ADC10AE0 |= 0x00;ADC10AE1 = 0x80; // A15 ADC10 function and enableADC10CTL1 = channel << 12;ADC10CTL0 |= ENC + ADC10SC; // sampling and conversion startwhile (!(ADC10CTL0 & ADC10IFG)); // wait until conversionreturn ADC10MEM;

} // end ADC_sample

Thermistor Values

0

100

200

300

400

500

600

700

800

900

1000

32 50 68 86 104

122

140

158

176

194

212

Temperature

AD

C V

alu

e

Page 35: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 35

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

Peripheral Devices

Page 36: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 36

Sonar Transponder

MaxBotix EZ0/1 Sonar Transponder Sonar range from 6 to 254 inches (1 inch resolution) Analog/serial digital output

Peripheral Devices

Page 37: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 37

Low Pass Filter

Digital equivalent of an analog low pass RC filter

Filters

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;

}

Page 38: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 38

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

Headers

Page 39: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 39

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

Jumpers

Page 40: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 40

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."

Page 41: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 41

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

Coding Assembler

Page 42: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 42

Three Basic Constructs

Task

Subtask 1

Subtask 2Subtask 1 Subtask 2

Testcondition

Subtask

Testcondition

Sequential Conditional Iterative

True

True

FalseFalse

Coding Assembler

Page 43: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 43

if-then-else Translation

if-then-else

if (buzzerON == 1){ pulse_buzzer(); turn_on_LED();}else{ turn_off_LED();}

cmp.w #1,&buzzerON ; jne myElse ; xor.b #0x20,&P4OUT ; bis.b #0x02,&P1OUT ; jmp myNext ; myElse: ; bic.b #0x02,&P1OUT ; ;myNext: ;

Coding Assembler

Page 44: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 44

while Translation

while loop…

#define TRUE 1

while (TRUE){ LED_ON(); delay(); LED_OFF(); delay();}

;while_loop: ; bis.w #Z,SR ; jnz while_done ; call #LED_ON ; call #delay ; call #LED_OFF ; call #delay ; jmp while_loop ;

while_done: ;

Coding Assembler

Page 45: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 45

switch/case Translation

switch/case

switch (myByte){ case DOT: do_dot(); break;

case DASH: do_dash(); break;

default:}

cmp.w #DOT,&myByte ; jne sw_01 ; call #do_dot ; jmp sw_end ;

sw_01: cmp.w #DASH,&myByte ; jne sw_end ; call #do_dash ; jmp sw_end ; ;sw_end: ;

Coding Assembler

Page 46: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 46

for-loop Translation

for-loop

int i;

for(i=0; i<10; i++){

do_dot(); delay(); do_dash(); delay();

}

.bss i,2 ;

mov.w #0,&i ;fl_ck: cmp.w #10,&i ; jge for_done ; call #do_dot ; call #delay ; call #do_dash ; call #delay ; add.w #1,&i ; jmp fl_ck ;

for_done: ;

Coding Assembler

Page 47: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 47

Page 48: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 48

TxCCTLx Control Register

Bit Description

15-8 Capture Configuration (Set to 0)

7-5 OUTMODx Output mode: 0 0 0 bit OUT0 0 1 Set0 1 0 Toggle/Reset0 1 1 Set / Reset1 0 0 Toggle1 0 1 Reset1 1 0 Toggle / Set1 1 1 Reset / Set

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

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Capture Configuration OUTMODx CCIE CCI OUT COV CCIFG

Pulse Width Modulation (H/W)

Page 49: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 49

Timer_A/B Output modesPulse Width Modulation (H/W)

Page 50: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 50

Timer_B PWM Example

Use PWM w/Timer B for transducer tones:

; reset TimerBclr.w &TBR

; SMCLK, /1, up mode (no interrupts)mov.w #TBSSEL_2+ID_0+MC_1,&TBCTL

; TB2 output mode = set/resetmov.w #OUTMOD_3,&TBCCTL2

; load tone (frequency)mov.w &DO,&TBCCR0

; load volume (duty cycle)mov.w #DO/2,&TBCCR2

Pulse Width Modulation (H/W)

Page 51: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 51

First, eliminate a lot of code!!

Step 12a: Use Timer Output PWM

.bss duty_cycle_high,2 ; high part of cycle .bss duty_cycle_low,2 ; low part of cycle .bss duty_cycle_toggle,1 ; duty cycle flag

mov.w #DO/2,&TBCCR0 ; start clock bis.w #TBIE,&TBCTL ; enable timer B interrupts mov.w #DO/2,&duty_cycle_high ; set duty cycles mov.w #DO/2,&duty_cycle_low

; << adjust volume here >>; rra.w r4 ; 50% duty cycle; mov.w r4,r5 mov.b volume,r5 ; get volume mov.w duty(r5),r5 ; r5 = duty cycle sub.w r5,r4 ; subtract from frequency cmp.w #0,r5 ; turn off? jne WD04 ; n mov.w #0,r4 ; y, high=low=0

WD04: mov.w r4,&TBCCR0 ; start clock (if necessary) mov.w r4,&duty_cycle_high ; set high duty cycle mov.w r5,&duty_cycle_low ; set low duty cycle

TB_isr: ; timer B ISR bic.w #TBIFG,&TBCTL ; acknowledge interrupt xor.b #0x20,&P4OUT ; pulse buzzer xor.b #1,&duty_cycle_toggle ; high? jeq TB02 ; n mov.w &duty_cycle_high,&TBCCR0 ; y, set high duty cycle jmp TB04

TB02: mov.w &duty_cycle_low,&TBCCR0 ; set low duty cycle

TB04: reti ; return from interrupt

.sect ".int12" ; timer B section .word TB_isr ; timer B isr

Pulse Width Modulation (H/W)

Page 52: Chapter 10 – eZ430X +. BYU CS/ECEn 124Chapter 10 - eZ430X2 Topics to Cover… MSPF2274 eZ430X Development Board Peripherals Peripheral Devices Low Pass.

BYU CS/ECEn 124 Chapter 10 - eZ430X 52

Put transducer (P4.5) as secondary function

Change WD ISR to just put the duty cycle in TBCCR2

Step 12b: Use Timer Output PWM

bis.b #0x20,&P4SEL ; P4.5 transducer output mov.w #OUTMOD_3,&TBCCTL2 ; output mode = set/reset mov.w #DO/2,&TBCCR2 ; use TBCCR2 as volume

; << adjust timer b tone here >> push r5 ; save r5 add.w r4,r4 ; (word index) mov.w scale(r4),r4 ; r4 = tone (frequency) mov.w r4,&TBCCR0 ; start clock (if necessary) mov.b volume,r5 ; get volume add.w r5,r5 ; (word index) mov.w duty(r5),r5 ; r5 = duty cycle mov.w r5,&TBCCR2 ; start clock (if necessary) pop r5

Pulse Width Modulation (H/W)