Propeller Multitasking-- Multiple Pulse Width Measuring
moonshine10
Posts: 2
I am using the chip to measuring pulse width from 6 channel. So far one channel can be measured though my code. Right now I am trying to use different cogs to execute the code on them to measuring different channel in the same time. But it does not work. Right now the code can only be execute over one stack , whichever I put at last of my main function. PLEASE HELP!
CON _clkmode = xtal1 + pll16x 'Use crystal*16 for fast serial _xinfreq = 5_000_000 'can make it up to 80MH OBJ pst :"Parallax Serial Terminal" VAR long value long value2 long port long output long count1 long count2 long count long StackA[128] long StackB[128] PUB main pst.Start(115200) cognew(go(3),@StackA) cognew(go(4),@StackB) PRI go(pin) port:=pin dira[port]~ dira[16..23]~~ repeat value := ina[port] if (value==1)&(value2==0) 'rasing edge count1:=cnt elseif (value==0)&(value2==1) count2:=cnt count:=count2-count1 output:=(count)/80000 'UNIT in ms pst.str(string(" Port: ")) pst.dec(port) pst.str(string(" ---------- ")) pst.dec(output) pst.str(string(" ",13)) value2 :=value
Comments
-Phil
This will not work without conflicts. You need to declare them local as follows:
Note local variables need to be initialized
Enjoy!
Mike
Are you adapting code you found on a Parallax tutorial/appnote? This reminds me of some code Parallax published on how to use multiple cogs but the code had an error. I think the error was what Mike describes.
I assume your present efforts are an attempt to learn to program. If you just want to read six pulses (from a radio controlled receiver) there are objects which can do this from a single cog.
Moon
My contribution to the code was to make easier to use on any of the Propeller's I/O pins. I also made it possible to use non-consecutive pins.
This sort of code is often used to read the incoming pulses from a radio control systems.
Combining this code to read pulses with the Servo32v9.spin object allows one to use the Propeller to mix the incoming channels in order to control servos in ways not possible with standard RC gear.