Hello to the Community.
I have just completed a program using the "Servopos" command.
It is a system that positions a servo to two programmable positions, depending on the logic state of a control input. ("ON/OFF Servo")
Unfortunately, I am experiencing instability in the servo positions.
Is there a solution to avoid this problem?
Thanks.
I have just completed a program using the "Servopos" command.
It is a system that positions a servo to two programmable positions, depending on the logic state of a control input. ("ON/OFF Servo")
Unfortunately, I am experiencing instability in the servo positions.
Is there a solution to avoid this problem?
Thanks.
Code:
'----------------------------------------------------------------------------------
' SERVO_TR.bas - "ON/OFF" Servo - Servo "Tout ou Rien"
'
' V1.0 - 09/05/2022 - RGL
'
' Moves a servo to two preset positions, depending on the state of a logic input
' Servo signals adjustable from 0.75 ms to 2.25 ms
'----------------------------------------------------------------------------------
'
' TWO POSITION SETTING PROCEDURE
' °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
' - In Normal Mode (Input Mode=1), the LED is on.
' - Set the logic input (S_Pos) to 0V or 5V to select either servo position.
'
' - In Configuration Mode (Input Mode=0), the LED is blinking.
' - The state of the S_Pos input will determine which position you are setting !
' - Turn the potentiometer in either direction: The servo follows the movement.
' - When the desired position is reached the LED goes out after a few seconds.
' - Then, return the configuration input to normal mode (High)
' The LED lights up again and the new position is stored in Eeprom.
' The system returns to Normal Mode with the new programmed position.
' - Do the same for the other position by changing the state of the S_Pos input.
'----------------------------------------------------------------------------------
'PotADC gives values from 0 to 255
'ServoPos delivers pulse values from 75 to 225 (0,75msec to 2,25msec)
'Pulse = PotADC*59/100+75
'*** Programming Directives *******************************************************
' #SimSpeed 500
' #Terminal 4800 'Only used in test mode with messages Sertxd
'*** PICAXE Pinouts ***************************************************************
#Picaxe 08M2
' __ __
' Vcc o| U |o Gnd
' C.5 x|Rx Tx|> C.0 Led
' Config. C.4 >| |> C.1 Servo
' Position C.3 >| |< C.2 Pot
' -----
'*** In/Out pins ..................................................
Symbol Led = C.0 'Output Led
Symbol S_OUT = C.1 'Output Servo
Symbol Potar= C.2 'Input Pot
Symbol S_Pos = pinC.3 'Input Control Position (Left/Right)
Symbol Mode = pinC.4 'Input Mode (Normal/Calibration)
'*** Variables ....................................................
Symbol Position1 = b0 'W0 Position1 servo
Symbol Position2 = b1 'W0 Position2 Servo
Symbol PotADC = b2 'W1 Pot ADC Value
Symbol NewADC = b3 'W1 New ADC Conversion
Symbol _PotADC = b4 'W2 =PotADC/10
Symbol _NewADC= b5 'W2 =NewADC/10
Symbol Pulse = b6 'W3 Pulse value to servo
Symbol State = b7 'W3 Normal/Configuration
Symbol Flashing = b8 'W4 Counter for Led Flashing Frequency
Symbol Waiting = w5 'b10-11 Counter for Validation Delay
'*** Constants ....................................................
Symbol FrBlink = 10 'Flashing Frequency of the Led
Symbol TValid = 250 'Waiting Time for Validation
'==================================================================================
INIT:
Read 0,Position1 'Read Positions in Eeprom
Read 1,Position2
If Position1<75 Or Position1>225 Or Position2<75 Or Position2>225 then
Position1=170 'if values outside the limits of a servo
Position2=130 'Preset Values
Endif
Let Flashing=0
Let Waiting=0
Servo S_Out,150 'Servo Timer initialization
Servopos S_Out,150 '1,5 msec(NEUTRAL Position Equivalent at PotADC=128)
Pause 2000
'---------------------------------------------------------------------------
MAIN:
DO 'Main Loop
If Mode = 1 then 'NORMAL Mode
High Led
If S_Pos=0 then 'Read the Desired Position
Servopos S_OUT,Position1 'Servo to Position1
Else
Servopos S_OUT,Position2 'Servo to Position2
Endif
Else 'CALIBRATION Mode !
DO Until Waiting = TValid 'Configuration Loop
State = S_Pos
ReadADC Potar,PotADC
Pulse=PotADC*59/100+75 'Converting ADC to Pulse
Servopos S_OUT,Pulse 'Visualisation of the new position
_PotADC=PotADC/10 'Stabilisation of the inaccuracy
_NewADC=NewADC/10 'of the Pot ADC reading
If _PotADC=_NewADC then 'If Pot Position Unchanged
INC Waiting 'Increase Waiting Time (Until=TValid)
Else
NewADC=PotADC 'Reset of the Waiting Time
Waiting=0
Endif
INC Flashing
If Flashing=FrBlink then
Toggle Led 'Blinking Led
Flashing=0 'Reset cpt Led
Endif
LOOP 'Configuration Loop
Gosub Validation 'The position of the Pot is Stabilised
Endif
LOOP 'Main Loop
End
'=================================================================================
' --- SUBROUTINE ---
'=================================================================================
VALIDATION: 'Storage of the New Position in Eeprom
Low Led 'Waiting to Deselect Configuration Switch Mode !
DO
LOOP Until Mode = 1 'Mode=1 -->NORMAL Mode
High Led 'OK, Ready to return to Normal Mode
If State=0 then 'New position Writing in Eeprom
Position1=Pulse
Write 0,Position1
Else
Position2=Pulse
Write 1,Position2
Endif
Flashing=1 : Waiting=0 'Reset Counters
return 'to Normal Mode
'== END OF PROGRAM ================================================================