Servo decoder: a software for open decoder (V.2)
Note: manual adjustment is missing in english text.
Overview
- Servo for model construction are a cheap way to move objects on a layout.
Moreover, they allow for a realistic movements of things like:
- Signals, barriers, switches
Shed gates, doors, roofs (self opening)
Children, who whip at the playground
Photo enthusiast, who turns around while a train drives by. (and flashes!)
All possible item in an entertainment park
Moved humans - when drinking, working (e.g. painting, scythe mower, chimney sweeping), making love
Moved vehicles (steam roller, wheeled loader) and objects (water crane, excavator)
Search headlight, radar antennas
Segment turntable.
If open decoder V.2 is loaded with this software, then the simultaneous control of two servos is possible.
This software implements a full accessory decoder, the programming of the servos is done by means of CV (=Configuration variable). The control during normal operation is then simply done with the usual switch keys.
Theory: Control of a Servo
- Signals to the servo
A usual model construction servo has three 3 connections, current supply and the positioning line:- GND (usually black or brown)
- +5V (usually red)
- PWM (usually white or orange)
With the PWM line the position is defined. For this a signal with a repeatition rate of 20ms is used by. The active time of the PWM pulse lies between 1ms and 2ms. The actual position of the servos is determined by the length of the pulse, whereby 1ms equals completely left and 2ms equals completely right (thus the end positions). A pulse width of 1,5ms would therefore mean the central position. The curcuits inside the servo evaluates a potentiometer coupled with the lever to regulate the given position. - Generation of the signals
The necessary PWM signal can be produced simply with the timer of the AVR processor. This timer is programmed in such a way that it overflows at the pulse period PWM (20ms, fast PWM mode), Since the counter is 16 bits wide, the incoming clock to the counter must be predivided to acheive the overflow at 20ms. This is done with the setting of clkdiv=8, the counter is then running at 1MHz.
The OCR registers are used to define a threshold value for the counter. The associated output pin is high when the counter is between 0 and OCR, afterwards it goes low. Thus OCR is between 1000 and 2000 with the above mentioned clock rate, which corresponds to 1ms to 2ms.
The ATmega8515 comes with two OCR registers (at timer 1), which allows for the independant control of two servos.
On overflow of the timer an interrupt is issued. This interrupt triggers the recalculation of the current value for OCR depending upon the desired movement. Thus ervery 20ms a new ocr value is calculated .
- Positioning
The physical accuracy of a servos is approx. 0.2% with 90° way. The method described above (by means of timer programming and controlling the servos by an hardware pin) a reslution of 1us is acheived, i.e. for the range 1ms to 2ms this are 1000 steps, thus about 0.1%.
The upper and lower limit position are stored as integer [range 0..65535]. A storage as unsigned char [range 0..255] (only using the high byte) corresponds to an accuracy of 0,3°. - Time locus
The movement of the servos takes place between start and destination using a profile with pairs of location and time, which is put down as as integer (range [0 ... 255]). Intermediate steps are interpolated.
This time locus is normalized and is scaled during output according to the current settings of the servo. Thus the profile can be stored independantly of actual calibration.
This example shows the movement profile when opening a form signal. The signal is pulled up, then the flag man pauses and then pushes the signal open completely. In the end position it whips after.
This profile is put down as standardized list (range of values of the positions 0..255) of time and points of position.
The time in the profile is stored as 8-bit value in units of 0,02s, thus giving a range from 0 to 5,12s. Additionally there is an aspect ratio factor (servo.time_ratio), with which the profile can be stretched up to 21min.
There is a number of pre-defined profiles of motion: e.g. form signal, child whip, pendulum, barrier.
At the end of one movement a seamless subsequent movement can be activated. Naturally the following profile must be suitable for that (first positiion must match last position of previous profile). The predefined profiles are using 25 and 230 as endpoints, this allows for some headroom during the intermediate movement.
When used, this profile is converted according to the current start and stop positions. Thus the normalized profile is mapped to the current range. This is shown in the following graphic for three different pairs of endpoints:Interpolation der Verlaufskurve für verschiedene Min und Max-Punkte ⇒
Configuration with CV-variables
- In order to get the desired movement, the the decoder must be configured for the respective task.
The following things must be set:
- The start and stop positions of the servos: these depend on the installation situation.
- The desired operating mode: run back and forth individually in each case (like a switch) or permanent run (as e.g. with a whip), i.e. run back and forth again and again.
- The desired profile, both for running forth and back. The profile may be selected from a number of pre-defined profiles (e.g. signal, whip, barrier) or from one of up to four user defined profiles, which can be loaded into the decoder.
- The duration of each run.
- CV 545 (33): DECODER MODE
This CV specifies the mode of operation of the decoder. Depending on the mode of the decoder the meaning of the following CV's can change completely!CV 545: DECODER MODE 0 (*) turnout and switch decoder with feedback 1 Dual Servo decoder
(described here)2 multiposition servo decoder 3 Direct relay control (only with OpenDecoder3) 4 Relay control and dual servo decoder combined (only with OpenDecoder3) 8 DMX decoder 16 KirmesDecoder with motor and ligth control for round-abouts 32 Signaldecoder for Semaphores with dimming
A loaded software will not support all modes. If a non supported mode is selected, the decoder will flash with an error code: 6 fast flashes, pause.
In the following only the CV's for the MODE 1 and MODE 4 (Dual Servo) are described! - CV 552: Minimum value for servo 1 (*=64)
lower limit of movement, range 0 ... 255. This is in reality the high order byte of an integer, the corresponding low byte is CV 551 and normally doesn't need changing. - CV 554: Maximum value for servo 1 (*=192)
upper limit of movement, range 0 ... 255.
This is in reality the high order byte of an integer, the corresponding low byte is CV 553 and normally doesn't need changing. - CV 555: control settings servo 1 (*=0)
This CV specifies the reaction of the servo in principle.CV 555: Control Setting Bit: Meaning 0 movement behavior: *0 Key green activates run towards A
Key red activates run towards B1 red: Servo 1 stops after the next run towards B.
green: Servo 1 runs permanently A-B-A ...1 output behavior: *0 no action on outputs coupled to movements. 1 The output corresponding to the current servo movement is activated at the end to the movement. (this can be used for controlling the frog of a switch). 2 Manual operation (only for board version 3): *0 no tracers attached at the decoder, the connectors may be used for controlling an external relay. 1 Control locally by tracers possible. 3 Feedback connected (only for board version 3): *0 no feedback connected 1 feedback tracers connected.
Note: this option is not available together with manual operation.4 Manual Adjustment (only for board version 3): 0 no additional commands for adjustment *1 additional commands for adjustment of the servos. Step width according to CV579. 5 Continous servo control: *0 If there is actually no movement in progress, the control pulses to the servo are turned off. The servo will keep its position with the intrinsic force. 1 The servo pulses are always put out. The servo will continous to control its position: this results in more force, but sometimes you can hear noise from the servos. The current consumption will be higher, especially when there is force on the servo. 6 Init sequence (the option could reduce the unintentional power on movement.) (requires version > V0.11) *0 pulses are off at power up. 1 pulse line is steady high at power up, an then pulses are generated. 7 Extended Pulse Width
Some servos use a larger puls range than the pre-defined 1ms to 2ms range.*0 Servo control is performed in the range of 1ms to 2ms. 1 Servo control is performed in the range of 0.5ms to 2.5ms.
When the red key is pressed, the current cycle is finished completely, to avoid a discontinuity at the next start. Cyclic operation should always be terminated by a keystroke, never simply turn of power. - CV 556: number of repetitions servo 1 (*=0)
If CV555, bit 0 is set to 1 (permanent run), then this CV determines the number of the repetitions.CV 556: Repetition 0 Servo runs after activation in continuous operation (forever)
1..255 In the case of an activation the indicated number of complete A-B cycles are performed. - CV 558: movement and time locus "A" (*=5)
Here the movement profile is selected - enter the number of the desired time locus. This profile applies to the run "A" (i.e. the movement for the green key).
The curves in the table are stretched in time scale with the value of the time aspect ratio, the following plot a shown for time aspect ratio = 1.
The curves in the table are scaled with the value for minimum and maximum (CV552/553 resp. CV554/555). The following calculation is used:- output value = table code * (max - min)/255.
An output value of 0 corresponds to 1ms pulse duration, a value of 255 corresponds to 2ms pulse duration.CV 558: Time loci 0 no curve
reserved for adjustment.1 user specific curve 1
this curve can be put down with further CVs in the decoder.2 user specific curve 2
this curve can be put down with further CVs in the decoder.3 user specific curve 3
this curve can be put down with further CVs in the decoder.4 user specific curve 4
this curve can be put down with further CVs in the decoder.5 simple movement
This curve is a simple linear movement from min to max.
6 simple movement
This curve is a simple linear movement from max to min.7 soft movement
This curve is a simple linear movement with a small acceleration phase at the beginning and brake phase at the end.
8 soft movement
This curve is a simple linear movement with a small acceleration phase at the beginning and brake phase at the end.9 sinusoidal movement, direction A
The movement follows a sinusoidal curve within the range 0° to +180°. This movement is suitable together with the movement 10 for oscillating motions.
10 sinusoidal movement, direction B
The movement follows a sinusoidal curve within the range 180° to 360°. This movement is suitable together with the above movement for oscillating motions.11 special movement, direction A
This process is suitable together with movement 12 e.g. for a flip.
12 special movement, direction B 13 Form signal - HP0
This movemnent corresponds to closing a form signal or a barrier with after whip.
14 Form signal - HP1
This process corresponds to opening a form signal with after whip.
15 Form signal - HP1 - break
This process corresponds to opening a form signal with a short pause of the flag man
- CV 559: Time aspect ratio servo 1, movement "A" (*=1)
The loaded curve is stretched in time scale by this factor. - CV 560: movement and time locus "B" (*=6)
- CV 561: Time aspect ratio servo 1, movement "B" (*=1)
Parameter for servo 2 (ranges of values like above):
- CV 564 (52): Minimum value servo 2 (*=64)
(corresponding low byte:CV 563) - CV 566 (54): Maximum value servo 2 (*=192)
(corresponding low byte:CV 565) - CV 567 (55): Control settings servo 2 (*=0)
- CV 568 (56): Repetitions servo 2 (*=0)
- CV 570 (58): movement and time locus "A" (*=7)
- CV 571 (59): Time aspect ratio servo 2, movement "A" (*=1)
- CV 572 (60): movement and time locus "B" (*=8)
- CV 573 (61): Time aspect ratio servo 2, movement "B" (*=1)
- CV 579 (67): Step width for manual adjustment
This CV set the increment which is used for manual adjustments. (normally no change required).
- 1: The decoder requires 4096 steps for a full travel from min to max.
255: The decoder requires 16 steps for a full travel.
Parameter for loadable curves:
- CV 600-CV 647: Curve 1
The curves are put down as sequence of pairs from time and location points.- The time values are indicated in units of 20ms, i.e. 100 is will result in 2sec. If the duration is to be extended, CV559/561 or CV571/573 allow for a stretch of the curve over time.
- The location values range from 0 to 255 and are scaled to the output with the current minimum and maximum values of the used servo. Regardless of the calibration of the servo the movement characteristics of the servo stay the same.
- A maximum of 24 curve points (including endpoint) can be defined. A point with time = 0 denotes the endpoint of this curve.
- Example: Above curve No. 5 "linear movement A" would be coded as follows:
CV 600 0 CV 601 25 Starting point with (0; 25) CV 602 2 CV 603 128 Intermediate point with (2; 128) CV 604 4 CV 605 230 last point with (4; 230) CV 606 0 CV 607 0 (0; 0) = curve end
- CV 648-CV 695: Curve 2
- CV 696-CV 743: Curve 3
- CV 744-CV 791: Curve 4
- Open decoder does implement CV remapping, i.e. CV 513 is accessible also as CV1, CV514 as CV2 etc.
- All not indicated CV's may not be changed.
- See the feedback decoder for a description of the CV's for normal instructions and address settings.
Notes:
Decoder instructions
-
After the configuration of the servo decoder
it can be addressed like every other decoder simply via the accessory commands.
In the following the contents of CV555/CV567, bit 0 are assumed to be 0
(separate movements for red and green key).
Key | Effect |
---|---|
1 | Servo 1 rotates direction B, at the end of the movement output 1 is activated. |
2 | Servo 1 rotates direction A, at the end of the movement output 2 is activated. |
3 | Servo 2 rotates direction B, at the end of the movement output 3 is activated. |
4 | Servo 2 rotates direction A, at the end of the movement output 4 is activated. |
5 | output 5 permanently on, output 6 off. |
6 | output 6 permanently on, output 5 off. |
7 | output 7 permanently on, output 8 off. |
8 | output 8 permanently on, output 7 off. |
OpenDecoder 3 is already equipped with relays and has no separate outputs. The commands 5 to 8 are used for adjusting the servos without using CV's.
Key | Effect (only with OpenDecoder 3) |
---|---|
1 | Servo 1 rotates direction B, at the end of the movement output 1 is activated. |
2 | Servo 1 rotates direction A, at the end of the movement output 2 is activated. |
3 | Servo 2 rotates direction B, at the end of the movement output 3 is activated. |
4 | Servo 2 rotates direction A, at the end of the movement output 4 is activated. |
5 | The last recently used destination gets corrected a little bit downwards. (smaller value
for the servo).
(This command only can be used if manual adjustment is enabled in CV555 / CV567). |
6 | The last recently used destination gets corrected a little bit upwards. (larger value
for the servo).
(This command only can be used if manual adjustment is enabled in CV555 / CV567). |
7 | The adjustment done with the commands 5 and 6 is saved.
(This command only can be used if manual adjustment is enabled in CV555 / CV567). |
8 | The speed of the last recently used servo can be adjusted. (is still missing) |
Which servo?
- Besides the perfect control also the choice of the servo is Crucial for a fine movement.
I checked out different servos, the conclusion is: don't buy cheap!
The cheap servos of Conrad at 5 Euros (e.g. ES-05, ES030) slip with slow movements and have problems with the dissolution.
I would recommend Robbe FS 100 (quietly and accurately, about 10 euro) and the Hitec HS-311 and as small servo the Hitec HS-55.
Excellent performance is offered by digital servos!
Installing the decoder and the servos
- Current supply:
A servo needs a 5V supply, this is generated by means of a linear regulator. If the supply of this regulator is done of DCC or of a high alternating voltage (> 10V), then a lot of energy has to be removed from the regulator.
Separate supplying the decoder with an inexpensive plug power pack with 9 V output voltage is recommended. - Switching on and off:
The decoder stores the last position of the servos. If the decoder (and thus the servo) is switched off before reaching the last position, then the stored position does NOT match the mechanical situation. At next power up, the servo moves to the stored position with its maximum speed.
Therefore a movement always should be terminated before turning off power. - Mechanical coupling:
Servos (particularly cheap ones) make a small jerk when switched on. Therefore the mechanics must be designed so that no damages can occur. This could be done by using a feather/spring construction or some rubber slip clutch.
I'm often using a plug for WireWrap headers - these clamp sufficient for simple movements, but open in case of overload and are easily adjustable.
Documents:
-
Calculation sheet for producing further loci: please inquire by mail 'servo_curve.xls'
Further too:
- back to the general main side
back to the main side open decoder
ServoDecoder with more than two target positions
FAQ
Download
to the software explanation