Shop OBEX P1 Docs P2 Docs Learn Events
Problems starting ASM — Parallax Forums

Problems starting ASM

crcordillcrcordill Posts: 29
edited 2008-07-17 18:40 in Propeller 1
Hey all:
I'm having difficulty with my code and I can't figure out what is going on. I start my program by passing some values to a new object:

PUB Test_SimpleSensor|ph
  RunPWM
  QE.Start(Epin, 4, 0, @EPos)                          'Encoder Start
  cogsenp := SEN.Start(SP,0, @Epos[noparse][[/noparse]W_num])
  cogsena := SEN.Start(SA,32,@Epos[noparse][[/noparse]W_num])
  Disp_All




Here is the Start PUB, where SP and SA are two different pins:

PUB Start(Pin,shift,PosAddr): Pass
_pin1     := Pin
_shft     := shift
_dmeann   := 1600               '=1.6*d_mean                  
_maxt     := 1000
_maxw     := 75
_dmean    := 1000
_dstd     := 300
_dstdtwo  := 150
_dstdfour := 75
_dhi      := 1700               '_dmean + _dstd * 2.5
_wmean    := 110
_wstd     := 32
_wstdtwo  := 16
_wstdfour := 8
Pos := PosAddr
Pass := (Cog := cognew(@Entry, Pos) + 1) > 0




So I start two new cogs for the sensor. They use the same code, but they are supposed to use inputs from two different pins. The problem is that when I'm actually using the code, both sensors end up using the same pin. Whats really puzzling me is that I save the values from each sensor to different variables. In order to do that, I use the second number I pass, the shift, which allows the code to shift over to the new variable. Does anyone have any ideas? I can add more code if you need me to, but I thought that you could probably figure out the problem here. Thanks for your help.
Craig

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-17 13:00
    You didn't provide enough code to tell, but I assume that things like _pin1 are variables in your DAT section that are part of the assembly routine.

    It takes quite a while for the assembly routine to get copied to the cog and started ... over 100us. The COGNEW doesn't wait for this to complete, so you're overwriting the variables for the first cog before they get copied to the cog, so both cogs get the same values.

    The easiest thing to do would be to add a WAITCNT after the COGNEW. 250us would be enough.
  • crcordillcrcordill Posts: 29
    edited 2008-07-17 13:04
    Yes, here is the first part of my DAT section.

    DAT
    Entry   ORG
            mov   p,par
            mov   cct,zero
            mov   valsave,zero
            mov   dvalu,zero
            mov   wvalu,zero
            mov   valu,zero
            mov   ct1,zero
            
            mov   pin1,one             WZ              'Set pin1 to input
            shl   pin1,_pin1
            muxz  ina,pin1
    
    



    Yes, I was thinking it had something to do with timing. I'll add the WAITCNT. I just wanted to make sure that there wasn't any larger problem that I was missing. Thanks
  • crcordillcrcordill Posts: 29
    edited 2008-07-17 18:20
    Well it didn't work. I tried adding a WAITCNT, all the way up to one second, and it didn't work. I even tried making two separate methods, one for each sensor, and I had no luck. Here is some more code:

    So the start code:
    PUB Test_SimpleSensor|ph
      RunPWM
      QE.Start(Epin, 4, 0, @EPos)                          'Encoder Start
      cogsenp := SEN.StartP(SP,0, @Epos[noparse][[/noparse]W_num])
      waitcnt(cnt + clkfreq)
      cogsena := SEN.StartA(SA,32,@Epos[noparse][[/noparse]W_num])
      Disp_All 
    
    



    and I have attached the code that SEN is:

    Though I'm really not sure what to do next. Any ideas?
  • crcordillcrcordill Posts: 29
    edited 2008-07-17 18:40
    Got it to work, I was just displaying the wrong thing. confused.gif But I still need to use the waitcnt in order for it to work.
Sign In or Register to comment.