Title: IO and Peripherals
1I/O and Peripherals
Key Concepts and Terms
- control and status registers
- ports
- bitmasking
- bit manipulation
- device drivers
- memory mapped I/O
- bandwidth
- synchronization
- polling
- busy waiting
- serial and parallel interfaces
- analog and digital signals
- analog to digital conversion
- sampling frequency
- active high, active low
- edge-triggered
- level triggered
- timing diagram
2I/O and UM003
- I/O
- Ports
- Device Drivers and Interfaces
- Control and Status Registers
- Synchronization Techniques
- Signal Processing
- Signal Types
- Sampling
- A/D Conversion
3UM003 Robot (Motor) Controller
encoder count (est pos)
AtMega (PD Control)
Motor
Encoder
user command (ref pos)
Serial Comm
PWM signal (motor control)
task goal (ref pos)
Visual System
4UM003 Motor Control
encoder count (est pos)
/3
/3
Motor
dir
Ch. A
Ch. B
PWM
dir
Motor
PWM
Ch. A
Ch. B
dir
PWM
Motor
Ch. A
Ch. B
5(No Transcript)
6Control and Status Registers
- Initialization
- direction
- function
- synchronization (when to read or write)
- Interaction with peripheral
- read or write value
7PORTS
- Atmega datasheet p. 365
- PORTA 1B (3B)
- DDRA 1A (3A)
- PINA 19 (39)
- winAVR io128.h (IO for atmega128)
- / Input Pins, Port A /
- define PINA _SFR_IO8(0x19)
- / Data Direction Register, Port A /
- define DDRA _SFR_IO8(0x1A)
- / Data Register, Port A /
- define PORTA _SFR_IO8(0x1B)
- winAVR sfr_defs.h (special function register
defs) - define _SFR_IO8(io_addr) ((io_addr)
__SFR_OFFSET)
8Read / Write to Ports
- Memory-Mapped I/O
- Port-Mapped I/O
- DMA
out(PORTA, 0x33) or PORTA 0x33
9Bit Manipulation
10Control Status Register Pins/Ports
iom128.h / Port B Data Register - PORTB
/ define PB7 7 define PB6
6 set bit7, bit6, bit0 hi (equivalent to
0xC2) DDRB (1ltltPB7) (1ltltPB6) (1ltltPB0)
read 4 most significant bits data PINA 0xF0
11UM003 Motor Control
encoder count (est pos)
/3
/3
Motor
dir
Ch. A
Ch. B
PWM
dir
Motor
PWM
Ch. A
Ch. B
dir
PWM
Motor
Ch. A
Ch. B
12Decoder (motor position)
13Reading Decoder on UM003
- int32_t read_decoder_U7()
-
- // select the appropriate decoder (U6/U7/U8)
- PORTG 0x
- //need to wait for a moment to ensure the demux
has switched - delay_ms(10)
- //read the data from the decoder and do
something with it - int8_t data PINC
-
-
- //now to reset the encoder
- PORTG 0x
- delay_ms(10)
- //and lastly, turn the encoder back on (stop
reset) - PORTG 0x00
-
14Device Driver
- Goal Hide the hardware completely.
- ONLY module to read/write control status
registers directly. - BUT, in embedded systems, little distinction
between - application software, OS, and device drivers
- The making of a device driver
- Create interface to registers (.h file)
- Define variables to track status.
- Routine to initialize hardware.
- API for users
- Interrupt service routines.
- First use polling to get driver working.
Writing Windows CE Device Drivers Principle to
Practice, Linux device driver design
embedded.com
15Relating to the outside world
- 4 categories of interfaces
- parallel (digital, simultaneous bits at a time)
- serial (digital, one bit at a time)
- analog (voltage, continuum)
- time (analog period, frequency, )
- Types of Signals (signal processing world)
- continuous-time (analog)
- discrete-time (sampled analog signal or
inherently discrete signal) - continuous-value
- discrete-value
- random (noise)
16Synchronization (Timing the Communication)
CPU State Transition
EMS Figs 3.1 and 3.2 p. 143
17Synchronization (Timing the Communication)
EMS Figs 3.3 and 3.4 p. 144
18Latency
- Latency
- Real-Time Systems
- Throughput (Bandwidth)
19Synchronization Techniques(Im just waiting on a
friend)
- blind cycle open door at precisely 204 pm
- busy wait (gadfly) stand at the door
- interrupt keep busy until doorbell rings
- periodic polling doorbell broke, check every 5
minutes - DMA friend lets herself in
20Blind Cycle (Input)
char Input (void) PULSE Timer_Wait(5) retur
n(PORT)
Figs 3.5 and 3.6 from EMS
21Blind Cycle (Output)
void Output (unsigned char LETTER)
PORTLETTER Pulse() Timer_MsWait(100)
Figs 3.5 and 3.6 from EMS
22Busy Wait (Gadfly)
/ use spinlock to wait for i to change. /
static void f1() while (i0) / do
nothing - just keep checking over and over /
printf("i's value has changed to d.\n", i)
return NULL
Figs 3.7 from EMS
23Interrupt (IN)
24Interrupt (OUT)
25Periodic Polling
do / play games, read, / / poll to
see if ready / status areWeThereYet()
while (status NO)
26Motivations for Various Synchronization Techniques
EMS Table 4.1 p. 193
27Peripherals and I/O
- Ports
- Device Drivers and Interfaces
- Control and Status Registers
- Synchronization
28Peripherals and I/O
- I/O
- Ports
- Device Drivers and Interfaces
- Control and Status Registers
- Synchronization
- Signal Processing
- Signal Types
- Sampling
- A/D Conversion
29Input (Sensors) and Output (Actuators)
- Force
- Position
- Motion (Acceleration, Velocity)
- Temperature, Humidity
- Chemical
- Sound
- Shape / Texture / Color
- Motors (DC, Stepper, Servo)
- LCD Display
- LEDs
- Alarm
- Microwaves
30Signals
- Signal
- a time varying physical phenomenon which is
intended to convey information.
31Relating to the outside world
- 4 categories of interfaces
- parallel (digital, simultaneous bits at a time)
- serial (digital, one bit at a time)
- analog (voltage, continuum)
- time (analog period, frequency, )
- Types of Signals (signal processing world)
- continuous-time (analog)
- discrete-time (sampled analog signal or
inherently discrete signal) - continuous-value
- discrete-value
- random (noise)
32Types of Signals
SS Fig. 1.3-1.5 p. 3
33Computer ScienceThe Art of Compromise (or The
Art of Abstraction)
Accuracy
Space
Time
34Sampling Methods
SS Fig 7.1 p. 493
35What computers understand
SS Fig 7.2 p. 493
36Analog to Digital Conversion (ADC)
- continuous-time, continuous-value
- ? discrete-value, continuous-time
- Using the process of
- Sampling
- Quantization
- Encoding
37ADC Process
SS Fig. 1.6 p. 4
38Sampling
- fs Sampling Frequency
- Ts Sampling Period (time between samples)
39Quantization
- if n is the word length of the ADC
- then
- quantization noise
SS Fig. 7.4 p. 494
40ADC Process
SS Fig. 1.6 p. 4
41Encode
SS Fig. 1.8 p. 5
42ADC Process
SS Fig. 1.6 p. 4
43Sinusoidal Signals
RED 20sin(2pi50t) BLUE 40sin(2pi50t)
RED 40sin(2pi25t) BLUE 40sin(2pi50t)
44Linear Combination of Sinusoids(Fourier Series)
SS Fig. 4.4 p. 211
45Sampling a Sinusoid(How often, is often enough?)
- Shannons Sampling Theorem
- If sampled at a rate more than twice the highest
frequency (of the component sinusoids) - it can be exactly reconstructed.
- fm Nyquist Frequency highest frequency
- 2fm Nyquist Rate
46Sampling a Sinusoid(How often, is often enough?)
47Sampling a Sinusoid(How often, is often enough?)
SS Figs 7.36, 7.37, 7.38
48Sampling a Sinusoid(How often, is often enough?)
SS Figs. 7.39, 7.41 p. 515
49Sampling a Sinusoid(How often, is often enough?)
RED 40sin(2pi25t) BLUE
40sin(2pi50t) BLACK BLUE RED
50Sampling a Sinusoid(How often, is often enough?)
RTS Fig. 1.2 p. 4
51Signal Processing (sub-basics)
- Signal Types
- Sampling
- A/D Conversion
52I/O and Peripherals
Key Concepts and Terms
- control and status registers
- ports
- bitmasking
- bit manipulation
- device drivers
- memory mapped I/O
- bandwidth
- synchronization
- polling
- busy waiting
- serial and parallel interfaces
- analog and digital signals
- analog to digital conversion
- sampling frequency
- active high, active low
- edge-triggered
- level triggered
- timing diagram