ROBODYSSEY SYSTEMS LLC

Product Catalog
Code Page
Policies
Gallery
Whats New
Press Releases
Resources
Links
Contact Us
About Us
Press

Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery

The communication cable to the PC is made as specified in the PicBasic Compiler Manual.
1.0K DB9
pin --/\/\/\---- RS-232 RX Pin 2
GND ------------ RS-232 GND Pin 5
This Project uses a 10k pot hooked to a voltage divider board to directly rotate a servo. One of the cool things here is how the program first calibrates the pot. It starts by telling you to rotate the pot and collects the min and max value. it then calculates the spread and produces a multiplier. It then uses this value to calculate servo positions relative to pot position.
See "PicDisplay" for more details on serial hookup.

	
****** Driving a servo directly **************
'********************************************** 
'@ Platform: PicBasic 
'@ Version: 1.0
'@ Author: Brian Patton (brianp@robodyssey.com)
'     Robodyssey Systems, LLC. - www.robodyssey.com
'@ Last Updated: Feb 19, 2004 
'*********Materials*****************************
' 1 Robodyssey PicPac MotherBoard
' 1 Pic16F876 or similar
' 1 Voltage Divider board
' 1 Variable Resistor (pot)
' 1 Servo connected to pin B4
' PicBasic Compiler and a programmer
'***********************************************
' Register Locations
Symbol  TRISA  = $85       ' Register Location of TRISA
Symbol  ADCON0 = $1F       ' Register location of ADCON0
Symbol  ADCON1 = $9F       ' Register Location of ADCON1
Symbol  ADRESH = $1E       ' Register Location of ADRESH
'***** Variables *******************************
Symbol MinPot = b4         'Value for the minimum of the pot
Symbol MaxPot = b5         'Value for the maximum of the pot
Symbol RPot = b6           'Range between Min and Max
Symbol ServoPos = b7       'Pulse the servos will use
symbol value = b8          'variable to hand off to
Symbol x = b1              'just a counter
'*****Initiation********************************
Init:
 Dirs = %11111111              ' Set all Port B to output
 
'*****Main Code Block Area**********************
'********* Calibrate Pots **********************
 Serout 0,N2400,("Calibate Pots",10,13) 'Display "Calibrate Pots" on the computer screen
 Pause 3000
Start:
  poke TRISA, %11111111      'Set all PortA Input
     poke ADCON1, %00000010 'xxxx0010 - PortA 0-4 analog inputs, 5-7 digital inputs 
                             '0xxxxxxx Sets result to Left justified
                             '1xxxxxxx Sets result to Right justified
Cal:
 b3 = 1                         'give it some start points
MaxMod:
 MaxPot = b3                    'give it some start points
MinMod:
 MinPot = b3                    'give it some start points
for x = 1 to 20                 'Give you time to turn the pot
     poke ADCON0, %11000001  'Set A/D to RC Osc, Channel 0, A/D converter ready
                                                'xx000xxx-Chan 0(RA0), xx001xxx-Chan 1(RA1),
                                                'xx010xxx-Chan 2(RA2), xx011xxx-Chan 3(RA3),
                                                'xx100xxx-Chan 4(RA4), xx101xxx-Chan 5(RA5),
                                                'xx110xxx-Chan 6(RA6), xx111xxx-Chan 7(RA7),
 
     b0 = %11000101                    'xxxxx1xx - on, xxxxx0xx - off
        Poke ADCON0,b0                 ' Turn on the conversion at Bit 2
 
calfin: 
  Pause 5
        Peek ADCON0,b0
   If b0 = %11000101 Then calfin       ' Wait for low on bit-2 of ADCON0, conversion finished
     Peek ADRESH,b3
  If b3 > MaxPot Then MaxMod           'Collect min and max values
   
  If b3 < MinPot then MinMod           'Collect min and max values
   
   Serout 0,N2400,("Min ",#MinPot," Max ",#MaxPot,10,13) 'Display min and max values on your screen
  pause 50
next
 Serout 0,N2400,("The Final Min ",#MinPot," Max ",#MaxPot,10,13) 'Display final min and max values on your screen 
 Pause 2000
 RPot = MaxPot - MinPot                             'Calculate the range
 Serout 0,N2400,("The Pot Range = ",#RPot,10,13)    'Display the Range
 Pause 2000
 RPot = 1200/RPot 'The 1200 comes from differece of the min pulse width and max pulse width recomended by the
                  'Servo manufacture time 10 in 10uSec units. The 10X is to keep the answer a 8 bit integer.
                  'So, a servo with a rated pulse of 0.0009 to 0.0021 is 90 to 210 ten uSec units.
                  'That is a difference of 120 uSec units. Times 10 is 1200.
      
 Serout 0,N2400,("The Multiplier = ",#RPot,10,13)   'Display the value from above
 Pause 2000
 Serout 0,N2400,("Calibration Finished",10,13)     'Display "Calibration Finished"
 Pause 2000
 
'******** Move the Servo **********************
AD0chk:
     poke ADCON0, %11000001  'Set A/D to RC Osc, Channel 0, A/D converter ready
                                               'xx000xxx-Chan 0(RA0), xx001xxx-Chan 1(RA1),
                                               'xx010xxx-Chan 2(RA2), xx011xxx-Chan 3(RA3),
                                               'xx100xxx-Chan 4(RA4), xx101xxx-Chan 5(RA5),
                                               'xx110xxx-Chan 6(RA6), xx111xxx-Chan 7(RA7),
 
     b0 = %11000101               'xxxxx1xx - on, xxxxx0xx - off
        Poke ADCON0,b0            ' Turn on the conversion at Bit 2
 
AD0fin: 
  Pause 5
        Peek ADCON0,b0
   If b0 = %11000101 Then AD0fin  ' Wait for low on bit-2 of ADCON0, conversion finished
     Peek ADRESH,b3
 
'************ convert value and ******************        
'************ drive the Servo ********************
 value = MaxPot + 10           'Hand over the value and keep it from ever becoming 0
 ServoPos = value - b3         'Subtract found value from the Max possible
 ServoPos = ServoPos / 10      'Correct the 10x thing from above
 ServoPos = ServoPos * RPot    'Multiply it by the range
 ServoPos = 210 - ServoPos     '210 is the longest pulse in 10uSec intervals my servo will handle
  Pulsout 4, ServoPos          'Pulse the Servo
'*************************************************
 goto AD0chk                   'Start it all over again
 end

Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery

Robodyssey Systems manufactures Robot Kits including Autonomous Mobile Walking Robots, Wheeled Robots, Talking Robots, Expressive Robots, and Social Robots. We also sell Robotics Accessories including Nexcell NiMH AA Rechargeable Batteries, Nexcell NiMH AAA Rechargeable Batteries, Battery Holders, Velcro Straps for Battery Packs, Battery Chargers, Robot Grippers, Hobby Servos, Servos Modified for Continuous Rotation, Tail Wheels for all Rolling Robotic Platforms, Polyurethane Skate Wheels with Servo Adapter Hubs, Sharp IR Sensors and Adjustable Sensor Brackets, Sensor Cables, and Programming Cables. All of our Robot Kits can be purchased as easy to assemble robot kits or as fully assembled stationary or mobile robots. Robodyssey uses 1/8 inch aluminum and acetyl for most all of our mobile robot components and robotics accessories. We provide classroom training for teachers interested in integrating robotics, computer programming and electronics into the classroom.

We hope you enjoy our web site. Feel free to use any robotic resources. Robodyssey is your complete solution for Educational Robotics as well as Hobby Robotics.