Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
EMS1EP Lecture 9 Analog to Digital Conversion (ADC) Dr. Robert Ross Overview (what you should learn today) • • • • • • Revision of Analog and Digital ADC + Quantisation Examples of Analog Inputs Worked examples Minor Project Major Project Analog/Digital Digital Voltages Physical Variable (Sound, light, pressure, temp, ect) DAC ADC Transducer (Sensor) Analog to Digital Converter Microcontroller (LArduino) Analog Voltages Digital to Analog Converter Actuator Control Physical Variable (Sound, light, pressure, temp, ect) Analog to Digital Converters (ADC) • Measure an analog value and provide a digital representation of this value • Like a digital multimeter for your microcontroller • Inside the Arduino microcontroller • Several different techniques used (covered in second year microcontrollers) ADC quantisation • Converting a continuous value into a digital number • Arduino has a 10bit ADC – (210 = 1024 voltage levels) • Value returned in the range of 0-1023 (corresponding to 0-5V) • 5/1023 = 4.89mV/step • Each time you increase the voltage by 4.89mV the digital value should go up 1 step ADC on the LArduino • LArduino has 4 analog inputs (marked Analog 0-3) • Analog inputs can be connected to all of these inputs at the same time • Can only read one analog input at a time Using the ADC • Analog pins don’t need to be setup in the setup function • To read an analog value use the analogRead() command. • Syntax: int analogRead(<ADC Pin>); Returns the analog result <ADC Pin>: specifies which ADC pin you wish to read (i.e. Pins 0-4) Typical use: int ADC_Result; ADC_Result = analogRead(2); Examples of Analog Inputs Temperature Acceleration Voltage (Variable resistor forms voltage divider) Pressure Light Worked Example: Potentiometer • Interface a potentiometer to an analog input on the Arduino • Every 500ms read the value of the potentiometer and send it via the serial port to the PC • If the value is more than 500 turn ON an LED – else turn off LED Worked Example: Potentiometer • Circuit Diagram 5V 5V LArduino Board Analog Pin2 Voltage (Variable resistor forms voltage divider) Pin5 Worked Example: Potentiometer int pot1 = 2; int led1 = 5; int ADCValue; void setup() { Serial.begin(<baud rate>); //Setup serial port pinMode(led1, OUTPUT); //Setup LED delay(500); } Worked Example: Potentiometer void loop() { ADCValue = analogRead(pot1); //Read analog value Serial.print(“ADC Result: “); Serial.println(ADCValue); if(ADCValue > 500){ //Turn LED on digitalWrite(led1,LOW); } else{ //Turn LED off digitalWrite(led1,HIGH); } delay(500); //500ms delay } Measuring multiple ADCs • Only one ADC can be measured at a time • If more than one need to be measured step through and measure one after another ADCValue1 = analogRead(ADC1); ADCValue2 = analogRead(ADC2); ADCValue3 = analogRead(ADC3); Worked example: Light Sensor • Create a ‘garden light sensor’ • A photodiode is used to sample how much light there is and gives an analog voltage output • If the voltage is below a preset threshold then turn on another LED – otherwise turn off the LED 5V 5V 100K LArduino Board Analog Pin1 Pin6 Worked Example: Light Sensor int pd1 = 1; int led1 = 6; void setup() { pinMode(led1, OUTPUT); } void loop() { //You fill in this section } //Setup LED Minor Project: Level Crossing System • Construction of a train level crossing system • Description – a level crossing system using 1 servo as the boom gate, activated by a debounced switch and with flashing warning lights and a audible buzzer alarm • Deliverables: – Working System for demonstration day – Schematics (completed in Altium) – Code Minor Project: Level Crossing System • When the switch is pressed (and at some point released): – The boom gate should come down (servo turn 90o) – Two LEDs should alternately flash at 1Hz – A buzzer should be controlled to beep in 0.5 second bursts (use PWM with 50% duty cycle) • The switch is a debounced switch. When the switch is pressed a second time the boom gate should come up, the LEDs should stop flashing and the buzzer should remain silent • See handout for more details • Minor project is to be completed in the lab (may require a small amount of extra outside lab time) • Demonstrations in lab 8 What the minor project should look like Major Project • Build a robot • Infrared photodiodes on the bottom (allow it to sense light/dark objects • Battery powered • Control algorithms • Applications – Line tracking/following – Staying inside a paddock – Racing What the major project should look like Continuous Rotation Servos • By default servo motors only have about 180O of motion that they can travel over • Servos can be modified for continuous rotation (they can go all the way around) • PWM signal controls speed not position of continuous rotation servos • Involves: – Removing feedback potentiometer (variable resistor) – Soldering in resistors – Cutting notch out of gears • Instruction video will be provided in the labs Control Algorithms • Three light sensors on the bottom of the robot used to detect the lines • For line following want to keep it close to the middle sensor • Possible readings: – – – – – – – No Sensors (but last seen on S1) S1 only S1+S2 S2 only S2+S3 S3 only No Sensors (but last seen on S3) S1 S2 S3 Control Algorithms • Suggested algorithm is a proportional one – The further away the robot is from the line (S2 only) the larger change in its relative speed between the wheels it should make – Should also give the robot a little forward bias so it keeps moving forward and doesn’t get stuck in tight bends • Can switch between just driving forward and control algorithm • Will need to experiment with different speeds and find a mix between speed and stability • Execution tests will have races with the fastest robots receiving bonus marks (but they must not leave the track) Summary (What you learnt in this session) • Many sensors that our microcontroller needs to read are analog • An ADC enables the microcontroller to read an analog value and convert it to a digital number • Introduction to the minor and major project tasks