+ Reply to Thread
Results 1 to 14 of 14

Thread: PIC basic and Servo Motor!

  1. #1
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default PIC basic and Servo Motor!

    Hi All ,

    i have a small R/C servo motor and i have tested it on my pic 16f877 board ,

    it worked but it moves with pulses : i mean to move from point A to point B it go there with 2 strokes not in one as usual.

    my program is :

    DIM POS AS WORD
    PINT = PORTC.1
    PORTC=0
    POS1=1500
    POS2=3000
    SERVO PIN,POS1
    DELAYMS 2000
    SERVO PIN,POS2


    SO WHAY THAT HAPPNED ,

    thank you


  2. #2
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,792

    Default

    You need to send a pulse every 20mS and so you need something like,

    Code:
    	for i = 0 to 100
    		servo pin,pos1
    		delayms 18
    	next i
    	for i = 0 to 100
    		servo pin,pos2
    		delayms 18
    	next i
    
    BTW, servo pulses normally go from 1mS to 2mS - not 1.5-3.

    Mike.

  3. #3
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default

    i'll try this and tell

  4. #4
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default

    thank you it works very well , but now i need to do something else ,

    suppose that i need to know the position of my servo , is it possible with picbasic.

    so i need my microcontroller to tell me the current position and it's value and sure i can dispaly it with LCD

    hope you can tell me how to do that

  5. #5
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,775

    Default

    Quote Originally Posted by watzmann
    thank you it works very well , but now i need to do something else ,

    suppose that i need to know the position of my servo , is it possible with picbasic.

    so i need my microcontroller to tell me the current position and it's value and sure i can dispaly it with LCD

    hope you can tell me how to do that
    It's not possible with normal servo's they are input only - but there should be no need to know, you tell it where to go and it goes there, so you should know where it is at all times.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  6. #6
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default

    i'll fix ultrasnoic sensor on it so i need to program my pic to take an action when the sensor detect soemthing ,so i thought to get the position of the servo and to adjust my robot position to that one .

    otherwise how i can do that

  7. #7
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,775

    Default

    Move the sensor to a specific point, then check to detect something, repeat for the entire sweep of the sensor - everytime you check you know where the servo is because you've just set it's position.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  8. #8
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default

    what about the time , will take time when it stop and move again , or the normal eye will not analyies that

  9. #9
    ssylee Newbie
    Join Date
    May 2007
    Location
    Vancouver, Canada
    Posts
    189

    Default

    The servo basically moves to an angle state indicated by the pwm that you're sending to it. As long as it's receiving the same PWM input, the servo would not move until it receives a PWM of a different length.

  10. #10
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default

    is it possible to know the range of pulses of my servo.

  11. #11
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default

    Pommie told that it's going from 1ms to 2 ms.......but i think it's differant from one servo to another

  12. #12
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,775

    Default

    Quote Originally Posted by watzmann
    Pommie told that it's going from 1ms to 2 ms.......but i think it's differant from one servo to another
    It may be slightly different, but it will be very similar - and it's not 'cast in stone', you can usually exceed the original specs by a huge amount, and greatly increase the movement range. Take one of your servos and test it.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  13. #13
    watzmann Bad
    Join Date
    Nov 2003
    Location
    Egypt
    Posts
    260

    Default

    i tried my rader using servo motor and a photosensor.

    it works well ,

    my program go like that

    ////for i = 0 to 100
    servo pin,pos1
    delayms 13
    next i

    ///if sensor = 1 then goto LED, to turn on a led for 2 seconds

    and i repeated this part for 10 times and each time i'm changeing the value of the position untill i reach the final destination , after each step i scan the sensor as you notice in the if statment

    waiting for your comments.
    Attached Images
    • File Type: jpg 1.JPG (471.1 KB, 301 views)

  14. #14
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,701
    Blog Entries
    5

    Default

    It's like ebay, always something fun in the background photo. Acne cream and a big glass of who knows what...
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

+ Reply to Thread

Similar Threads

  1. Need Servo And Basic Stamp Ii Help
    By ltmhall in forum Robotics Chat
    Replies: 15
    Latest: 11th October 2006, 11:40 AM
  2. Just the basic but not simple: Control velocity of DC motor.
    By wonbinbk in forum General Electronics Chat
    Replies: 1
    Latest: 1st May 2005, 10:46 PM
  3. DC Motor Postion control help (servo)
    By lompa in forum Robotics Chat
    Replies: 6
    Latest: 24th October 2004, 03:16 PM
  4. Automated blinds, project basic principle ideas please
    By lompa in forum Electronic Projects Design/Ideas/Reviews
    Replies: 1
    Latest: 28th August 2004, 01:44 AM
  5. Motor Control
    By Don Case in forum General Electronics Chat
    Replies: 18
    Latest: 19th December 2003, 12:41 PM

Tags for this Thread