Intro to Robotics       Moayad H. AlmohaishiLouisiana Tech MS computer science President of Louisiana Tech Robotic        ...
ROBOTIC 2010Video Deleted to reduce the file size. I will add it soonto Youtube.
What you need to start MPLAB Programming IDE (need windows OS)• http://www.microchip.com/stellent/idcplg?IdcService=S S_GE...
Programming tool
PartsPrototype BoardWiresPIC 18 MicroprocessorCapacitorsResistorsVoltage regulatorLEDsBattery6-pins headersSensors
Parts4Mhz CrystalH-Bridge / Motor ControllerThe Base(Chassis)- Eachgroup will bring itsown robot base.Note1: When buyingth...
Board        Note: All the pins inside               the shaded areas are               connected together.connectivity
Power Circuit Main      VoltagePower      Regulat                     5 voltsource       or                     Capacito  ...
Power Circuit   Note: The same like                the previous slide, just                another perspective.
The Board
PIC 18 pins map  Port A         Port BAnalog Input    Digital I/O    Port A  Port C        Port C Digital I/O   Digital I/O
Connecting PIC 18 Resistor  Capacit    or      Capacit              Crystal       orsNote: Sometimes you will need to add ...
Start ResetNote: You need the Start/Reset sercut to give the microcontroller the signal to start/restart the program. You ...
The Board
The H-BridgeWhy do we need the H-bridge ?
The H-BridgeNote: As and ENs areinputs from the MicroController and Ys areoutputs to the motors.
H-Bridge Logic1             +1             -0
H-Bridge Logic0             -1             +1100
Connecting The H-Bridge               Pin               C0                                   Pin               Pin        ...
Complete Board
What You LearnedRobot requirements (Softwares and Hardwares)How to make the power circuitHow to connect your PIC18 chipHow...
MPLABPort APort A
Hello World - LED ON/** I N C L U D E S **************************************************/#include "p18f2520.h"/** D E C ...
Hello World - Blinking LED/** I N C L U D E S **************************************************/#include "p18f2520.h"#inc...
DirectionsPORTC =   C7          0    RM +                C6    RM -                       C5    RM E                      ...
Directions         PORTC =       0   RM +   RM -   RM E   0   LM -   LM +   LM Eint moveForward =      0    1      0      ...
Running The Robot/** I N C L U D E S **************************************************/#include "p18f2520.h"/** D E C L A...
Timing/** I N C L U D E S **************************************************/#include "p18f45k20.h"#include "delays.h"/** ...
What You LearnedHow to start your first projectHow to define the Input and the output portsHow to Time Control your output
Problem        Robot with Touch Sensor        Our Robot IR SensorWall
IR SensorOperating Voltage 4.5v - 5.5v (red and black)Distance 4cm - 30cmAnalog output (White Cable)Note: The white cablew...
IR Sensor Note: if the distance is less than 4cm the Sensor gives back wrong measuring.Note2: Because theresponse time for...
PIC 18 pins map  Port AAnalog Input    Port A
Connecting the IR Sensors  Center Sensor (AN0)   Left Sensor (AN1)  Right Sensor (AN2)
Using The AD Convertervoid setSensor(sensorChannel){    switch (sensorChannel)    {         case 0:// channel AN0 for Cent...
ADCON0                                                        STATUS   ON/OFF                         CHANNEL NUMBER BITS ...
void setupAD(){    ADCON1 = 12; //This sets the chip so that AN0, AN1, AN2 are analog. Instructions for this can be found ...
How to use it in the main                                       Note: The Values for FarRange andint farRange = 70;       ...
What You learnedThe Usage of SensorsHow to use Analog IR sensorMaking The right diction                           Note: Th...
SPECIAL THANKSRobotic Club Advisor   •Dr. Ben ChoiRobotic Club Vise President   •James Hurst Our FaceBook Group : Louisian...
Upcoming SlideShare
Loading in …5
×

Intro2 Robotic With Pic18

606 views

Published on

Presentation for The robotic club introductory meeting

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
606
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Intro2 Robotic With Pic18

  1. 1. Intro to Robotics Moayad H. AlmohaishiLouisiana Tech MS computer science President of Louisiana Tech Robotic Club
  2. 2. ROBOTIC 2010Video Deleted to reduce the file size. I will add it soonto Youtube.
  3. 3. What you need to start MPLAB Programming IDE (need windows OS)• http://www.microchip.com/stellent/idcplg?IdcService=S S_GET_PAGE&nodeId=1406&dDocName=en019469 &part=SW007002 MPLAB C compiler for PIC18 MCUs• http://www.microchip.com/stellent/idcplg?IdcService=S S_GET_PAGE&nodeId=1406&dDocName=en534868 PIC18F2520 Data Sheet• http://www.microchip.com/wwwproducts/Devices.aspx ?dDocName=en010277
  4. 4. Programming tool
  5. 5. PartsPrototype BoardWiresPIC 18 MicroprocessorCapacitorsResistorsVoltage regulatorLEDsBattery6-pins headersSensors
  6. 6. Parts4Mhz CrystalH-Bridge / Motor ControllerThe Base(Chassis)- Eachgroup will bring itsown robot base.Note1: When buyingthe base, put in yourmind the maze size.and the way the basemove.Note2: a sample of themaze is available in thesecond floor ofNethken Hall
  7. 7. Board Note: All the pins inside the shaded areas are connected together.connectivity
  8. 8. Power Circuit Main VoltagePower Regulat 5 voltsource or Capacito Resistor LED r Ground
  9. 9. Power Circuit Note: The same like the previous slide, just another perspective.
  10. 10. The Board
  11. 11. PIC 18 pins map Port A Port BAnalog Input Digital I/O Port A Port C Port C Digital I/O Digital I/O
  12. 12. Connecting PIC 18 Resistor Capacit or Capacit Crystal orsNote: Sometimes you will need to add a resistor between the Pin10 and the crystal. for more information look at the PIC18F2520Data Sheet.
  13. 13. Start ResetNote: You need the Start/Reset sercut to give the microcontroller the signal to start/restart the program. You can adda push button if you want a restart button
  14. 14. The Board
  15. 15. The H-BridgeWhy do we need the H-bridge ?
  16. 16. The H-BridgeNote: As and ENs areinputs from the MicroController and Ys areoutputs to the motors.
  17. 17. H-Bridge Logic1 +1 -0
  18. 18. H-Bridge Logic0 -1 +1100
  19. 19. Connecting The H-Bridge Pin C0 Pin Pin C6 C1 LM + RM + LM - RM - Pin Pin C5 C2 PinNote: LM = Left C4Motor, RM = RightMotor
  20. 20. Complete Board
  21. 21. What You LearnedRobot requirements (Softwares and Hardwares)How to make the power circuitHow to connect your PIC18 chipHow to connect the H-Bridge
  22. 22. MPLABPort APort A
  23. 23. Hello World - LED ON/** I N C L U D E S **************************************************/#include "p18f2520.h"/** D E C L A R A T I O N S ******************************************/void main (void){ TRISC = 0b01111111; // PORTC bit 7 to output (0); bits 6:0 are inputs (1) LATCbits.LATC7 = 1; // Set LAT register bit 7 to turn on LED while (1) Note1: You need to ; include the specific library of the PIC18 you} are using. Note2 : Use the Note3 : Use The register TRIS to define function LAT to define the output pins and the the output value of a input pins in the Port. specific pin
  24. 24. Hello World - Blinking LED/** I N C L U D E S **************************************************/#include "p18f2520.h"#include "delays.h"/** D E C L A R A T I O N S ******************************************/void main (void){ TRISC = 0b01111111; // PORTC bit 7 to output (0); bits 6:0 are inputs (1) while (1){ LATCbits.LATC7 = 1; K // Set LAT register bit 7 to turn on LED Delay1KTCYx(50); // Delay 50 x 1000 (1k) = 50,000 cycles; 50ms @ 4MHz LATCbits.LATC7 = 0; // Set LAT register bit 7 to turn on LED Delay1KTCYx(20); // Delay 50 x 1000 (1k) = 50,000 cycles; 20ms @ 4MHz} Note: To use the delay ; function, you have to include the delay} libraryPut your Note: application inside the While(1) loop to make it run forever.
  25. 25. DirectionsPORTC = C7 0 RM + C6 RM - C5 RM E C4 C3 0 LM - C2 LM + C1 LM E C0
  26. 26. Directions PORTC = 0 RM + RM - RM E 0 LM - LM + LM Eint moveForward = 0 1 0 1 0 0 1 1int moveBackward = 0 0 0 1 1 0 1 1int turnLeft = 0 1 0 1 0 0 1 0int turnRight = 0 1 0 0 0 0 1 1
  27. 27. Running The Robot/** I N C L U D E S **************************************************/#include "p18f2520.h"/** D E C L A R A T I O N S ******************************************/void main (void){ int moveForward = 0b01010011; int moveBack = 0b00110101; int turnLeft = 0b01010010; int turnRight = 0b01000011; TRISC = 0b00000000; // All PORTC bits to output (0) PORTC = moveForward ; // set PORTC bits to 0b10100011 while (1) ; Note : Use the register PORT to give or read a value from/to all the} pins in the specified Port. Note : PORTA, PORTB, PORTC
  28. 28. Timing/** I N C L U D E S **************************************************/#include "p18f45k20.h"#include "delays.h"/** D E C L A R A T I O N S ******************************************/void main (void){ int moveForward = 0b01010011; int moveBack = 0b00110101; int turnLeft = 0b01010010; int turnRight = 0b01000011; TRISC = 0; // All PORTC bits to output (0) (using the dismal system ) PORTC = moveForward ; Delay1KTCYx(50); // Delay 50 x 1000 (1k) = 50,000 cycles; 50ms @ 4MHz PORTC = turnLeft ; Delay1KTCYx(50); // Delay 50 x 1000 (1k) = 50,000 cycles; 50ms @ 4MHz PORTC = turnRight ; Delay1KTCYx(50); // Delay 50 x 1000 (1k) = 50,000 cycles; 50ms @ 4MHz PORTC = moveBack ; Delay1KTCYx(50); // Delay 50 x 1000 (1k) = 50,000 cycles; 50ms @ 4MHz while (1) ;} Note: Think about how this robot will be moving
  29. 29. What You LearnedHow to start your first projectHow to define the Input and the output portsHow to Time Control your output
  30. 30. Problem Robot with Touch Sensor Our Robot IR SensorWall
  31. 31. IR SensorOperating Voltage 4.5v - 5.5v (red and black)Distance 4cm - 30cmAnalog output (White Cable)Note: The white cablewill go to the MicroController. And theRed to the Regulated5v we created. and theblack to the ground.Note2: The responsetime for this IR Sensoris 39ms. which is tooslow for a movingrobot.
  32. 32. IR Sensor Note: if the distance is less than 4cm the Sensor gives back wrong measuring.Note2: Because theresponse time for theIR sensor is tooslow, you need todetect the distance asearly as you can. andput a safe fail backtechnique
  33. 33. PIC 18 pins map Port AAnalog Input Port A
  34. 34. Connecting the IR Sensors Center Sensor (AN0) Left Sensor (AN1) Right Sensor (AN2)
  35. 35. Using The AD Convertervoid setSensor(sensorChannel){ switch (sensorChannel) { case 0:// channel AN0 for Central Sensor ADCON0 = 1; break; case 1: // channel AN1 for Right Sensor ADCON0 = 5; //101 break; case 2: // channel AN2 for Left Sensor ADCON0 = 9; //1001 break; } Note2: We create the} Function SetSensor to make it easer for us to debug and understand the code.
  36. 36. ADCON0 STATUS ON/OFF CHANNEL NUMBER BITS BIT BITNote2: if you need to understand more about the Analog toDigital Converter’s registers read about it in the microcontroller Data Sheet.
  37. 37. void setupAD(){ ADCON1 = 12; //This sets the chip so that AN0, AN1, AN2 are analog. Instructions for this can be found inthe chip documentation. p 230 ADCON0 = 0; //Make sure ADC settings are 0 ADCON2 = 164; //this sets Right justified. Bit 6 is NC (0), Bits 5-0 adjust time (Bits 5-0 are 100100)}void enableAD() // You don’t need this function, we already set our ADON to 1 in the function SetSensor() I put itjust to explain what you can do.{ Note: Enable the AD ADCON0bits.ADON = 1; //Enables the A/D converter buy changing the pit} ADON value to 1 andvoid listenToAD() disable it by changing{ the value to 0; ADCON0bits.GO_DONE = 1; //Like the start button for the converter. while(ADCON0bits.GO_DONE == 1) //Wait until the ADC is finished. GO_DONE will change to 0 and theloop will end { //do nothing here }}
  38. 38. How to use it in the main Note: The Values for FarRange andint farRange = 70; CloseRange is just for explaining. You willint closeRange = 150; need to figure out the best values for yourint centralSensor, rightSensor, leftSensor; robot. ownsetSensor(0); Note: The values from the AD will listenToAD(); be stored in the Register ADRES, if you need to compare the centralSensor = ADRES; distance from the sensors you if (centralSensor < farRange) need to store the value to a variable or your ADRES will be PORTC = moveBack; overwritten. if (centralSensor > farRange && SC < clsoeRange) PORTC = turnLeft; if (centralSensor > closeRange) PORTC = moveBackward;
  39. 39. What You learnedThe Usage of SensorsHow to use Analog IR sensorMaking The right diction Note: The Code I provided is not meant to be running 100%, it is explanatory code ONLY. You will need to define your functions and variables correctly.
  40. 40. SPECIAL THANKSRobotic Club Advisor •Dr. Ben ChoiRobotic Club Vise President •James Hurst Our FaceBook Group : Louisiana Tech Robotic Club

×