CSC-2700 – (3) Introduction to Robotics

Download Report

Transcript CSC-2700 – (3) Introduction to Robotics

Robotics Research Laboratory
Louisiana State University


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
5V
+
S1 = 0 ~ 20000 Ω
Connect to ADC
5V
-
0V drop = Xi mA x 0 Ω
X V drop = Xi mA x S1 Ω
R2 = 1000 Ω
0V
X v+ restV drop = Xi mA x 1000Ω
Resistance value of S1(IR sensor) can be changed by sensing
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


Translates data between parallel and serial
forms
UARTs are commonly used in conjunction
with communication standards
◦ ex) EIA RS-232, RS-422 or RS-485

Character framing
◦ Start bit: logic low
◦ Stop bit : logic high ( 1 or 2 bits)
◦ Parity bit : optional (even or odd)

Important Setting for Serial UART :
◦ Baud Speed , Flow control, Port

Minimum required connection
◦ RX(yellow),TX(green), and Ground(black)

Our programmer has 2 serial port
◦ ttyACM0 : ISP programming port
◦ ttyACM1 : UART serial port

Wire connection
◦ PE0
◦ PE1
◦ GND

 Yellow wire
 Green wire
 Black wire
Open Gtk-term
◦ Set port :
◦ Speed :
/dev/ttyACM1
57600 for ttyACM1
9600 for Bluetooth connection

Config.h
◦ Set : #define CFG_USE_UART0 1

Hardware.h
◦ Set : #define UART0_BAUD_RATE

57600
ADC_test.c
◦ Add : #include "UART.h”
◦ Create file pointer : FILE *u0; // for UART0
◦ Open u0
 if defined( __AVR_LIBC_VERSION__ )

 #else

 #endif
u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio );
u0 = fdevopen( UART0_PutCharStdio, UART0_GetCharStdio, 0 );
◦ Send values using fprintf(u0,”your message %d”, variable);
/home/csc2700/csc2700/40-ADC-02

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'){
}else if ( tmpChar == ‘c'){
}else if ( tmpChar == ‘r’){
}
}
}
// start moving
// clear counter
// report counter number





Make a led0
from UART
Make a led0
Make a led1
from UART
Make a led1
on when ‘0’ message is received
off when button0 is pressed
on when ‘1’ message is received
off when button1 is pressed
Send “!!!good bye!!!” message to UART tx
when “bye” message is received from UART rx




Make a led0 ON and a motor clockwise spin
when ‘4’ message is received from UART
Make a led1 ON and a motor anti-clockwise
spin when ‘6’ message is received from UART
Make a led2 ON and speed of the motor
increase when ‘8’ message is received from
UART
Make a led3 ON and speed of the motor
decrease when ‘2’ message is received from
UART