* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Document
Survey
Document related concepts
Control system wikipedia , lookup
Distributed control system wikipedia , lookup
Transmission line loudspeaker wikipedia , lookup
Opto-isolator wikipedia , lookup
Electronic engineering wikipedia , lookup
Brushed DC electric motor wikipedia , lookup
Fault tolerance wikipedia , lookup
Public address system wikipedia , lookup
Music technology (electronic and digital) wikipedia , lookup
Variable-frequency drive wikipedia , lookup
Analog-to-digital converter wikipedia , lookup
Time-to-digital converter wikipedia , lookup
Immunity-aware programming wikipedia , lookup
Transcript
Embedded Systems Design: A Unified Hardware/Software Introduction Chapter 4 Standard Single Purpose Processors: Peripherals 1 Stepper motor controller • Stepper motor: rotates fixed number of degrees when given a “step” signal – In contrast, DC motor just rotates when power applied, coasts to stop • Rotation achieved by applying specific voltage sequence to coils • Controller greatly simplifies this Sequence 1 2 3 4 5 A + + + A’ + + - B + + + Vd 1 16 A’ 2 MC3479P 15 A 3 14 4 13 5 12 Bias’/Set 6 11 Phase A’ Clk 7 10 CW’/CCW O|C 8 9 Full’/Half Step GND Red White Yellow Black Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis B’ + + Vm B B’ GND A A’ B B’ 2 Stepper Motor Operation Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 3 Stepper motor with controller (driver) /* main.c */ MC3479P Stepper Motor Driver 10 7 void main(void){ sbit clk=P1^1; sbit cw=P1^0; 8051 CW’/CCW CLK P1.0 P1.1 2 A’ B 15 3 A B’ 14 */turn the motor forward */ cw=0; /* set direction */ clk=0; /* pulse clock */ delay(); clk=1; void delay(void){ int i, j; for (i=0; i<1000; i++) for ( j=0; j<50; j++) i = i + 0; } /*turn the motor backwards */ cw=1; /* set direction */ clk=0; /* pulse clock */ delay(); clk=1; } Stepper Motor Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis The output pins on the stepper motor driver do not provide enough current to drive the stepper motor. To amplify the current, a buffer is needed. One possible implementation of the buffers is pictured to the left. Q1 is an MJE3055T NPN transistor and Q2 is an MJE2955T PNP transistor. A is connected to the 8051 microcontroller and B is connected to the stepper motor. +V 1K Q1 A B Q2 1K 4 Stepper motor without controller (driver) 8051 P2.4 /*main.c*/ sbit notA=P2^0; sbit isA=P2^1; sbit notB=P2^2; sbit isB=P2^3; sbit dir=P2^4; GND/ +V P2.3 P2.2 P2.1 P2.0 Stepper Motor A possible way to implement the buffers is located below. The 8051 alone cannot drive the stepper motor, so several transistors were added to increase the current going to the stepper motor. Q1 are MJE3055T NPN transistors and Q3 is an MJE2955T PNP transistor. A is connected to the 8051 microcontroller and B is connected to the stepper motor. +V 1K Q1 B +V 1K A Q2 330 Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis void delay(){ int a, b; for(a=0; a<5000; a++) for(b=0; b<10000; b++) a=a+0; } void move(int dir, int steps) { int y, z; /* clockwise movement */ if(dir == 1){ for(y=0; y<=steps; y++){ for(z=0; z<=19; z+4){ isA=lookup[z]; isB=lookup[z+1]; notA=lookup[z+2]; notB=lookup[z+3]; delay(); } } } /* counter clockwise movement */ if(dir==0){ for(y=0; y<=step; y++){ for(z=19; z>=0; z - 4){ isA=lookup[z]; isB=lookup[z-1]; notA=lookup[z -2]; notB=lookup[z-3]; delay( ); } } } } void main( ){ int z; int lookup[20] = { 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0 }; while(1){ /*move forward, 15 degrees (2 steps) */ move(1, 2); /* move backwards, 7.5 degrees (1step)*/ move(0, 1); } } 5 Data conversion Interface circuits Anti-aliasing filter Sample-and-hold (S/H) circuit Analog-to-digital converter (ADC) Digital-to-analog converter (DAC) Reconstruction filter Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 6 A/D and D/A transfer curves output Quantization error Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 7 5.0V 4.5V 4.0V 3.5V 3.0V 2.5V 2.0V 1.5V 1.0V 0.5V 0V 1111 1110 1101 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001 0000 4 4 3 3 analog output (V) Vmax = 7.5V 7.0V 6.5V 6.0V 5.5V analog input (V) A/D and D/A conversion 2 1 t1 0100 proportionality Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis t2 t3 time t4 1000 0110 0101 Digital output analog to digital 2 1 t1 t2 0100 t3 1000 0110 Digital input t4 time 0101 digital to analog 8 A/D Data Converters • Sigma Delta – High resolution, low-to-medium speed • Pipelined – Low-to-medium resolution, high speed • Flash – Low resolution, high speed • Successive approximation register (SAR) – Medium resolution, medium speed Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 9 SAR A/D Converter Start CLK EOC CONV Timing control SAH Vin Sample & hold Successive Approximation Register (SAR) + - Anti-aliased signal N bits VDAC Vref DAC N bits Register ¾ Vref CLK ½ Vref Vin Start ¼ Vref SAH CONV 0 Conversion time time bit 3=0 (MSB) bit 2=1 bit 1=0 bit 0=1 (LSB) Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis EOC 10 A/D 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/(28-1) d= 85 Encoding: 01010101 Successive-approximation method ½(Vmax – Vmin) = 7.5 volts Vmax = 7.5 volts. 0 0 0 0 0 0 0 0 ½(5.63 + 4.69) = 5.16 volts Vmax = 5.16 volts. 0 1 0 1 0 0 0 0 ½(7.5 + 0) = 3.75 volts Vmin = 3.75 volts. 0 1 0 0 0 0 0 0 ½(5.16 + 4.69) = 4.93 volts Vmin = 4.93 volts. 0 1 0 1 0 1 0 0 ½(7.5 + 3.75) = 5.63 volts Vmax = 5.63 volts 0 1 0 0 0 0 0 0 ½(5.16 + 4.93) = 5.05 volts Vmax = 5.05 volts. 0 1 0 1 0 1 0 0 ½(5.63 + 3.75) = 4.69 volts Vmin = 4.69 volts. 0 1 0 1 0 0 0 0 ½(5.05 + 4.93) = 4.99 volts 0 1 0 1 0 1 0 1 Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 11 Analog-to-digital converters Example: You have a 12 bit A/D and the range of the A/D is -1V to 1V. If the output of the A/D is: “001010111111” what analog voltage is at the input? We are trying to determine the analog input which is e. e/Vmax = d/(2n – 1) e/(1 – (-1)) = d/(2n – 1); note: the range is shifted by 1V d = “001010111111” = 703; n = 12; 2n = 4096; e/2 = 703/(4096 – 1) = 703/4095 = 0.1716722 e = 0.343345; shifted back e = -1 + 0.343345 = -0.656654 Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 12 Exercises 1. You have a 4-bit ADC which has an input range from 2V to 3V. It is sending the value “1110.” What is the analog input? Can you determine the tolerance (ie: accuracy) of you answer? 2. A 16 bit A/D with a 0 to 5V range has it’s 8 most significant bits connected to an 8 bit D/A with a range of 0 to 5V. If the input to the A/D is 3.700V what is the output of the D/A? Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 13 Interface with the microcontroller fs Anti-alias filter Dout mp ADC Sample and hold Vin fs/2 EOC Vr+ Start Vr- Driver Din mp I+ I- IV DAC EOC Vr+ Start Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 14 Real-time Clock (RTC) • Much like a digital wristwatch, keeps the time and date • Typically composed of a crystal-controlled oscillator, numerous cascaded counters and a battery backup • The crystal controlled oscillator generates a very consistent high frequency digital pulse that feeds the counters • Operation: – The 1st counter counts up to the oscillator frequency (Example: f = 32.768kHz, first counter counts 32768 or 215, corresponding to 1 sec) – At this point the 1st counter generates a pulse that feeds the 2nd counter that counts up to 59 and generates a pulse that feeds the 3rd counter – The 3rd counter counts up to 59 and so on... – The hour, date, month and year counters work in a similar fashion Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 15 Real-time Clock • Provides a time-of-day clock and 100-year calendar with alarm features and battery operation. mp Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis 16