Kategorie: Elektronik mit PICAXE und Arduino
Zugriffe: 1975

SERVODELAY

In meinem neuen Boot wird ein Klappschnorchel eingebaut werden. Für die Umsetzung des Antriebs hatte ich mir einige Varianten überlegt, bin zum Schluss bei einer ganz normalen Ansteuerung mittels Servo hängen geblieben, dies erschien mir die einfachste Möglichkeit. Ein Hauptproblem sollte allerdings die Servoansteuerung als solche sein. Ich wollte das Servo nicht einfach ansteuern weil es dann zu schnell gelaufen wäre, es musste also eine "Bremse" her. 

Nach ein bisschen googlen habe ich auch eine passende Lösung mit meinem Lieblingschips gefunden: Auf der Seite http://www.diyrc.com/ habe ich eine kleine Schaltung nebst Programm gefunden, die mit einem PICAXE ein Servo verzögert. Die Schaltung hat einen Ein- und einen Ausgang. Am Eingang wird ein normaler Empfänger angeschlossen, am Ausgang das entsprechende Servo. Mit einem Poti kann man die Geschwindigkeit der Verzögerung einstellen. Die Signallänge wird 1:1 durchgeschliffen und nicht begrenzt. Leider kann die Geschwindigkeit während des Betriebes nicht verändert werden, das Poti wird nur beim Einschalten eingelesen.

Ich habe die Schaltung mal in Eagle neu nachgezeichnet und auch ein entsprechendes Board entworfen. Bitte beachten, es gibt keinen Programmiereingang auf der Platine, der PICAXE muss also separat bespielt werden. 

DAS PROGRAMM

 

'Radio control servo slowdown using PICAXE-08M

'Kevin Goom, 17 October 2005

'Updated for new Picaxe S/W (changed loop to loop1, restart to restart1)

'

'

'PICAXE-08M connections are:

' Leg 1            +5V

' Leg 2 (Serial in) Tie to Ground through 10K resistor

' Leg 3 (In4/Out4)  Wiper of 10K potentiometer connected to +5V & ground

' Leg 4 (In3)       Pulse input from radio receiver

' Leg 5 (In2/Out2)  Pulse output to servo

' Leg 6 (In1/Out1)  Mode indicator output

'1/2 second flash = no valid signal

'Steady on = pass-through (no servo slowdown)

'Flicker = servo slowdown mode

' Leg 7 (Out0/Serial Out) NC

' Leg 8 Ground

 

symbol Delay=b8                                'Name the delay factor

symbol PWin=w0                                 'Name the input pulse length

symbol PWout=b2                                'Name the output pulse length

symbol PWinPrev=b3      'Name the length of the prior input pulse length

symbol PWinErr=b6       'difference between input &output pulse lengths

symbol skip=b4          'counter for skipping "Delay" times

 

restart1:

  Skip=0

  high 1

  servo 2,135          'Center the servo initially and on input pulse loss

  Pause 500            'Wait 1/2 second initially

  toggle 1

  readadc 4,Delay      'Read the voltage from the delay potentiometer

  pulsin 3,1,PWin      'Measure the input pulse width initially

  if PWin<75 or PWin>225 then restart1   'Go back if no valid input detected

  high 1

  low 2                 'Stop the servo command if valid input detected

  PWinPrev=PWin 'Initially set the prior pulse width to current pulse width

  if Delay<3 then StraightThru    'If delay pot set near zero skip slowdown

  Delay=Delay/60        'Set 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)

  PWout=PWin            'Set output pulse to input pulse initially

 

loop1:

  toggle 1

  PWinPrev=PWin         'Reset the prior pulse width

  pulsin 3,1,PWin                       'Measure the input pulse

  if PWin<75 or PWin>225 then restart1   'Go back if no valid input detected

  PwinErr=PWin-PWOut

  if PWinErr<2 or PWinErr>254 then StayPut  'Add 2 units of hysteresis

  if PWout<PWin then MoveUp

  if PWout>PWin then MoveDown

 

MoveDown:                'Routine to decrease the output pulse width

  if skip>=Delay then Skip1     'Loop to delay change to Delay x 20ms

     Skip=Skip+1

     goto Skip2

 Skip1:

    Skip=0

    PWout=PWout-1

 Skip2:

    pulsout 2,PWout     'Send the output pulse to the servo

    goto loop1           'Return to re-measure the input pulse

 

MoveUp:                        'Routine to increase the output pulse width

  if skip>=Delay then Skip3   'Loop to delay change to Delay x 20ms

     Skip=Skip+1

     goto Skip4

 Skip3:

    Skip=0

    PWout=PWout+1

 Skip4:

    pulsout 2,PWout           'Send the output pulse to the servo

    goto loop1                 'Return to re-measure the input pulse

 

StayPut:                       'Routine to send the same output pulse

  pulsout 2,PWout

  goto loop1                   'Return to re-measure the input pulse

 

StraightThru:

  pulsin 3,1,PWin

  if PWin<75 or PWin>225 then restart1   'Go back if no valid input detected

  PwinErr=PWin-PWinPrev

  if PWinErr<2 or PWinErr>254 then Stay 'Add 2 units of hysteresis

  pulsout 2,PWin

  PWinPrev=PWin

  goto StraightThru:                 'Return to re-measure the input pulse

  Stay:

  pulsout 2,PWinPrev  'Set output pulse to input pulse

  goto StraightThru:                 'Return to re-measure the input pulse