This object is provided under license. By downloading this object, you are agreeing to the terms of the MIT License.
User Reviews:
rubrchicken commented:
I'll post the new code in the forums. (I took out debug because I didn't need it, you can put it back if you want)
No idea here, but it may be the fact that you're using the raw pulsins and pushing them to the servo object. Have you tried just using pulsout?
Hmmm... I just tried pulsout, and it is accurate, but slow as heck and is jerky, but not like before.
OOPS. Get rid of the .25 waitcnt and it is fixed!! Your new code:
(No line breaks allowed. Uggh)
{{
Origional Code: Travis
Modded By: Forrest (rubrchicken)
}}
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
'Pin on Prop Chip for LED Indicator
PIN_LED = 15
'Pins on Prop Chip for Servo Input/Output
PIN_SERVO_IN = 0
PIN_SERVO_OUT = 1
var
long us
OBJ
'Debug : "FullDuplexSerial" 'standard from propeller library
SERVO : "Servo32v3" 'standard from propeller library
PUB Begin(in,out) | x,y,z
us := clkfreq / 1_000_000 ' Clock cycles for 1 us
'SERVO.Set(out,1422)
'SERVO.Start
y := PULSIN(in,1)
'SERVO.Set(out,(y * 2))
PULSOUT(out,y)
'waitcnt(clkfreq / 4 + cnt) '0.25 seconds
PUB PULSIN (Pin, State) : Duration | usa
usa := clkfreq / 1_000_000 ' Clock cycles for 1 us
Duration := PULSIN_Clk(Pin, State) / usa / 2 + 1 ' Use PulsinClk and calc for 2uS increments \
PUB PULSIN_Clk(Pin, State) : Duration
DIRA[pin]~
ctra := 0
if state == 1
ctra := (%11010 << 26 ) | (%001 << 23) | (0 << 9) | (PIN) ' set up counter, A level count
else
ctra := (%10101 << 26 ) | (%001 << 23) | (0 << 9) | (PIN) ' set up counter, !A level count
frqa := 1
waitpne(|< Pin, |< Pin, 0) ' Wait for opposite state ready
phsa:=0 ' Clear count
waitpeq(|< Pin, |< Pin, 0) ' wait for pulse
waitpne(|< Pin, |< Pin, 0) ' Wait for pulse to end
Duration := phsa ' Return duration as counts
ctra :=0 ' stop counter
PUB PULSOUT(Pin,Duration) | clkcycles
{{
Produces an opposite pulse on the pin for the duration in 2uS increments
Smallest value is 10 at clkfreq = 80Mhz
Largest value is around 50 seconds at 80Mhz.
BS2.Pulsout(500) ' 1 mS pulse
}}
ClkCycles := (Duration * us * 2 - 1250) #> 400 ' duration * clk cycles for 2us
' - inst. time, min cntMin
dira[pin]~~ ' Set to output
!outa[pin] ' set to opposite state
waitcnt(clkcycles + cnt) ' wait until clk gets there
!outa[pin]
March 20, 2009 5:35 p.m.