Accessing Cog memory...
siljamicke
Posts: 66
Someone, please enlighten me!
I can't figure out why this program stops after one iteration...
It is a small test program, just to venture a little bit into the world of PWM... I'll post the program (it is a bit cluttered with amongst other things the "add dummy,#1" etc. It's there only to make the loop sort of equally long...)
Now, it loops just fine as long as i put a value between 1 and 3 where i marked it in red, so it has to do with:
But why can't i read more than three longs from sampleSet?
I'm probably missing something obvious, but i have read the manual a couple of times today, and i can't still find out what i'm doing wrong...
In hope for a helpful answer,
Micke
I can't figure out why this program stops after one iteration...
It is a small test program, just to venture a little bit into the world of PWM... I'll post the program (it is a bit cluttered with amongst other things the "add dummy,#1" etc. It's there only to make the loop sort of equally long...)
CON _CLKMODE = RCSLOW ' _CLKMODE = XTAL1 + PLL1X ' _XINFREQ = 6_000_000 PUB Main cognew(@entry, 0) DAT org 0 entry mov dira,DACpin mov r2,#1 mov sampleCtr,#0 :LoopWaveform mov dutyCtr, #0 shl r2,#23 mov outa, r2 'put one on pin 23 mov r1,#sampleSet add r1,sampleCtr 'load sample mov sample,r1 :PinHigh add dutyCtr, #1 add dummy,#1 sub dummy,#1 add dummy,#1 cmp dutyCtr, sample WZ 'loop high part of duty cycle if_NZ jmp #:PinHigh mov r2,#0 shl r2,#23 mov outa, r2 ' put zero on pin 23 add sampleCtr,#1 cmp sampleCtr,[COLOR="red"]#32[/COLOR] WZ 'shift into next sample if_Z mov sampleCtr,#0 mov r2,#1 :PinLow add dutyCtr, #1 sub dummy,#1 add dummy,#1 sub dummy,#1 cmp dutyCtr, dutyLen WZ 'loop low part of duty cycle if_NZ jmp #:PinLow jmp #:LoopWaveform sampleSet long 1,2,3,4 long 5,6,7,8 long 9,10,11,12 long 13,14,15,16 long 15,14,13,12 long 11,10,9,8 long 7,6,5,4 long 3,2,1,0 'a basic triangle waveform r1 long 0 r2 long 0 sample long 15 dutyCtr long 0 dutyLen long 32 sampleCtr long 0 dummy long 0 DACpin long %00000000100000000000000000000000 fit 496
Now, it loops just fine as long as i put a value between 1 and 3 where i marked it in red, so it has to do with:
mov r1,#sampleSet add r1,sampleCtr 'load sample mov sample,r1
But why can't i read more than three longs from sampleSet?
I'm probably missing something obvious, but i have read the manual a couple of times today, and i can't still find out what i'm doing wrong...
In hope for a helpful answer,
Micke
Comments
I am reading it now, just had to let you know right away how thankful i am for your help!
Much to my girlfriends regret, i'm going to look it through thoroughly until i understand it all!
Thanks again!
Most of the things I wrote are not a real problem, but give you cleaner code. The main point is that the propeller does not have indirect addressing like other mikrocontrollers. R1 and R2 let me think that you used AVRs before?! So you have to get used to self modifying code (even call and ret are self-modifying because the prop does not have a stack). There is a good description of PASM specialities - as far as I remember from Oldbitcollector? - which is a must-read. Is it mentioned in the sticky? ....
Here we go;
nop... you'd guess that for a guy like me who started out with assembler on a Commodore would know about No OPeration... ;( I'm embarrased...
or/and... It's about time i learn the truth tables of the various xor's and and's. I tend to avoid using them because i can't bother with the extra brain effort. I will never do this kind of programming again! (Note to self, stop cutting corners!)
RES... I don't know why i keep doing all this double initialization of the variables... It's like i don't trust that the value really is what i want it to be, so i have to do it twice. I'll stop that immediately!
I'll do my homework, and repost the correct code!
I could put color tags around text inside code tags, but the button for it only shows up in advanced reply...
I'm not sure which text you are referring to. I have read the manual, deSilva's tutorial and Propeller trix and traps, but they are all very brief on every topic...
But i'll learn as i go along!
http://forums.parallax.com/showthread.php?96594-Machine-Language-Tutorial!
This is what it looks like now:
It sounds like two pops, meaning it halts after one time through the program, without looping.
By the way, all of a sudden the compiler complains about: saying that it's an "Undefined symbol". I'm quite sure it is not, since it worked perfectly fine an hour ago...
How looks Yours Propeller platform ---> Maybe it is hardware problems
There is another global label (a label without : at begin) between the point where :LoopWaveform is defined and the point where the jmp #:loopWaveform is written. So these are not the same local labels. The first can be seen as entry:loopWaveform and at the jump the label will be samplRd:loopWaveform.
Andy
I didn't realize the colon( : ) made it somehow special, i thought it was merely a choice of preference. In what way do these labels differ?
You moved the mov dutyCounter,#0 outside of the loop ... that was a bad idea
With you current code 0 will still give you a peak and waveLen will still give you a gap. (BTW waveLen is not the right name for this variable, right?)
If you change the pinHigh and pinLow as follows, you can have 0 without peak and waveLen without gap:
My excuse is that it was done quite late in the evening here in Sweden... Not really an excuse... Also i only had the one cup of coffea... No excuse either? Ok... Well then i'm all outta excuses...
Changing that into pulseLen, or maybe cycleLen?
More questions:
I have 32 samples, and in my loop i try to read 33, which isn't what i intended, so i changed it into #31. Fine, now it works. But why doesen't it work when i read 32 samples? I mean, shouldn't it just play one possibly weird sample, and then start over from the top of sampleSet?
You've officially become my mentor. I'll follow your advice to the point, blindly and promptly! I will change the code immediately!
Yet again, big thanks!
Here is my version:
I only added another output (commented out currently) to measure the output with a scope.
I changed it into your suggestion... Now it all works! Big big thanks!