1 / 85

Micro-Controllers & Robotics

Micro-Controllers & Robotics. Robotics Club IT-BHU. Agenda. Session I Introduction to Microcontrollers( uCs ) Introduction to Compiler & Downloader Atmega16 Components Programming of PORTs Glowing LEDs n making dancing patterns Introduction to Motors & Motor Drivers

caseym
Download Presentation

Micro-Controllers & Robotics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Micro-Controllers & Robotics Robotics Club IT-BHU

  2. Agenda • Session I • Introduction to Microcontrollers(uCs) • Introduction to Compiler & Downloader • Atmega16 Components • Programming of PORTs • Glowing LEDs n making dancing patterns • Introduction to Motors & Motor Drivers • Controlling Motors using Atmega16 • Lab Session • Session III • Introduction to LCD • Programming of LCD • Intro & Prog of Timers • Making Digital Clock • Lab Session • Session II • Introduction to IR LED & Rx • Making IR Sensor • Using IR sensor with ATmega16 • Introduction to ADC • Programming of Inbuilt ADC • Making Line Follower Robot • Lab Session • Session IV • Doubt Clearing • Completing programs / projects • Algorithms for various Robots • Advanced topics – Keypad & Communication

  3. What is a uC ? Introduction In simple words -- a single chip Computer

  4. Introduction • Computer • uP • RAM • HDD • Clock • Ports (Serial/USB) • Ports (Parallel) • Mic/Headphone Jack (ADC/ DAC) • Power Supply Unit • Reset • Mother-board • uC • uP • Flash Memory • EEPROM • Clock Unit • SPI / UART Controllers • Digital I/O Ports • ADC • Power Supply Unit • Reset • IC

  5. From uP to uC • uP • Memory • Oscillator • Buffers • ADC • Comparator • UART • Interrupt controllers • SPI • Two Wire connector • JTEG Connectors

  6. Atmega16L : An Overview 8-bit Micro-cotroller 40-pin DIP 32 Programmable I/O Lines Operating Voltages 2.7 - 5.5V Speed Grades 0 - 8 MHz 16K Bytes of In-System Self-programmable Flash program memory 512 Bytes EEPROM Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode 8-channel, 10-bit ADC Programmable Serial USART Master/Slave SPI Serial Interface Programmable Watchdog Timer with Separate On-chip Oscillator On-chip Analog Comparator

  7. Pin diagram

  8. Block Daigram

  9. Simplified Diagram 4 8bit Parallel Input-Output ports through which you can i/p or o/p digital data.

  10. Port Architecture P O R T A D D R A P I N A uC External world

  11. Programming the Ports Normal C program int x; float y; x= 10; y= 8.97; Program for Ports DDRA = 0b11111111 or 0xFF // o/p DDRC = 0b00000000 or 0x00 // i/p PORTA = 27; // decimal PORTC= 0b11010110; // binary DDRx defines whether the port will act as input port or o/p port. Just as ‘int’ declares a variable as integer type. It does not assign any value to it. PORTx assigns the value to be output. If DDRx=0 ie port is defined as input port, PORTx will store the value but will not o/p it.

  12. More Examples PORTA=0x5A ; PORTA=0b01011010; PORTA=5; DDRA=0xFF; DDRA=0b11110000; // pins A7-A4 as o/p & A3-A0 as i/p You can even address individual pins of any Port DDRA.3= 1; // Only Pin 3 of Port A (A4) is configured as o/p pin , rest untouched PORTA.0=1; // pin 0 of Port A outputs 1, rest retain there previous values

  13. Taking Inputs To take Digital i/p from external world first configure the port as i/p port using DDRx=0 Use PINx to read the digital value. x = PINA // read 8 bit integer value from Port A. 0 < x < 255 y= PINB x,y must be defined as unsigned integers in ur C program. Individual pins can be read in the same way. x= PINA.2 // as the individual pins are read n the value is digital, therefore x can either be 0 or 1 y= PINC.6

  14. Complete Program A program to o/p 33 (hex) on PortD and configure and read pins 2 and 7 of Port A #include <mega16.h> void main( ) { unsigned intx,y; DDRD=0xFF; // all pins o/p DDRA=0b01111011; // pin 7 & 2 i/p rest immaterial PORTD=0x33; x=PINA.2; y=PINA.7; }

  15. LED GND - + V +

  16. Glowing LED 0 P o r t A - 1 + To glow LED set PORTA.0=0; PORTA.1=1; or PORTA=0b00000010; or PORTA=0x02;

  17. Glowing LED contd.. 0 P o r t A - 1 +

  18. LED Panel on PCB +V GND

  19. Blinking Pattern While (1) { PORTA=0xFF; delay_ms(500); PORTA=0x00; delay_ms(500); } While (1) { PORTA=0xFF; PORTA=0x00; }

  20. Complete Program A program to make a blinking pattern #include <mega16.h> #include <delay.h> void main( ) { DDRA=0xFF; // all pins o/p While (1) { PORTA=0xFF; // all LEDs ON delay_ms(500); PORTA=0x00; // all LEDs OFF delay_ms(500); } }

  21. Motors & Motor Drivers

  22. Motors and Motor Drivers Types Motors • AC Motor • DC Motor • Stepper Motor • Servo Motor

  23. DC motor

  24. Stepper Motor • Similar principle to DC motors • More accurate control than DC motors • Rotate in fixed angles • Speed control is in our hands • Multiple coils – so excitation done in pattern for rotation

  25. Stepper Motor

  26. Servo Motors • DC motors with built in gearing and feedback Control loop • Generally rotate through 90 and 180 deg. (360 deg also available) • Used for extreme precision

  27. Motor Driver Why do we need the motor driver? The total output current that Atmega16 can provide is 200mA. But motors need much higher current to run. Therefore a driver circuit is required which provides the necessary current. Moreover the o/p from uC can either be 0V or +5V, but motors come in various ratings 2V-36V (typically small ones). Atmega cannot provide this voltage hence we need external supply to drive motor depending upon i/p from uC Basically a motor driver connects or disconnects the motor from some external supply depending upon the i/p from uC. If the uC sends ‘1’ , driver connects the motor to some external supply ( battery in our case) thus motor actually runs by drawing current from the battery. If the uC sends a ‘0’ , o/p is connected to ground and hence the motor does not get the supply.

  28. Working ofMotor Driver +VPP 1 0 O/p 1 I/p 1 ( O/p from uC) O/p 2 I/p 2 O/p 3 I/p 3 O/p 4 I/p 4 If uC send ‘1’ to I/p 1, O/p is conn to + VPP GND If uC send ‘0’ to I/p 1, O/p is conn to GND

  29. Working ofMotor Driver +VPP O/p 1 I/p 1 ( O/p from uC) 1 0 O/p 2 I/p 2 O/p 3 I/p 3 O/p 4 I/p 4 If uC send ‘1’ to I/p 2, O/p is conn to + VPP GND If uC send ‘0’ to I/p 2, O/p is conn to GND

  30. Similarly other 2 o/p are connected /disconnected by I/p 3 & I/P 4 All the O/p’s operate independently, ie if all I/p 1-I/p 4 are 1, all O/p1 – O/p4 will be connected to +VPP L298 can provide 1A current / Output channel , therefore total of 4A. But heat sinks should be installed for such high currents . VPP can be anything in the range 2V- 46V , therefore any motor can be driven even though Atmega provides only 0/5 V.

  31. L298N Motor Driver

  32. A T M E G A MOTOR DRIVER 4 Outputs 4 Inputs MOTOR

  33. Driving a Motor To drive a motor A motor has two wires : +ve & -ve. To drive it u need to apply a voltage between them Lets connect +ve wire to O/p1 & -ve to O/p2 of L298 If we give I/p1 =1 & I/p2 = 0, O/p1 will be +VPP & O/p2 GND The voltage diff between two wires of motor = +VPP , therefore it will run in one direction If we give I/p1 =1 & I/p2 = 1, O/p1 will be +VPP & O/p2 +VPP The voltage diff between two wires of motor = 0, therefore it will NOT run If we give I/p1 =0 & I/p2 = 1 , O/p1 will be GND & O/p2 +VPP The voltage diff between two wires of motor = -VPP , therefore it will run in reverse direction If we give I/p1 =0 & I/p2 = 0, O/p1 will be GND& O/p2 GND The voltage diff between two wires of motor = 0, therefore it will NOT run

  34. Lets Connect I/p 1 to PortB.0 & I/p 2 to PortB.1 As these ports will o/p data from uC, therefore their DDR should be 1 DDRB= 0b00000011; Or DDRB=0x03; For running in reverse dir, PORTB.0 =0 & PORTB.1=1 PORTB=0b00000010; Or PORTB=0x02; For running in forward dir, PORTB.0 =1 & PORTB.1=0 PORTB=0b00000001; Or PORTB=0x01;

  35. Complete Program Sample program for running motor forward for 1s , reverse for 1s & stop for 1s in sequence #include<mega16.h> #include<delay.h> void main() { DDRB=0x03; // other part included by CVAVR comes here while (1) { PORTB=0x01; // forward delay_ms(1000); PORTB=0x02; // reverse delay_ms(1000); PORTB=0x00; // stop delay_ms(1000); } }

  36. Session II

  37. Sensors • A sensor is a device which measures a physical quantity and converts it into a signal which can be read by an observer or by an instrument. • They are used to provide feedback from the external environment

  38. IR Sensor Pair Object / Line IR sensor Pair Transmitter (Tx) Receiver (Rx) Transmitter = LED( Light Emitting Diode) Receiver = Photodiode

  39. Principle of Operation WHITE surface Maximum reflection T1 is turned ON Vout is LOW BLACK surface Minimum or No Reflection T1 is turned OFF Vout is HIGH R1< R2

  40. Interfacing IR sensor with ATmega16 Out: 1 0 1 Out: 0 2 A T M E G A PORTA In

  41. Programming IR sensor with ATmega16 #include <mega16.h> void main() { int x; DDRA=0b00000011; // last two pins as o/p for Vcc & GND PORTA.0 =1; // Vcc PORTA.1= 0; // Gnd x= PINA.2; // now you can use x for any calculation u want }

  42. Vout is ANALOG But uC being digital can only read it as 0 or 1. 0 if Vout < 1.2 V 1 if Vout > 1.2 V However most applications require much higher resolution n multiple levels.

  43. Analog to Digital Convertor (ADC) • The ATmega16 has an inbuilt 10 bit ADC (1024 Levels) • 8 Multiplexed Single Ended Input Channels • 7 Differential Input Channels

  44. Registers used in the ADC • ADMUX – ADC Multiplexer Selection Register • ADCSRA – ADC Control and Status Register A These registers are used to configure ADC However when using CVAVR this will be done by code wizard

  45. Configuring ADC using Code Wizard ADC Open a new project Select ‘yes’ to use code wizard Goto ADC tab on Code Wizard

  46. Configuring ADC Set the parameters as shown or as per your requirement. Finally Generate Save & Exit

  47. Programming ADC When you generate the program after setting the code wizard you will a find a function unsigned intread_adc(unsigned char adc_input) declared & defined just after #include It accepts an Unsigned character as argument which is basically the hex address of the pin on which Analog i/p is applied. However we don’t need to give the address but just the name of pin and the conversion is done by compiler. Return value is the digital value ( 0-1023 or 0-255) of the analog i/p.

  48. Programming ADC To use ADC just call the function read_adc( ) as shown unsigned int s; Argument specifies which pin the analog i/p (ie o/p of sensor) is connected s = read_adc(PINA.2) ; S can now be used for any calculations. Its value ranges from 0-1023 (if Use 8 bits was NOT checked in configuration) 0-255 (if Use 8 bits was checked in configuration)

More Related