Shop OBEX P1 Docs P2 Docs Learn Events
assembly call — Parallax Forums

assembly call

New @ assembly... I want to have cogs putting out square waves at two freqs, and do something else in spin... also would like to have
an assembly routine I could call to just put out a short pulse (<1Us)
see code... not working...
Thanks...

Comments

  • AribaAriba Posts: 2,682
    You need another ORG 0 just before the Tweet label. The code for the second cog needs also to be compiled from addr 0.

    Andy
  • Remember that you can use a counter to output a short pulse -- this way you don't have to launch a cog
    pub pulse_out(pin, tix) | mask
    
      mask := |<pin
    
      ctra := (%00100 << 26) | pin                                  ' configure for pulse
      frqa := 1
      dira[pin] := 1
    
      phsa := -tix                                                  ' start pulse
      waitpeq(mask, mask, 0)                                        ' wait for high
      wanipne(mask, mask, 0)                                        ' wait for low
    
      ctra := 0                                                     ' kill counter
    
    Warning... if the pulse is VERY short, the waitpeq may get missed -- you'll need to test. You can also port this code to PASM; there is nearly a 1-for-1 instruction match.
  • Thanks Andy , that fixed it... And Thanks Jon. I'll work on your sample tomorrow..
    good job guys...

    Bill
  • And one more... how do I call an assembly routine.. see what I added...?
  • JonnyMacJonnyMac Posts: 8,927
    edited 2020-08-29 04:45
    To communicate with your assembly routine you have to pass the hub address of a "mailbox" variable. I made a really simple pulse generator app (that's all it does) so you can see how this works.

    The second parameter of cognew() is the hub address that is your mailbox. Since this address is passed to the cog, you can use it as a base address for several values. In this demo, there is only one (ticks). Note that when the pulse is done the cog tells the Spin program it's finished by clearing the ticks pulse timing.
Sign In or Register to comment.