Results 1 to 4 of 4

Thread: Picbasic serial commands

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    1

    Picbasic serial commands

    I am interfacing with a PIC16F84 using the RS232 serial port. I am using Picbasic to compile the software for the microcontroller.

    currently this is my MCU code -

    Code:
      Include "modedefs.bas"  ' Include serial modes
    si     var  PORTA.0
    pos    var  byte
    servo  var  byte
    cont   var  byte
    trisb = 0  'make all of port B outputs
    
    start:
      serin si,N2400,servo,pos
    for cont = 0 to 50
      pulsout  servo,pos
      pause    15
    next       cont
      goto     start
    It is to control an array of servo motors.

    There is a problem with the code, in that when i send the servo and pos data to the chip, it pulses the servos 50 at the required rate. Then it stops and the servo can move out of place again.

    Is there any way i can create a loop that checks for any data coming in. If not it pulses it again before looping back, if there is data, it collects it, changes the values of the variables accordingly, luses, and then loops.

    Thanks

    Harry

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Picbasic serial commands

    This really should be in the Other Basic forum, but ...

    There are two ways of holding the servo in its current position:

    1) If you're controlling the servo directly (not through a servo controller chip) - keep DC on the last pair of poles.

    2) Using a selsyn (or other position sensor), ALWAYS turn the servo to the required position with a voltage proportional to the error. If it's in the right position the voltage will be 0. As soon as it moves it'll get a pulse driving it in the opposite direction. (You don't even need a servo with this method - any DC motor will give you an accuracy of around 14-16 bits. That's about 1 part in 10^12 - it should be accurate enough for any real-world use. This is the method used to drive the 5 axes of the Zeiss planetarium projector in the Hong Kong Space Museum.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Picbasic serial commands

    Quote Originally Posted by Al42
    This really should be in the Other Basic forum, but ...
    Agreed.

    Moved

  4. #4
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Picbasic serial commands

    Is the drive tuned correctly?
    When the drive is tuned to the motor you should have a stiff shaft (no comments from the peanut gallery please)
    The motor should not drift unless the load is heavier than then the motor can stabilize. Sounds like you may have some slop.
    How much is the motor moving out of place?
    Last edited by gtilles; Apr 10th, 2007 at 01:47 PM.
    Truly, you have a dizzying intellect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width