Servo, serial speeds and resonator question

trevorwright0

New Member
Hi, I've poured over these forums lots before but I guess this is my first post here! I guess I've always found the answer here before needing to post a question! Greetings!

I've used Picaxe 08's for a long time but just for VERY simple things...

This is my most complex project so far, so don't laugh...

I have a 14M2 hooked to a SparkFun Serial enabled 16x2 LCD, a servo and a SparkFun thermocouple with breakout board with the MAX31855K chip.

I've got everything working and have been playing around with my program.

Obviously, that's three serial devices all at the same time, and I've noticed my servo is kind of buzzing until I stop the LCD and stop using so many sertxd commands, which makes sense.

My first question is,

If I increase the resonator higher, will that help it process all the serial interfaces better? Can you overheat these chips like overclocking a computer?

My second question is,

Once I've moved the servo to the desired position, is there a way to terminate communication with it? There is no actual load on the servo, it is sliding a metal plate that will just rest there once in position.

Otherwise I think I'll keep the LCD off until I want to view it, then just have a button that maybe shuts off the temperature sensor and/or servo.

Thanks in advance!
 

lbenson

Senior Member
Welcome to the forum.

There are often glitches with the SERVOPOS command, especially with sertxd and other serial commands, which require precise timing and can interfere with other commands which also require precise timing. For Servos, one reliable alternative is to use the pulsout command. The code that follows is a sample that I have used since 2008--I attribute its clunkiness (e.g., mixing of "b#" variables with symbols) to its age, but it has worked well for me.
Code:
servoOut:  ' smoothly move from lastSpot
  ' activeSpot is where we want to move to, lastSpot is where we are
  ' activeServo is the pin number for the servo we want to move
  ' uses b2, b3, and b4 as scratch variables
  b2 = activeSpot - lastSpot
  b3 = 1
  if activeSpot < lastSpot then
    b2 = lastSpot - activeSpot
    b3 = $FF   ' minus one
  endif
  sertxd ("|",b1," ",#b2, " ", #b3, " ", #lastSpot, " ", #activeSpot,13,10)
  activeSpot = lastSpot
  for b4 = 1 to b2       ' move smoothly to new activeSpot
    activeSpot = activeSpot + b3
    pulsout activeServo,activeSpot
    pause 20
    pulsout activeServo,activeSpot  ' twice seems to make it work
    pause 20
  next b4
  return
Its one trick is that it uses the value $FF to effectively subtract 1 when moving to a lower servo position one step at at time.
 

trevorwright0

New Member
Welcome to the forum.

There are often glitches with the SERVOPOS command, especially with sertxd and other serial commands, which require precise timing and can interfere with other commands which also require precise timing. For Servos, one reliable alternative is to use the pulsout command. The code that follows is a sample that I have used since 2008--I attribute its clunkiness (e.g., mixing of "b#" variables with symbols) to its age, but it has worked well for me.
Code:
servoOut:  ' smoothly move from lastSpot
  ' activeSpot is where we want to move to, lastSpot is where we are
  ' activeServo is the pin number for the servo we want to move
  ' uses b2, b3, and b4 as scratch variables
  b2 = activeSpot - lastSpot
  b3 = 1
  if activeSpot < lastSpot then
    b2 = lastSpot - activeSpot
    b3 = $FF   ' minus one
  endif
  sertxd ("|",b1," ",#b2, " ", #b3, " ", #lastSpot, " ", #activeSpot,13,10)
  activeSpot = lastSpot
  for b4 = 1 to b2       ' move smoothly to new activeSpot
    activeSpot = activeSpot + b3
    pulsout activeServo,activeSpot
    pause 20
    pulsout activeServo,activeSpot  ' twice seems to make it work
    pause 20
  next b4
  return
Its one trick is that it uses the value $FF to effectively subtract 1 when moving to a lower servo position one step at at time.
K thanks I'll try playing with what you gave me and see if I can get it to work

So does increasing the resonator speed help with something like this or not really. Part of me thinks it might make things less reliable idk.
 

lbenson

Senior Member
Increasing the clock speed of the M2 devices (no external resonator) with the SETFREQ command using the parameters given in the manual will not cause overheating. If your servo problem is caused by conflicts in use of the timers, I doubt that changing the frequency will help.

Using PULSOUT instead of the SERVO command should eliminate jitter. All of the servos I have used will hold the position they have been set to with PULSOUT (given no great at-rest torque on the servo arm)--I understand there may be some which do not.
 

hippy

Technical Support
Staff member
The issue probably is that servo timing pulses are being affected by the serial communications. Increasing operating speed may reduce the problems but it is difficult to tell without testing it.

Another solution is to adjust the serial commands so they only output a character at a time. This should limit the potential for collisions when serial data is being sent and servo pulses occur. This may be simplified by using #MACRO commands to minimise changes to the program.

Servos can be disabled once position as you asked; just issue the "SERVO <pin>, OFF" command.

It may also be possible to use PULSOUT control of the servo as suggested which should eliminate any servo jitter.

Another alternative if the servo is just moving between two or few positions is to have the PICAXE set a digital signal or serial command to say what the position should be and have a second PICAXE dedicated to placing the servo where it should be.
 
Top