july 18, 2008cosmos @ ucsd - r.a. de callafon short intro to micro processors and i/o functions of...

24
July 18, 2008 COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon Dynamic Systems & Control Group Center of Magnetic Recording Research UCSD, Dept. of MAE Email: [email protected] COSMOS LECTURE

Upload: lee-sanders

Post on 19-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Short Intro to Micro Processors and I/O functions of our

Kinetic Sculpture Control Box

Raymond de CallafonDynamic Systems & Control Group

Center of Magnetic Recording ResearchUCSD, Dept. of MAE

Email: [email protected]

COSMOS LECTURE

Page 2: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

2 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Introduction

Micro Processor: combination of Processor (for computing) Input/Output functionality RAM (Random Access Memory) ROM (Read Only Memory)

(FLASH or EPROM) Mostly “all on one chip”

Page 3: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

3 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

In this COSMOS cluster we are using a micro processor for: Process measurement data

Timing events (when a ball passes by) Count how many balls came by Compute what velocity was Display result on LCD screen Make a sound

Send out control signals Turn a servo motor Turn of/off a switch or actuator

Introduction

Page 4: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

4 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of a Micro Processor

Page 5: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

5 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of a Micro Processor

Functionality depends on “brand” (Intel, HP, MicroChip, Motorolla) Peripheral interface

General items in micro processor: Can be programmed! Arithmetic Functionality Timers Interface with Peripherals Digital In and Out signals Analog In signals Pulse Width Modulation Out

Page 6: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

6 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Micro Processor in your Kinetic Sculpture Box: Peripheral Interface Controller Micro Processor

Some details: PIC made by MicroChip Reduced Instruction

Set Computing (RISC) HARVARD memory

(separation betweenprogram and variables)

(Only) needs power + clock(oscillator) to operate

Page 7: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

7 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Arithmetic Functionality Adding, subtracting and multiplying integer

numbers Adding, subtracting and multiplying real numbers

via “emulation”: means a lot of computing time In general only fixed point precision, compared to

floating point precision Floating point computations: co-processor

needed…

Page 8: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

8 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Timers Timers increment and decrement on the basis of

clock (oscillator) Use to time events! Oscillator = clock and value can be retrieved and

stored in memory Example: speed sensors

Measure clock at first passing of sensor Measure clock at second passing of sensor Time = difference in timer Velocity = distance/time

Page 9: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

9 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Interface with Peripherals Write to the LCD screen Turn on/off certain LED’s (digital out signals)

Some example code of LCD writing:

LCD = variable defined in file VARIABLES

serout = command to write to a serial port

Page 10: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

10 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Help on programming: We use an friendly IDE

(Integrated DevelopmentEnvironment)

Pressing F1 will open help Look for command (serout) Read documentation

Many examples on COSMOSwebsite!

Page 11: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

11 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Digital I/O signals PIC microprocessor in box has over 30 connection

pins COSMOS controlbox has 3 digital input pins

DA, DB and DC Each pin can be programmed to be an Digital

Input or Digital Output Digital I/O:

Only 2 values: 0 and 1 0 corresponds to low voltage < 0.5 Volt 1 corresponds to high voltage > 3.8 Volt

Combining digital I/O data yields numbers!

Page 12: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

12 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Examples of use Digital I/O signals: Digital I/O signal to detect events

Position measurement of ball:When ball passes sensor, pin # becomes “low” or “high”

Velocity measurement of ball:Measure time (using timer) when ball passes two sensors

Digital /IO signal as numbers Consider 8 digital Input channels (on port D) with:

Combining them gives what (decimal) number?104643282021212021202020 86543210 D

Page 13: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

13 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Analog I/O signals COSMOS controlbox has 3 analog input pins

AD0, AD1 and AD2 Microprocessor converts analog input signal to a

number of bits number This process is called AD conversion (Analog to

Digital Conversion) Important parameters in AD conversion:

Number of bits or resolution (typically 8 bits) Speed of AD conversion

Page 14: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

14 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Examples of use Analog I/O signals: Analog I/O signal to measure “user input”

Position of a potentio meter (variable resistor) Varying voltage signal from a sensor

Resolution Consider a AD conversion that will convert a

signal between 0 and 5 Volt to an 8 bit number. What will be the resolution?

Volt resolution soies,possibilit 255 1- 0196.0255/528

Page 15: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

15 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Combination of I/O signals + computations:

Measurements & Actuation Physics experiments Move a servo motor

Detection To see if your kinetic sculpture is working properly Time events

Automation (most interesting part) Process certain events automatically! Process user input automatically!

Page 16: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

16 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Automation Principles of Automation are based on

Combining Measurement and Actuation Feedback (remember labtour to the control

laboratory)! Formats of Feedback

On/Off actuation Fuzzy actuation Continuous actuation

Page 17: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

17 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Functionality of Micro Processor

Microprocessor makes this active KS work:

measure ball velocity with optical sensor

actuate stepper

motor

Page 18: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

18 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Programming a Micro Processor

Programming via Assembly code (RISC)

Very hard to understand (at first) Code hard to maintain

C code (high level) A bit easier to understand Easier for maintenance

P basic or Q basic (based on BASIC like language) Easy to understand Not so easy for large projects

Page 19: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

19 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Programming a Micro Processor

Write your code in basic via BasicMicro IDE

Compile code and see if there any errors

Download (burn flash memory) onto microprocessor

Test and debug code (can also be done before downloading)

Page 20: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

20 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Programming a Micro Processor

Main ingredients in code Definition of constants (I/O pins and memory)

Definition of variables + typebit 0 to 1byte 0 to 255sbyte -127 to 128word 0 to 65535sword -32767 to 32768long -2147483647 to 2147483648float (*not used in this course*)

comments

name type

Page 21: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

21 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Programming a Micro Processor

Main ingredients in code If statements:

Initializations & computations:

Page 22: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

22 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Programming a Micro Processor

Main ingredients in code Setting up timers with interrupt:

Define interrupt function:

Page 23: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

23 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Simulation of Micro Processor

Simulation in Working Model: actuate catching!

Change force, depending on measurement of velocity

(more in next lecture on dynamics)

Page 24: July 18, 2008COSMOS @ UCSD - R.A. de Callafon Short Intro to Micro Processors and I/O functions of our Kinetic Sculpture Control Box Raymond de Callafon

24 July 18, 2008COSMOS @ UCSD - R.A. de Callafon

Programming a Micro Processor

example code(s) explained by Alex Simpkins

Example of BAS code

Tutorial on how to write a program