ece 3561 - lecture 1 1 l15 –i/o part ii department of electrical and computer engineering the ohio...

21
ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Upload: ralph-webb

Post on 19-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

ECE 3561 - Lecture 1 1

L15 –I/O Part II

Department of Electrical and Computer EngineeringThe Ohio State University

ECE 2560

Page 2: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Digital I/O on the 430

Digital input and outputModify the routine to vary the time on/off of

each led in oscillationAllow toggle on input from push button

ECE 3561 - Lecture 1 2

Page 3: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

There is a MSP 430 wiki page

There is a Launch Pad wiki pagehttp://processors.wiki.ti.com/index.php/

MSP430_LaunchPad_(MSP-EXP430G2)

ECE 3561 - Lecture 1 3

Page 4: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Modifying the blink rate

We can create two memory locations that modify the blink rate of the LEDs.

This will be done in real time in class.

ECE 3561 - Lecture 1 4

Page 5: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Digital input

The launch pad has one input available to the user. It is at P1.3 It is a momentary push button switch.

The code can be modified to turn the light on when this switch is pressed.

Note: There is another momentary push button switch – it is a hard reset.

ECE 3561 - Lecture 1 5

Page 6: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Configure the port

The port configuration must be modified to set that pin as an input.

It is pin 3 of Port 1Need to set the value in the P1DIR to xxxx 0xxx To read the value on this switch.

When combined with output configuration for the LEDs it give a value of 1xxx 0x1x to be written to P1DIR

ECE 3561 - Lecture 1 6

Page 7: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

The code for setting it up

Setting the port to read the input switch.Set unused pins to output

mov.b #0xF7&P1DIR ;dir register mov.b #0x00,&P1IE ;disable int mov.b #0x00,&P1SEL ;all pins I/O mov.b #0x00,&P1OUT ;LEDs off mov.b P1IN,R6 ;read input mov.b P1IN,R6

ECE 3561 - Lecture 1 7

Page 8: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Consider code in CCS

For some reason the switch does not seemed not to work. But it should.

Then it was realizedThe DIRection register should be 1111 0111 or $F7 not $FB This is a note slide to show how easy it is

to make minor errors that result in errors.Time to revisit and just work with the bit

instruction.

ECE 3561 - Lecture 1 8

Page 9: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

General scheme to configure

To configure – Two alternativesConfigure all bits in the control registerConfigure only the bit you desire to set

ECE 3561 - Lecture 1 9

Page 10: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

The flow of control

The diagram show the relationships

ECE 3561 - Lecture 1 10

Page 11: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Using diagram

The steps to configure pull up First set bit in SEL register to

0 – Digital I/O The set DIR register to 0 –

Input From here you configure if

you want interrupts (later) – 0 disable for now

Also, PxREN – internal pull-up 0 – disabled 1 – enable PxOUT 0 for a pull down 1 for a pull up

ECE 3561 - Lecture 1 11

Page 12: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

What is a pull up

Port pin can have an internal pull upPossible switch circuits

SPDT –Single Pole Double Throw – issue here is that during transition the input is floating.

Often see these as DPDT and used in automotive window up/down switch.

ECE 3561 - Lecture 1 12

Page 13: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Switch on input

Use a SPST – Single pole single throwHave a connection to Vdd through a limiting

resistor.When switch is open Input is at

VddWhen switch is closed Input is drawn to ground.Limiting resistor limits current to a low value

when closed as there is a path Vdd to GND

ECE 3561 - Lecture 1 13

Page 14: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Typical values for pull up

Typical values5V system so Vdd = 5VOften a pullup resistor of 290Ω or 330Ω is

used.So current is 0.017 Amp or 17 mA (15mA)

In 3.3V system – 11 mA (10 mA)

When switch is closed this is the current that flows through the resistor.

ECE 3561 - Lecture 1 14

Page 15: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

The code to just set that pin

Use bit set and bit clear instruction Will do this for Port 1 pin 3 which is the

pushbutton switch – a SPST momentary bic.b #0x08,&P1SEL ;I/O bic.b #0x08,&P1DIR ;Output bis.b #0x08,,&P1REN ;Resistor bis.b #0x08,&P1OUT ;Pullup bic.b #0x08,&P1IE ;Disable mov.b &P1IN,R6 ;get value mov.b &P1IN,R6 ;get value mov.b &P1IN,R6 ;get value

ECE 3561 - Lecture 1 15

Page 16: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Could be done using bytes

This also could have been set using the mov.b instruction. The first attempt with the byte mov instruction failed due to the bit being set wrong in P1OUT so the resistor was a pull down.

ECE 3561 - Lecture 1 16

Page 17: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Good code for bytes

mov.b #0x00,&P1SEL ;set I/O mov.b #0xF7,&P1DIR ;in/out set mov.b #0x08,&P1REN ;res enable mov.b #0x08,&P1OUT ;pullup mov.b #0x00,&P1IE ;disable int mov #P1IN,R6 ;read port to R6 mov.b @R6,R7 ;get val mov.b @R6,R7 mov.b @R6,R7

Can see this work in demo

ECE 3561 - Lecture 1 17

Page 18: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Now change light blink code

Set up code in iodemo2 for One loop has fast blinking lights-stitch pressed –

value is 1 Other has slower blinking lights – switch released –

value is 0 How to tell?

Use bit – bit test instruction bit #0x08,&P1IN Does a logical and of src,dst so if = 0, switch not

pressed, if =1 switch pressed Use JEQ instruction – if Z=0 no jump and code for

slower

ECE 3561 - Lecture 1 18

Page 19: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

And to watch a code demo

Note the code running on the 430

The code for iodemo and iodemo2 is on the webpage.

Play with iodemo2 to add code such the blink rate is one rate when the switch is pressed and another when released.

ECE 3561 - Lecture 1 19

Page 20: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

Now we can modify

We can now modify our led program to change the blinking frequency when we press the switch.

File iodemo.asm has core of the code.And a modification is in iodemo2.asm

ECE 3561 - Lecture 1 20

Page 21: ECE 3561 - Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560

ECE 3561 - Lecture 1 21

Summary - Assignment

Try out the codeAdd an inner loop to lengthen the time

for each individual light.

No new assignment.