Arrays, Spin, PASM??? Something funny going on
Harley
Posts: 997
I have a problem I've been chasing for too long.
VAR 'value' is an array used to hold 128 A/D samples, and two longs up front at value[noparse][[/noparse] 0 ] and value[noparse][[/noparse] 1 ]. Problem is Spin can initialize value[noparse][[/noparse] 1 ], but PASM A2D only sees ZEROs there via PASD.
If I load a constant in Nsamp, write it to PAR+4 that writes OK and via TV_text displays correctly. Initially at 80 changes to 26. I need to adjust this value (via a keypad) in use. I've used the constant initially to bring up A2D. Now am surprised I cannot make this work as planned with a variable .
The A2D array values are properly being scaled and displayed on a graphic LCD via ST7920. Photo of the simulated pulse from D2A.
What all might be wrong with this? Stumping me to death.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
VAR 'value' is an array used to hold 128 A/D samples, and two longs up front at value[noparse][[/noparse] 0 ] and value[noparse][[/noparse] 1 ]. Problem is Spin can initialize value[noparse][[/noparse] 1 ], but PASM A2D only sees ZEROs there via PASD.
If I load a constant in Nsamp, write it to PAR+4 that writes OK and via TV_text displays correctly. Initially at 80 changes to 26. I need to adjust this value (via a keypad) in use. I've used the constant initially to bring up A2D. Now am surprised I cannot make this work as planned with a variable .
The A2D array values are properly being scaled and displayed on a graphic LCD via ST7920. Photo of the simulated pulse from D2A.
What all might be wrong with this? Stumping me to death.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
spin
76K
Comments
I get 128 A/D samples, but I don't understand the bit about value[noparse][[/noparse] 0 ] and value[noparse][[/noparse] 1 ].
I don't get the Nsamp thing or about adjusting with a keypad. Are you wanting to set the number of samples via a keypad?
What works and what doesn't work?
don't forget the @
again @ AND ... 60*80_000_000 will exceed 32 bit, so you don't get what you expect.
Post Edited (MagIO2) : 2/15/2010 10:13:42 PM GMT
Funny thing, a constant loaded into Nsamp works, but trying to 'rdlong Nsamp,_ptr' at the PAR+4 location only loads all zeros. In PASD the PAR+4 value doesn't get updated when the keypad increments/decrements the value; in fact doesn't even get initialized from a Spin 'value := 80'. This is the part that doesn't work. The value at 'value[noparse][[/noparse] 1 ] doesn't get initialized from Spin as viewed in PASD debugger. Shouldn't a PASM array get initialized via Spin? At least I see it using TV_text and on a DVD monitor, the output can be incremented/decremented via the keypad. So why wouldn't the value at value which should also be PAR+4 location be seen by this A2D set of instructions?
@ MagIO2, I will attend to the '@' and 60 ° 80_000_000 details later. Thank you for the 'good detective' eyes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
It works, but don't understand WHY. Any explanation why initializing a PASM variable before or after a cognew makes a difference?
Anyway, it worked beautifully. Now can expand or contract the image to effectively view several pulses or the magnifie first detected pulse. Presently I'm setting a threshold about 1/2 maximum pulse displayable. And when triggered, move that left a number of samples back to place the pulse at the left of the screen. Sort of making it 'synchronize' to the first event over the threshold.
Now I can move on to other details in this area. Maybe even add a SD card. Ah, the snowballing begins to take effect...
Thanks Graham.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
Edit: sort out before/after
Post Edited (kuroneko) : 2/16/2010 1:04:31 AM GMT
So if I am right, you set the cog initialising then set some other cogs initialising and did some other set up stuff, in the mean time the asm cog started running and read value as 0. Only later would it then get updated to 80 by the spin.
Graham
I seem to recall some thread on boot-up timings, maybe a year ago or so. Anyone recall that thread? I'm curious as to WHEN initialization of variables can occur?
The reason I ask is I ran into the above 'strange' situation with Spin initializing a variable, value := 80, in an array written by both Spin and and read by PASM code. But after the cogs are running, this cog's array only had all zeros in Hub RAM. The suggestion, from Graham Stabler, was to initialize prior to that cog's cognew, which worked. Probably that writes to Hub RAM, which later is read once the cog begins to run.
I suppose that value of zero, used by a djnz counter, then had to do 2^32 loops x 128 times before it could return and read value for the next major loop. I calculate a time of over 2 hours! So I didn't wait long enough to see it working. Sure consumed lots of wasted time trying to figure out where the problem was.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
If you initialize some of the memory to be copied prior to the COGINIT, all will be well.· If you wait until after the COGINIT, the hub controller may have copied the long already.· The other choice is to wait until after the cog has started running.· In that case, you'll need initialization·code in the cog to copy the information from a shared area into the appropriate variables in the cog's memory.· There's no way for one cog to copy information to another cog's memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko