Docsity

ECE332 Week 9: Timers, Counters, UARTs, PWM, LCD Controllers, and Keypad Decoders, Study notes of Microprocessors

Partial preview of the text

Download ECE332 Week 9: Timers, Counters, UARTs, PWM, LCD Controllers, and Keypad Decoders and more Study notes Microprocessors in PDF only on Docsity!

1

ECE332, Week 9 October 24, 2007

2

Topics  Timers, Counters, Watchdog Timers

   UARTPulse Width Modulators (PWM)LCD Controllers

   KeypardAnalog to Digital, Digital to Analog convertersReal-time Clocks Decoder

3

Accurate?  How accurate delay() { is this delay loop?

 What^ }^ int^ for( happen when you have a different system clock?^ i;i=0;i<1000000;i++) {}

   From 8 MHz to 4 MHzWill the delay loop criteria?During this delay loop, the or timing loop still have the same general processor is doing nothing timing

 By the way, what is the source of system clock?^ useful!

4

^ Single-Purpose Processors Performs specific computation task  Conventional processor versus soft-core processor

  Custom single-purpose processors  Standard  Designed for a unique task“Off-the-shelf single-purpose processors” -- pre-designed for a common task  ^ Conventional ^ a.k.a., peripherals, serial transmission (e.g. MAX 232)analog/digital conversions (8-bit, 10-bit, 12-bitThese chips will need to interface to general-purpose pins solutions …)  Programmable solutions  ^ Multi-chip solutionsMuch of these special purpose hardware is in FPGAHowever, some still required (a.k.a. what we do in lab) special chips, e.g. ADC

7

^ Other Timer Structures Interval timer  Indicates when desired time interval has passed

  Cascaded countersPrescaler^ We set terminal count to desired interval^ ^ Number of clock cycles = Desired time interval / Clock period  ^ PLL^ Divides clockIncreases range, decreases resolution

Top
Clk Prescaler^ Time with^ prescaler^ 16-bit up counter
Mode
Clk 16-bit up counter 16
Terminal count^ =^ Top^ Reset
Timer with a terminal count Cnt
Clk^ 16-bit up 16-bit up counter
counter^16 Top1^ Cnt
16/32-bit timer Cnt

8

Example  Reaction timer

 Watchdog timer^ Measures the time a^ or audio stimulus^ person to respond to a visual   Must reset timer every X time unit, else timer generates a signalCommon use: detect failure, self-reset

9

Serial Transmission Using  UART: Universal Asynchronous UARTs

Receiver Transmitter   Takes parallel data and transmits seriallyReceives serial data

and converts to parallel

1 0 0 1 1 0 1 1 embedded^ device
Sending UART^1 0 0 1 1 0 1 1 Receiving UART^1 0 0 1 1 0 1

   Parity: extra bit for simple error checkingStart bit, stop bitBaud rate  signal changes per second

 Voltage levels

10

UART Cont.  Transmitter and receiver must agree on the

following   the number of bits per characterthe speed or baud rate

   use or not use parityodd or even paritythe number of stop bits

 The most common configuration is   Eight bit characters, with one stop bit and no parity bitThus 10 bits are used to send a single character 8N

13

LCD Controller R/W E

microcontroller^8 DB7^ RS controller LCD–DB0^ communications^ bus^ #define^ { }^ while^ usleep^ LCD->^ LCD_write_data^ write_data((100);^ LCD->^ read_data^ =^ data;(data)^ &^ LCD_BUSY^ );^ \\
I I S S S R// DD///=CCL == 1 === (^10) w 1 01 d cci tcsuuhisuhrr (^) prissdflsooitsao rrtpyr (^) omm lsm arhooyoigvv (^) ifveesthessh (^) tm irfleiteg fntht (^) t CODEDDNNFFSLL (^) ==== == (^1010 10 5521) xx (^84) rr 17 - -oo 0 bbdwwii ttdosotsts R/L = 0 shift to left

RS 0000 R/ 0000 W DB 00007 D 0000 B 6 D 0000 B 5 D 0000 B 4 D 0001 B 3 D (^001) D B 2 D (^01) IC/B (^) D 1 D (^1) *SB B 0 DCRS sOepeleNetestsauc/c (^) iOrrrcsnfiuiFp (^) seart (^) ssFilcolo unondrr (^) ofism stao ptlrooll ahv (^) dsyoei (^) h,mds (^) iprifetler (^) ateduycir(ntsDipo (^) l)cnau, (^) y racsnuodrrs/ (^) oohrrome (^001 000 00 00 01) W (^1) D (^) LRI (^) TE DSN/AC (^) T (^) A RF /L ** ** OMS dWeiNsotrsp/viO (^) lteiaenF (^) ysct DFuelri^ rna(sfCatoeacs)r, (^) e,^ a adannanddtd (^) a^ s b (^) chllehiifnantrsgka (^) t^ dhcpi,tose (^) rspni tlufaoimoynnbt^ e(Br o)f

14

Keypad Decoder N1 N

N3 N4 M1 M2 M
M4 keypad controller key_code 4 k_pressed key_code

N=4, M=

15

Analog-to Digital Converters

proportionality
Vmax = 7.5V
0V
0.5V^ 1.0V^ 1.5V^ 2.0V^ 2.5V^ 3.0V
3.5V^ 4.0V^ 4.5V^ 5.0V^ 5.5V^ 6.0V
6.5V^ 7.0V
analog to digital
analog input (V)^10100 t1 t2 Digital output 1000 t3 0110 t4 0101 time
digital to analog
analog output (V)^10100 t1 Digital input 1000 t2 0110 t3 0101 t4 time

Resolution?

16

Digital-to-analog conversion using successive approximation Given an analog input signal whose voltage should range from 0 to 15 volts, and an 8-bit digital encoding, calculate the correct encoding for 5 volts. Then trace the successive-approximation approach to find the correct encoding. 5/15 = d= 85 d/(2 (^8) -1) Successive-approximation method 0 1 0 0 0 0 0 0

½ V(Vmaxmax = 7.5 volts. – Vmin) = 7.5 volts^ Encoding: 01010101

½ V½ V(7.5 + 0) = 3.75 voltsmin(7.5 + 3.75) = 5.63 voltsmax = 3.75 volts.= 5.63 volts^00 01 00 00 00 00 00
½ V(5.63 + 3.75) = 4.69 voltsmin = 4.69 volts. 0 1 0 1 0 0 0 0

½ V ½ V(5.63 + 4.69) = 5.16 voltsmax(5.16 + 4.69) = 4.93 voltsmin (^) = 4.93 volts.= 5.16 volts. (^00 11 00 11 00 01 00 ) ½ V ½(5.16 + 4.93) = 5.05 voltsmax(5.05 + 4.93) = 4.99 volts = 5.05 volts. 00 11 00 11 00 11 00 01