Problems starting ASM
crcordill
Posts: 29
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:
Here is the Start PUB, where SP and SA are two different pins:
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
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
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.
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
So the start code:
and I have attached the code that SEN is:
Though I'm really not sure what to do next. Any ideas?