PASM Problem
Oh for the love of god why won't it work...
I WAS trying to do something a little more complicated, but have narrowed the program down to a simplier form. I only want the PWM signal in my code to loop X amount of times, stored as an external variable in spin. I read the first long, that's the period - the second long, the duty cycle, and the third long, the number of times to repeat. It loops forever... It's not waiting for the counter to roll over since it's been sitting for 5 minutes now, repeating the same waveform.
Someone please help me... I've looked through tutorials and it SHOULD work! ARRRRRG.
I WAS trying to do something a little more complicated, but have narrowed the program down to a simplier form. I only want the PWM signal in my code to loop X amount of times, stored as an external variable in spin. I read the first long, that's the period - the second long, the duty cycle, and the third long, the number of times to repeat. It loops forever... It's not waiting for the counter to roll over since it's been sitting for 5 minutes now, repeating the same waveform.
DAT
org 0
entry or dira, pinOut
mov t1, #0
mov cnt1, #0
'set the period
mov addr1, par
rdlong period, addr1
'set the onTime to next var
add addr1, #4
rdlong onTime, addr1
'compute offTime
mov offTime, period
sub offTime, onTime
'get the next onTimeTable value - in spin code, just an array
add addr1, #4
rdlong cnt1, addr1
'set the time and next flip-flop
mov time, cnt
add time, onTime
'loop 1000 times
mov cnt1, #1000
DJNZ cnt1, #:loop
' ret
:loop waitcnt time, offTime
andn outa, pinOut 'turn pin OFF
waitcnt time, onTime
or outa, pinOut 'turn pin ON
loopval_ret ret
pinOut long 1<<15
period res 1
onTime res 1
offTime res 1
time res 1
t1 res 1
addr1 res 1
cnt1 res 1
fit 496
Someone please help me... I've looked through tutorials and it SHOULD work! ARRRRRG.

Comments
1. You never set the ret address. You either fall into it or (firstly djnz to it).
2. You are not executing the djnz loop at all.
Hope this helps - didnt examine too closely
Try this
········'loop 1000 times
······· mov···· cnt1, #1000
:loop·· waitcnt time, offTime
······· andn··· outa, pinOut 'turn pin·OFF
······· waitcnt time, onTime
······· or····· outa, pinOut 'turn pin ON
······· DJNZ··· cnt1, #:loop
:stop jmp #:stop 'loop here indefinately
·····
Post Edited (Cluso99) : 7/1/2008 6:15:21 AM GMT
This is easy to catch with a simulator
'loop x times :Choice DJNZ cnt1, #:loop jmp #:Continue :loop waitcnt time, offTime andn outa, pinOut waitcnt time, onTime or outa, pinOut jmp #:Choice :Continue nopAre there any problems with this?
1. I would normally put the djnz at the bottom of the loop in place of the jmp #:choice, unless you specifically need to handle the cnt1 == 0 case. In asm the less jmping around you do the easier it is to understand the code. You tend to have more jmping is asm that spin but the less to add the better.
2. when cnt1 gets to 0 you jmp to :continue, this will execute a nop and then execute whatever is in memory that the prop loaded from hub memory. Thats propably not what you want. Either put a cogstop or a jmp #:Continue so the cog just loops in place of the nop or something else for the cog to do.
I want to be able to reuse a routine in different areas of my code. I'd like to be able to jump to it, do something, then continue on from where I left off in the original routine. How do you do this? I'm reading deSilva's tutorial, but I don't get this part.
Edit: The best is to make small routines, so everything is easier to reuse.
call X
X mov t0, #1
X_ret ret
so call X modifies the ret instruction with the address after the call instruction. Then jmps to X, executes the mov, then executes the ret which is now a jmp to the instruction after the call.
Well, again, I'm stuck in the infinite loop. Ideas?
:Choice call #loop DJNZ cnt1, #:choice jmp #Continue loop waitcnt time, offTime andn outa, pinOut waitcnt time, onTime or outa, pinOut loop_ret ret Continue nopI'll probably be asking many more questions as I learn.
Good news, is I've got my program working correctly(almost). I thought I would have a base frequency of 30.72kHz. The duty cycle of this frequency would vary, based on a table of sine values I made in Excel. These values are read in between pulses, and the duty cycle changes based on these. This SHOULD create a modified sine wave, and from my scope, it looks good. the pulses vary and due to the voltage rise time of the prop, it actually looks like two sinewaves on top of each other(the top being the ON times, and the bottom the OFF times).
Now, the only problem to this is that the frequency reads 30.11kHz, not my target 30.72kHz. My period is a constant 2604 clocks which is rounded from 2604.1666. This rounding should in no way affect my frequency THIS much... Any thoughts?
org 0 entry 'set the output pin and temps or dira, pinOut mov t1, #0 mov cnt1, #0 :main 'set the period mov addr1, par rdlong period, addr1 'set cnt2 to zero mov cnt2, #64 'set the onTime to next var :loop1 add addr1, #4 rdlong onTime, addr1 'compute offTime mov offTime, period sub offTime, onTime 'set the time and next flip-flop mov time, cnt add time, onTime 'set the counter to x mov cnt1, #1 'loop x times :Choice call #OnOff DJNZ cnt1, #:choice DJNZ cnt2, #:loop1 jmp #:main OnOff waitcnt time, offTime andn outa, pinOut waitcnt time, onTime or outa, pinOut OnOff_ret retThis would be similiar to the following code in spin
time := cnt
repeat
time += x
waitcnt(time)
...do something...