PWM monitoring with spin?
So i have a· PWM signal coming from a device that would normally drive a servo.· instead, i want to be able to se the PWM with the Propeller and based on its width, have the propeller accomplish different tasks.· Where is the starting point in spin to do this?· what commands would i use.· I realize that i could use the BS2 functions object but i dont need all the other things associated with it.· Any help would be great.· Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!

Comments
In Spin, wait for the pulse to go high, then wait for the pulse to go low. At that point, read the counter (PHSx) and you'll get the width in 12.5ns steps (with an 80MHz clock). Zero the counter and you'll be ready for the next pulse.
PUB INIT dira[noparse][[/noparse] 0] := 1 'set your Pulse in pin to pin P0 dira[noparse][[/noparse] 1] := 0 'set Apin to output P1, may not be used in this example CTRA := %00100 << 26 + 1 set Apin to P1 frqa := 0 ' no accumulation yet PHSA := 0 ' not required, but illustrates that PHSA will start counting at 0 PUB TestPulseWidth Repeat Frqa := 0 ' set to no accumulation PHSA := 0 ' reset PHSA to 0 Waitpeq (%1, %1, 0) 'wait for P1 to equal 1, this is your pulse to test FRQA := 1 'starts the CTRA counting from 0 Waitpeq (%0, %1, 0) 'wait for P0 to equal 0, your pulse is finished, set FRQA stop counting next Frqa := 0 ' stop the accumulation TestResult 'or do a Return PHSA, and let the caller do the TestResult using the returned valuePost Edited (TChapman) : 4/8/2007 7:10:05 AM GMT
What does this do differently from the example that Mike gave of using %01000
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
I am not clear on Mikes idea yet, I am still looking at it to see what that mode is and how it works, I think it is a POS in detector.
Post Edited (TChapman) : 4/8/2007 6:26:35 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Page 6, Table 6 says that mode %11010 APIN = 1 accumulates PHSA when pin is a 1.
Page 16 says "Mode %01000 (POS detector) is identical to mode %11010 (LOGIC A)"
I think Mike is suggesting that the Apin be used as the input to the counter , when High the counter accumulates at the rate of FREQA.
PUB INIT dira[noparse][[/noparse] 0] := 0 CTRA := %01000 << 26 + 0 frqa := 1 PUB TestPulseWidth Repeat PHSA := 0 ' reset PHSA to 0 Waitpeq (%1, %1, 0) 'wait for high, counter starts also on a 1 Waitpeq (%0, %1, 0) 'wait for a low, the counter stops on a 0 TestResult 'count := PHSAPost Edited (TChapman) : 4/8/2007 9:04:19 AM GMT
Thanks for pointing out that modes %01000 and %11010 are the same.