Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Multitasking-- Multiple Pulse Width Measuring — Parallax Forums

Propeller Multitasking-- Multiple Pulse Width Measuring

moonshine10moonshine10 Posts: 2
edited 2014-08-06 18:22 in Propeller 1
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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-08-04 14:37
    Your problem is with pst. It's started from one cog and called from two different cogs. The right way to do this is to pass the count data back to the main cog and let it do all the interfacing with pst.

    -Phil
  • msrobotsmsrobots Posts: 3,709
    edited 2014-08-04 15:05
    another problem I can see Is that you are using global variables Inside go().

    This will not work without conflicts. You need to declare them local as follows:

    Note local variables need to be initialized
    PRI go(pin) | port, value, value2, count, count1, count2
      value2 := 0
      count := 0
      count1 := 0
      count2 := 0
    port:=pin
    dira[port]~
    dira[16..23]~~
    repeat
        
      value := ina[port]
    ...
    

    Enjoy!

    Mike
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-08-04 17:08
    moonshine10,

    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.
  • moonshine10moonshine10 Posts: 2
    edited 2014-08-04 18:32
    I found the problem. It is what exactly what mike describe. Thank yall very much !

    Moon
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-08-06 18:22
    As requested in your "visitor message", here's a link to some code to read six channels at once with (I believe) 1us precision.

    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.
Sign In or Register to comment.