Download presentation
Presentation is loading. Please wait.
Published byKristofer Corke Modified over 10 years ago
1
EMS1EP Lecture 9 Analog to Digital Conversion (ADC) Dr. Robert Ross
2
Overview (what you should learn today) Revision of Analog and Digital ADC + Quantisation Examples of Analog Inputs Worked examples Minor Project Major Project
3
Analog/Digital Microcontroller (LArduino) ADC Analog to Digital Converter DAC Digital to Analog Converter Transducer (Sensor) Actuator Physical Variable (Sound, light, pressure, temp, ect) Control Physical Variable (Sound, light, pressure, temp, ect) Analog Voltages Digital Voltages
4
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)
5
ADC quantisation Converting a continuous value into a digital number Arduino has a 10bit ADC – (2 10 = 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
6
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
7
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( ); Returns the analog result : specifies which ADC pin you wish to read (i.e. Pins 0-4) Typical use: int ADC_Result; ADC_Result = analogRead(2);
8
Examples of Analog Inputs Pressure Acceleration Temperature Voltage (Variable resistor forms voltage divider) Light
9
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
10
Worked Example: Potentiometer Circuit Diagram LArduino Board 5V Analog Pin2 Voltage (Variable resistor forms voltage divider) Pin5 5V
11
Worked Example: Potentiometer int pot1 = 2; int led1 = 5; int ADCValue; void setup() { Serial.begin( ); //Setup serial port pinMode(led1, OUTPUT); //Setup LED delay(500); }
12
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 }
13
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);
14
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 LArduino Board Analog Pin1 5V Pin6 5V 100K
15
Worked Example: Light Sensor int pd1 = 1; int led1 = 6; void setup() { pinMode(led1, OUTPUT); //Setup LED } void loop() {//You fill in this section }
16
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
17
Minor Project: Level Crossing System When the switch is pressed (and at some point released): – The boom gate should come down (servo turn 90 o ) – 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
18
What the minor project should look like
19
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
20
What the major project should look like
21
Continuous Rotation Servos By default servo motors only have about 180 O 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
22
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) S1S2S3
23
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)
24
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.