Download presentation
Presentation is loading. Please wait.
Published bySimon Bryant Modified over 9 years ago
1
Robotics Research Laboratory Louisiana State University
2
Analog to Digital (ADC, A/D or A to D) ◦ Converting an analog voltage to a digital value that can be used by a microcontroller. ◦ There are many sources of analog signals to be measured such as light intensity, temperature, distance, position, etc. ATMega128 ADC has 10 bits resolution (0~1024) ◦ Has 8 channels through a multiplexer ◦ 8 pins on PORTF ◦ Need to set PORTF as input without pull-up ◦ Has own power supply (labeled AVCC) ◦ Allows measuring voltages from 0 to 5 volts with a resolution of 5/1024 volts, or 4.88 mV
3
S1 = 0 ~ 20000 Ω R2 = 1000 Ω - + 5 V X V drop = Xi mA x S1 Ω X v+ restV drop = Xi mA x 1000Ω 0V drop = Xi mA x 0 Ω 5 V Connect to ADC 0 V Resistance value of S1(IR sensor) can be changed by sensing
4
uint16_t a2d_10( uint8_t Channel ){ // Select the channel in a manner which leaves REFS0 and REFS1 un touched. ADMUX = ( ADMUX & (( 1 << REFS1 ) | ( 1 << REFS0 ))) | Channel; // Start the conversion ADCSR = ADCSR | ( 1 << ADSC ); // Wait for it to complete while ( ADCSR & ( 1 << ADSC )); return ADC; // ADC defined at avr/iom128.h ( special function register: SFR_IO16) } // a2d_10 /home/csc2700/csc2700/40-ADC-01
5
Our programmer has 2 serial port ◦ ttyACM0 : ISP programming port ◦ ttyACM1 : UART serial port Wire connection ◦ PE0 Yellow wire ◦ PE1 Green wire ◦ GND Black wire Open Gtk-term ◦ Set port : /dev/ttyACM1 ◦ Speed: 57600 for ttyACM1 9600 for Bluetooth connection
6
Config.h ◦ Set : #define CFG_USE_UART0 1 Hardware.h ◦ Set : #define UART0_BAUD_RATE57600 ADC_test.c ◦ Add : #include "UART.h” ◦ Create file pointer : FILE *u0;// for UART0 ◦ Open u0 if defined( __AVR_LIBC_VERSION__ ) u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio ); #else u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio, 0 ); #endif ◦ Send values using fprintf(u0,”your message %d”, variable) ; /home/csc2700/csc2700/40-ADC-02
7
Check the UART buffer first ◦ int UART0_IsCharAvailable() Read a character from UART buffer ◦ int UART0_GetChar() int counter; char tmpChar; While(1){ if ( UART0_IsCharAvailable() ) { tmpChar = UART0_GetChar(); if ( tmpChar == ‘s'){ // start moving }else if ( tmpChar == ‘c'){ // clear counter }else if ( tmpChar == ‘r’){// report counter number }
8
Make a led0 on when ‘0’ message is received from UART Make a led0 off when button0 is pressed Make a led1 on when ‘1’ message is received from UART Make a led1 off when button1 is pressed Send “!!!good bye!!!” message to UART tx when “bye” message is received from UART rx
9
photo IR Temperature GAS Acceleration Humidity Sonar
10
Internal Interrupt ◦ Timer interrupt ◦ Counter interrupt External Interrupt INT0 = SCL [PD0] INT1 = SDA [PD1] INT2 = RXD1 [PD2] INT3 = TXD1 [PD3] INT4 = OC3B [PE4] INT5 = OC3C [PE5] INT6= T3[PE6] INT7= ICP3 [PE7] RESET= RESET [RESET] SPI, UART, etc
11
Main program Interrupt service routine Interrupt occur Interrupt Register Bit check Interrupt Trigger check Save Main program PC at stack Jump to Triggered Interrupt Vector Execute Interrupt Service Routine Load PC from Stack then, return to Main program
12
1) Falling edge2) Rising edge 3) Low level High: + 4 V Low: 0.9 V
13
ISCn1ISCn0Trigger Signal 00The low level of INTn 01Reserved 10The falling edge of INTn 11The rising edge of INTn // Grab the rising edge. EICRB |= (( 1 << ISC71 )|( 1 << ISC70 )|( 1 << ISC61 )|( 1 << ISC60 )); // External interrupt control register B EIFR = (( 1 << INTF7 ) | ( 1 << INTF6 )); // External interrup flag register EIMSK |= (( 1 << INT7 ) | ( 1 << INT6 )); // External interrup mask register DDRE &= ~(( 1 << 6 ) | ( 1 << 7 )); // PE6 & PE7 set input PORTE |= (( 1 << 6 ) | ( 1 << 7 )); // pullup for input sei(); // set interrupt cli();// unset interrupt
14
int leftCounter = 0; int prevLeft = 0; int runFlag = 0; long cnt = 9000000; main(1){ // Grab the rising edge. EICRB |= (( 1 << ISC71 )|( 1 << ISC70 )|( 1 << ISC61 )|( 1 << ISC60 )) // External interrupt control register B EIFR = (( 1 << INTF7 ) | ( 1 << INTF6 )); // External interrup flag register EIMSK |= (( 1 << INT7 ) | ( 1 << INT6 )); // External interrup mask register while(1){ if (leftCounter != prevLeft){ prevLeft = leftCounter; PIN(LED,1,SET_TOGGLE); } while (cnt-- > 0){ } cnt = 9000000; } // interrupt service routine for int6 SIGNAL(SIG_INTERRUPT6){ leftCounter++; PIN(LED,0,SET_TOGGLE); } // SIG_INTERRUPT6
15
Make a counter for the optical switches on wheels Make a clear the counter when ‘c’ message is received from UART Make a report the counter when ‘r’ message is received from UART Make a robot move forward when ‘s’ message is received from UART until the counter value is 90
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.