Chapter 17: Sensors CEG2400 – Embedded system design CEG2400 Ch17: Sensors (v.4b) 1 Contents 1. Sensors for our robot: 2. Touch sensors 3. Range IR proximity sensors: Light sensors 4. Schmitt trigger and IR Path following sensors 5. Sound sensors 6. Ultra-sonic sensors 7. Temperature Sensor 8. Electromagnetic sensors: electronic compass 9. Accelerometers 10. Application example: Self balancing robot building CEG2400 Ch17: Sensors (v.4b) 2 1) Sensors for robot • CEG2400 Ch17: Sensors (v.4b) 3 The classic robot with sensors CEG2400 Ch17: Sensors (v.4b) 4 Electronic compass • Our robot Microcontroller LPC2131 Obstacle detector: light-dependent resistor (LDR), + Infrared IR_LED USB RS232 serial interface Bottom view Speed encoder for the D.C. motor: IR-LED+ IR receiver CEG2400 Ch17: Sensors (v.4b) 5 2) Touch sensors Key switch interfacing • CEG2400 Ch17: Sensors (v.4b) 6 Key switch array: A keypad for PC keyboard and mobile phones GPIO output port • GPIO input port CEG2400 Ch17: Sensors (v.4b) 7 Key scan algorithm 0 1 2 3 4 5 6 7 • Key_scan_simple( ) 8 9 A B • { unsigned char i,x,y; C D E F • //handle denounce problem here, such as, • // check if the previous key press has been released or not • //scanning for a key press • for(i=0;i<4;i++) //4 times GPIO • { y=1110(B); //Y(3),Y(2),Y(1),Y(0)=1110 4-bit • output y to GPIO output port Output port • X = read in GPIO input port • If (X not equal to 1111(B)) • { //a key has been depressed and detected, • break; GPIO 4-bit Input port • } • rotate “y” 1 bit to left, i.e. 1110 will become 1101 etc. • } • Find which key has been depressed by current X and Y values. • } CEG2400 Ch17: Sensors (v.4b) 8 Student ID: ___________,Date:_____________ Name: _______________ CENG2400 , Exercises for chapter 17 : sensors • Exercise 1 : a) Explain how to scan the key press using x and y? b) If the key “9” is depressed , what are the values of x and y when the key is detected? a) How to handle multiple key presses. CEG2400 Ch17: Sensors (v.4b) 9 Tentacles • Exercise 2: Add “tentacles” to your project robot. Explain your design and how to interface the GPIO etc. • Suggest examples when such “tentacles” may be useful. CEG2400 Ch17: Sensors (v.4b) 10 (3a) Schmitt trigger logic, Exercise 3: • What is Schmitt trigger logic? Why 7414 inverter do we need a Schmitt trigger inverter here? • What is the value of the input when the output of 7414 changes from High to low? • What is the value of the input when the output of 7414 changes from Low to High? CEG2400 Ch17: Sensors (v.4b) 11 Schmitt triggered inverter (7414) http://www.datasheetcatalog.net/de/datasheets_pdf/7/4/1/4/7414.shtml • For small frustrations of the input , the frustrations will be removed by the Schmitt triggered inverter CEG2400 Ch17: Sensors (v.4b) 12 Example of using Schmitt triggered non-inverting buffer • E.g. in IR motor speed encoder • V1=IR receiver input V1 IR receiver Signal with noise Comparator gives bad result Unstable region when V1 and Vref are closed V0 Better output Using Schmit trigger Schmitt trigger inverter CEG2400 Ch17: Sensors (v.4b) 13 Diagram for hysteresis (non-inverting Schmitt triggered buffer, same as inverting Schmitt triggered chip-7414 just reverse the output ), see P.420, S. Franco, Design with operational amplifiers and analog integrated circuits, McGraw Hill. Voltage • V0 V1 VTH VTL t Output Voltage V1 Switch over voltage V0 10V VTH -VTL= (Vohigh –Volow)(R1/R2)=2V -10V VTL =-1V VTH =1V CEG2400 Ch17: Sensors (v.4b) Vref =0 Input voltage 14 (3b) IR proximity range sensor: Frequency modulated range sensor (less sensitive to surrounding light) used in TV remote controller • Use any MCU with GPIO CEG2400 Ch17: Sensors (v.4b) 15 Using analog-to-digital (ADC)converter • Using analog-to-digital converter to measure the distance between the light sensor and the obstacle. • ADC=Analog to digital converter • DAC=Digital to Analog converter CEG2400 Ch17: Sensors (v.4b) 16 N channels range measurement using IR, multiplexer and ADC. • Used in our classic robot CEG2400 Ch17: Sensors (v.4b) 17 Algorithm for channel selection (one of N channels) and conversion • • • • • Main() { Init. System (GPIO , ADC). Select channel ; Read sensor reading by ADC. } CEG2400 Ch17: Sensors (v.4b) 18 You may use a commercially available chip: Infrared (IR) reflective proximity range sensor, from Mondotronics. Exercise 4 : Draw a block diagram for how to use this sensor in your robot • From: http://datasheet.octopart.com/3337-Mondotronics-datasheet7285303.pdf CEG2400 Ch17: Sensors (v.4b) 19 4) IR path following setup • CEG2400 Ch17: Sensors (v.4b) 20 5) Sound sensors • Types of microphones • Moving coil microphone • Condenser microphone --• Use ADC to convert to digital code • Input to Speech Recognition system • Clipping for simple sound detection CEG2400 Ch17: Sensors (v.4b) 21 Moving coil microphone (battery not required) • CEG2400 Ch17: Sensors (v.4b) 22 Condenser microphone (more sensitive, battery required) • CEG2400 Ch17: Sensors (v.4b) 23 Microphone with amplifier • UA741 or LM741 operational -amplifier http://www.ti.com/lit/ds/symlink/lm741.pdf CEG2400 Ch17: Sensors (v.4b) 24 A digital sound recorder using ADC and DAC • Microphone: uses a uA741 op-amp to amplifier the signal • ADC circuit –An ADC (ADC0820 or ARM ADC) circuit is used to convert speech signal input into digital form. • Output Digital-to-Analog converter DAC that converts digital code into analog voltage • Output is fed to an audio power amplifier (LM386) to drive a speaker. CEG2400 Ch17: Sensors (v.4b) 25 Output power amplifier using a small LM386 amplifier chip • http://www.ti.com/lit/ds/symlink/lm386.pdf CEG2400 Ch17: Sensors (v.4b) 26 Algorithm to drive the digital recorder • • • • • • • • • • • • • • • • • • xdata unsigned char ram_store[N], i; record //sampling record and playback at one go { for(i=0; I < N ; i++) { ram_store[i] = read_in_sound_code_from_GPIO; output_to_dac = ram_store[i]; delay(); //this determines the sampling rate } } playback() // playback what has been rcordered { for(i=0; I < N ; i++) { output_to_dac = ram_store[i]; delay(); //this determines the sampling rate } } CEG2400 Ch17: Sensors (v.4b) 27 Exercise 5 a) Write the program for the interrupt method. b) Write the algorithm to detect the sound of a handclap or a whistle sound. c) What are the elements we need to implement a speech recognition system? (advanced question) CEG2400 Ch17: Sensors (v.4b) 28 Sound DC level shifter for sound level detector • GPIO cut-off point (higher than this is 1, lower than this is 0) With level shifter, all signal is 1. After level shifter (shifted low) sometimes it is 0. CEG2400 Ch17: Sensors (v.4b) 29 6) Ultrasonic radar system • non invasion range detection system • Batman’s radar system Ultrasonic Transmitter | receiver picture from: http://szsaibao.taobao. com/?spm=2013.1.2543493819.1.TCe5j8 CEG2400 Ch17: Sensors (v.4b) 30 The transmitter circuit • CEG2400 Ch17: Sensors (v.4b) 31 The receiver circuit Ultra sound receiver mic • CEG2400 Ch17: Sensors (v.4b) 32 Method 1 (by polling) : Ultrasonic-radar control using MCU and timer Ultra sound On/off control,0=on,1=off • Clock input Courting on/off control Algortithm_radar1() //by polling Timer clock is 13824 KHz { Send out pulses switch on timer Wait until echo is received. Stop timer //wait-loop Read timer, Convert time into length } CEG2400 Ch17: Sensors (v.4b) 33 Method 2 (by interrupt) : Ultrasonic- radar control using interrupt and MCU’s internal timer • Ultra sound On/off control,0=on,1=off Timer clock is 13824 KHz Video http://www.youtube.com/watch?v=qHuVhR6-Q1E CEG2400 Ch17: Sensors (v.4b) 34 Algorithm_radar2 : Ultrasonic- radar control using MCU interrupt and its internal timer • Algorithm_radar2 ( ) // by interrupt and timer method, tested with good result • { initialize internal_timer interrupt; • instruct the GPIO to send out pulses; • start timer; //32-bit internal timer counting at 13.824MHz; //loop • wait a while; // wait a while, the echo is expected to arrive • read internal_timer value; // result, convert into distance • } • //ISR ////////////////////////////////////////////////////////////////////////////// ///////// • isr2_type2_for_timer1_for_radar2 //executes when echo arrives • { Stop internal_timer; • } CEG2400 Ch17: Sensors (v.4b) 35 Exercise 6 a) Compare the two methods Algorithm_radar1(){polling} and Algorithm_radar2( ) {using internal timer interrupt shown above}. b) For Algorithm_radar2( ), if the object is 3 meters away and the speed of sound is 330m/s, what is the time duration that the sound wave travels from the transmitter to the receiver? c) What is the result at the count? d) What is the accuracy (+-meters) of this design? What factors determine the accuracy of this system? CEG2400 Ch17: Sensors (v.4b) 36 7) Temperature sensors • CEG2400 Ch17: Sensors (v.4b) 37 8) Electromagnetic sensor Electronic compass, accuracy +/- 1 degree • 2 perpendicular coils CEG2400 Ch17: Sensors (v.4b) 38 HMC1501 and HMC1512 Linear, Angular, and Rotary Displacement Sensor • http://www.ssec.honeywell.com/magnetic/datasheets/hmc1501-1512.pdf CEG2400 Ch17: Sensors (v.4b) 39 MEMS (Microelectro-mechanical systems ) electromagnetic sensors used in our robot • E.g. http://www.st.com/web/en/catalog/sense_power/FM89?icmp=fm89_pron_memsx2_sep2013&sc=mems-x2 • http://www.st.com/web/en/catalog/sense_power/FM89/SC1449 • CEG2400 Ch17: Sensors (v.4b) 40 9) Accelerometers • An accelerometer measures acceleration, vibration, and shock. • Example: car airbag triggering sensor, 3D mouse -- tilt sensor. • From National Instruments Corporation http://www.ni.com/products/ CEG2400 Ch17: Sensors (v.4b) 41 Example of using accelerometer From:http://www.csl.sony.co.jp/person/rekimoto/tilt/ Youtube Link: CEG2400 Ch17: Sensors (v.4b) 42 Accelerometers in WII • http://myskitch.com/keith/wii20070724-011824.jpg/preview.jpg • IMU (Inertial measurement unit) camera control / stabilization Video link https://www.youtube.com/watch?v=7GVXqNLLH7Q http://youtu.be/CQ_P5XWkYcI CEG2400 Ch17: Sensors (v.4b) 43 Use accelerometer and gyroscope to make a self balancing robot 2-side wheels self balancing robot • • Our CUHK robot has one of the hottest “self balancing robots” in YouTube. 62637 clicks so far on 17 Nov 2014 Motor cycle • http://www.youtube.com/w atch?v=0312BNqIBFI CEG2400 Ch17: Sensors (v.4b) 44 Exercise 7: Self balancing robot: Discuss how to build a self balancing robot using a) Assume we have an inclination sensor (accelerometer is an example) : output 0.1 Volts/degree. Discuss how to interface the inclination sensor with LPC2131. b) Discuss how to control the motor rotation direction and speed. c) Discuss how to make a feedback system for balancing the robot (Hint: use PID, see the diagram on the right for speed-control-PID, but you need to modify it to become a position control PID) CEG2400 Ch17: Sensors (v.4b) Accelerometer output= *0.1 Volts/degree A typical speed control PID 45 Summary • A number of different sensors have been studies • And examples of how they are used are also demonstrated CEG2400 Ch17: Sensors (v.4b) 46 Appendix: Answer for Exercise 6 for ultrasonic radar a) Compare the two methods Algorithm_radar1( ){polling} and Algorithm_radar2( ) {using internal timer interrupt shown above}. b) For Algorithm_radar2( ), if the object is 3 meters away and the speed of sound is 330m/s, what is the time duration that the sound wave travels from the transmitter to the receiver? – Answer: sound traveled 3x2=6m. – Time_delay (dt)=6m/(330m/s)=18.18ms – If interrupt is 13.824MHz, each timer clock is 1/13.824M=72.33ns c) What is the result at the count? A. so counting result for dt=18.18ms/(1/13.824M)=18.18ms/72.33ns=251347. d) What is the accuracy (+-meters) of this design? What factors determine the accuracy of this system? – Each clock pulse is (1/13.824M)s=72.33ns, that represents dL=330m/s*(72.33ns)= (330/13.824M)m=0.239mm – The real accuracy is half of it because it is an echo , so 0.239mm/2=0.119mm – It is not accurate because temperature may change sound speed. CEG2400 Ch17: Sensors (v.4b) 47
© Copyright 2024