Sei sulla pagina 1di 2

Chapter 4: Standard Single-Purpose Processors: Peripherals Embedded System Design 39 C O N T R O L _ W O R K = 0 x 1 B ; / / 8 - b i t , o n e l i n e , a n d 5 x 1 0 f o n t // (00011011)EnableLCD(45); // toggle enable and delay } 4.

9 Given a 120-step stepper motor with its own controller, write a C function Rotate (int degrees) , which, given the desired rotation amount in degrees (between 0 and 360),p u l s e s a m i c r o c o n t r o l l e r s o u t p u t p o r t t h e c o r r e c t n u m b e r o f t i m e s t o a c h i e v e t h e desired rotation.The motor takes 120 steps to rotate 360 degrees so the degrees per step = 360/120 = 3. Rotate( int degrees ){c o n s t i n t D P S = 3 / / d e g r e e s p e r s t e p i n t i f o r ( i = 0 ; i < ( d e g r e e s / D P S ) ; i + + ) { o u t p o r t = 0 delay()o u t p o r t = 1 }} 4.10 Modify only the main function in Figure 4.12 to cause a 240-step stepper motor torotate forward 60 degrees followed by a backward rotation of 33 degrees. This steppermotor uses the same input sequence as the example for each step. In other words, do notchange the lookup table. / / 3 6 0 / 2 4 0 = 1 . 5 d e g r e e s p e r s t e p while(1){/ / 6 0 d e g r e e s / 1 . 5 d e g r e e s p e r s t e p = 4 0 s t e p s move(1,40); // 1 = forward/ / 3 3 / 1 . 5 = 2 2 s t e p s move(0,22); // 0 = backward} 4.11 Extend the ratio and resolution equations of analog-to-digital conversion to any voltagerange between V min to V max rather than 0 to V max .ratio: (e Vmin) / (Vmax Vmin) = d / (2^n 1)resolution: (Vmax Vmin) / (2^n 1)4.12 Given an analog output signal whose voltage should range from 0 to 10 V, and an 8-bitdigital encoding, provide the encodings for the following desired voltages: (a) 0 V, (b)1 V, (c) 5.33 V, (d) 10 V, (e) What is the resolution of our conversion?n = 8, 2 n 1 = 255Vmin = 0, Vmax = 10

Chapter 4: Standard Single-Purpose Processors: Peripherals 40 Embedded System Design (a) 0V0 / 10 = d / 255d = 000000000(b) 1V1 / 10 = d / 255d = 25.5 2500011001(c) 5.33V5.33 / 10 = d / 255d = 135.9 13610001000(d) 10V10 / 10 = d / 255d = 25511111111(e) What is the resolution of our conversion?10 0 / 255 = 0.039V4.13 Given an analog input signal whose voltage ranges from 0 to 5 V, and an 8-bit digitale n c o d i n g , c a l c u l a t e t h e c o r r e c t e n c o d i n g f o r 3 . 5 V , a n d t h e n t r a c e t h e successive-approximation approach (i.e., list all the guessed encodings in the correctorder) to find the correct encoding.3.5 / 5 = d / 255d = 178.5 179101100113 . 5 > ( 5 + 0 ) 1 0 0 0 0 0 0 0 3 . 5 < ( 5 + 2 . 5 ) 1 0 0 0 0 0 0 0 3 . 5 > ( 3 . 7 5 + 2 . 5 ) 1 0 1 0 0 0 0 0 3.5 > (3.75 + 3.125) 101100003.5 < (3.75 + 3 . 4 3 7 ) 1 0 1 1 0 0 0 0 3.5 < (3.594 + 3.437) 101100003.5 > (3.515 + 3.437) 101100103.5 > (3.515 + 3.476) 10110011

Chapter 4: Standard Single-Purpose Processors: Peripherals Embedded System Design 41 4.14 Given an analog input signal whose voltage ranges from 5 to 5 V, and a 8-bit digitale n c o d i n g , c a l c u l a t e t h e c o r r e c t e n c o d i n g 1 . 2 V , a n d t h e n t r a c e t h e s u c c e s s i v e - approximation approach to find the correct encoding.(1.2 (-5)) / (5 (-5)) = d / 255.62 = d / 255d = 158.1 158100111101 . 2 > ( 5 + - 5 ) 1 0 0 0 0 0 0 0 1 . 2 < ( 5 + 0 ) 1 0 0 0 0 0 0 0 1 . 2 < ( 2 . 5 + 0 ) 1 0 0 0 0 0 0 0 1 . 2 > ( 1 . 2 5 + 0 ) 1 0 0 1 0 0 0 0 1 . 2 > ( 1 . 2 5 + 0 . 6 2 5 ) 1 0 0 1 1 0 0 0 1 . 2 > ( 1 . 2 5 + 0 . 9 3 7 5 ) 1 0 0 1 1 1 0 0 1 . 2 > ( 1 . 2 5 + 1 . 0 9 3 7 5 ) 1 0 0 1111 0 1.2 < (1.25 + 1 . 1 7 1 8 7 5 ) 1 0 0 1 1 1 1 0 4.15 Compute the memory needed in bytes to store a 4-bit digital encoding of a 3-secondanalog audio signal sampled every 10 milliseconds.3 s * (1000 ms / 1s) = 3000 ms3000ms / (10 ms / sample) = 300 samples3 0 0 s a m p l e s * 4 b i t s = 1 2 0 0 b i t s * ( 1 b y t e / 8 b i t s ) = 1 5 0 b y t e s

Potrebbero piacerti anche