Download presentation
Presentation is loading. Please wait.
Published byMarlene Newman Modified over 9 years ago
1
Suleyman Demirel University 20151 CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS
2
Suleyman Demirel University 20152 ATMEGA328P ARCHITECTURE In-System Programmable (ISP) flash to store programs holds run-time variables store any data 23 general purpose input/output lines three Timer/Counters with compare modes 2-wire Serial Interface Serial Peripheral Interface6-channel 10-bit Analog/ Digital Converter All peripheral devices are controlled via sets of specific registers, each of which is connected to the 8-bit data bus
3
Suleyman Demirel University 20153
4
4 General-Purpose Input/Output Basic operation to output a digital signal on pin n of port x is to: 1. write a ‘1’ into DDRx_Bitn, then 2. write either a ‘1’ or ‘0’ into Portx_Bitn. Basic operation to input a digital signal on pin n of port x is to: 1. write a ‘0’ into DDRx_Bitn, then 2. read the value out of Pinx_Bitn.
5
Suleyman Demirel University 20155 INTERNAL PULL-UP RESISTOR Generally, when a port pin is not being used, the microcontroller will default the pins to input, in order to save on power. Floating pin data can lead to strange and unexpected behavior. Very standard method for managing unused input pins is to connect a fairly large resistance between the pin and the power supply.
6
Suleyman Demirel University 20156 PORT B (8-13) I/O REGISTERS pinMode(pin, mode); //Input sample code: pinMode(8, INPUT); //Sets DDRB0 to 0 digitalRead(8); //Reads PINB0 //Output sample code: pinMode(8, OUTPUT); //Sets DDRB0 to 1 digitalWrite(8,HIGH); //Sets PORTB0 to 1
7
Suleyman Demirel University 20157 Analog Signals Potentiometer - a mechanical knob is used to adjust the resistance between terminals; Thermistor - a device that changes resistance based on temperature; Accelerometer - a device that measures the acceleration of gravity in three dimensions and outputs an associated analog value for each dimension (e.g., this is the basis behind the Nintendo Wii video-game controllers); Ambient light sensor - a device that measure the environmental ambient light intensity and outputs an associated analog value (e.g., many laptop computers will adjust the backlight level based on the surrounding environment light level); Microphone - a device that converts vibrations (i.e., acoustic- waves) into analog levels.
8
Suleyman Demirel University 20158 Analog Input Port In order for a microcontroller to operate on the sensor outputs, an Analog-to-Digital Conversion (ADC) circuit must be used The parallel ADC uses typical values for Vmin and Vmax where the minimum voltage is simply set to ground and Vmax is controlled externally via the user-defined reference voltage VREF. The resistor network on the left- hand side is designed such that VREF−V2=V2−V1=V1−V0=V0 The analog voltage VA is first converted into a three-bit codeword defined by (c2c1c0), where each bit is the output of a comparator. 4 possible codewords are then passed through an encoder that outputs the final two-bit value (b1b0).
9
Suleyman Demirel University 20159 Analog Input Port Arduino development board has six 10-bit ADCs, all of which are found on Port C. (A0-A5) For generic usage of the ADC port functionality, the following steps should be addressed. Register ADCSRA needs to be enabled, started, auto trigger enabled, and an appropriate prescalar selected; Register ADCSRB needs to have the auto trigger source set to free running, so the program can read the converted value of a low-frequency sensor (which is often our application); Register ADMUX needs to have a VREF source selected, right or left justification selected, and the desired ADC channel selected; Register DIDR0 should have the input pin associated with the ADC channel selected in ADMUX disabled. Once the ADC is initialized, the program can poll the ADC output by reading the 16-bit ADC register which contains the 10-bit result
10
Suleyman Demirel University 201510 Analog Port Registers
11
Suleyman Demirel University 201511 Analog Input Port analogReference(type); Configures the reference voltage used for analog input. The options are: DEFAULT: the default analog reference of 5 volts. INTERNAL: a built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega) EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference. analogRead(pin); Reads the value from the specified analog pin. The Arduino Uno board contains a 6 channel, 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, 4.9 mV per unit. The input range and resolution can be changed using analogReference(). It takes about 100 microseconds to read an analog input, so the maximum reading rate is about 10,000 times a second.
12
Suleyman Demirel University 201512 Reading Analog Value int analogPin = A0; // potentiometer wiper (middle terminal) connected to // analog pin 3 outside leads to ground and +5V int val = 0; // variable to store the value read void setup() { Serial.begin(9600); // setup serial } void loop() { val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.