Robotics Research Laboratory Louisiana State University
MOSFET-based H-bridges Metal–Oxide–Semiconductor Field-Effect Transistor DC Motor Controller (TB6612FNG)
int main(void){ InitHardware(); // PWM setting // ICR3 = 40000u;// input capture registor --> pulse cycle every 40 milli seconds TCNT3 = 0;// interupt flag registor // Set the WGM mode & prescalar for oscillating timer ( TCCR3A & TCCR3B : Timer control registors) TCCR3A = ( 1 << WGM31 ) | ( 0 << WGM30 ) | ( 1 << COM3A1 ) | ( 1 << COM3B1 ) | ( 1 << COM3C1 ); TCCR3B = ( 1 << WGM33 ) | ( 1 << WGM32 ) | TIMER3_CLOCK_SEL_DIV_8; DDRE |= (( 1 << 3 ) | ( 1 << 4 ) | ( 1 << 5 ));// I/O control registor (PWM pins as outputs) MC_HI(STANBY); MC_LO(LEFT0); MC_LO(LEFT1); MC_LO(RIGHT0); MC_LO(RIGHT1); int speed = 1000; int delay = 100; while (1){ MC_LO(LEFT0);MC_HI(LEFT1); OCR3A = speed; ms_spin(delay); MC_HI(LEFT0);MC_LOW(LEFT1); speed += 1000; if (speed > 40000){ speed = 1000; }
Converting a continuous quantity to a discrete time digital representation 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. The reverse operation is performed by a digital-to-analog converter (DAC).
The number of discrete values it can produce over the range of analog values. ◦ Usually stored electronically in binary form ◦ The number of discrete values available, or "levels", is a power of two. (ex) 8bits Range from 0 to 255 ◦ where n is the ADC's resolution in bits V ref-High - V ref-Low 2n2n Resolution =
ATMega128 ADC has 10 bits resolution ◦ What is the range? Has 8 channels through a multiplexer ◦ 8 pins on PORTF ◦ Need to set PORTF as input without pull-up ◦ How to set this 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
Can be configured in several different ways Single-ended � mode : the analog voltages presented on the ADC channels are compared to ground. There are several selectable voltage references, which determine the range of the ADC conversion. (ex) AVCC Free-running mode (update continuously) or only one conversion.
QuantitySymbolUnit of measurement Unit of Abbreviation CurrentIAmpere (“Amp”)A VoltageV or EVoltV ResistanceR OhmΩ E = IR, I = E / R, or R = E / I
R1 = 100 Ω R2 = 400 Ω V 10 mA = 5 V / 500 ΩI = E / R 1V drop = 10 mA x 100 Ω 4V drop = 10 mA x 400 Ω 0V drop = 10 mA x 0 Ω 5 V 4 V 0 V First calculate current ( I ) by using E / R (5 / 500 = 0.01) Then calculate voltage drop at each point based on Ohm’s Law E = I x R (R1 = 0.01 * 100, R2 = 0.01 * 400)
S1 = 0 ~ Ω R2 = 1000 Ω 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
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
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
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