I am sure this has been covered in the forums but thought it a good idea to post this
as a Code Snippet.
What this bit of demo code does is control a servo full range using a 10K pot and the pulsout
command rather than the Picaxe "servo" and "servopos" commands.
So why do it this way instead of using SERVO ? Mainly because of the conflicts that
can occur between "servo" and other commands that use the internal timer. These
conflicts can cause seemingly random glitches and/or jitter. Using Pulsout in a
timed loop eliminates any possibility of jitter or glitches cause by timer conflicts.
In this snippet it eliminates glitches caused by a conflict between READADC and SERVO.
as a Code Snippet.
What this bit of demo code does is control a servo full range using a 10K pot and the pulsout
command rather than the Picaxe "servo" and "servopos" commands.
So why do it this way instead of using SERVO ? Mainly because of the conflicts that
can occur between "servo" and other commands that use the internal timer. These
conflicts can cause seemingly random glitches and/or jitter. Using Pulsout in a
timed loop eliminates any possibility of jitter or glitches cause by timer conflicts.
In this snippet it eliminates glitches caused by a conflict between READADC and SERVO.
Code:
#Picaxe 08M
setfreq m8
symbol Servo1 = 4 [COLOR=#008000]'Output[/COLOR]
symbol Position = W0 [COLOR=#008000] 'Pulse width[/COLOR]
symbol delay = b2 [COLOR=#008000]'Off time [/COLOR]
let delay = 33
do
pulsout servo1, position
[COLOR=#008000]'===========================================[/COLOR]
readadc10 1, position
position = position * 5 / 17 + 180 [COLOR=#008000]'scale the value + offset[/COLOR]
[COLOR=#008000]' In this areas stuff can be done such as receive
' serial data, etc that would normall interfere
' with SERVO. However much time this takes should
' be subtracted from "delay" to keep the off time
' between pulses close to 20 ms. Many servos
' can operate between 5 and 40 ms, so the 20 ms
' is not carved in stone.
'===========================================[/COLOR]
pause delay
loop