generate pulse in asm

I am trying to generate a 5uS pulse continuosly. But I continue to generate a pulse of aprx .72uS no matter what
I put in for the delay amount. I have read the propeller book about waitcnt and read the waitcnt examples in the
first page· of the sticky asm for beginners in the front of this forum. Can anybody tell me what I am doing wrong in the attached code genpulse? I have read everything I can get my hands on. I am stuck!!!! Please help!!!
Thanks Dave!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (ratronic) : 4/14/2007 12:53:25 AM GMT
I put in for the delay amount. I have read the propeller book about waitcnt and read the waitcnt examples in the
first page· of the sticky asm for beginners in the front of this forum. Can anybody tell me what I am doing wrong in the attached code genpulse? I have read everything I can get my hands on. I am stuck!!!! Please help!!!
Thanks Dave!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D RatFix it if ain't broke·
Post Edited (ratronic) : 4/14/2007 12:53:25 AM GMT
Comments
con 'genpulse generate pulse 5uS _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 pub start cognew(@entry, 0) dat org entry mov m0, #0 'mov a 0 into mask m0 shl m0, pin 'shift pin # of bits into mask m0 mov m1, #1 'mov a 1 into mask m1 shl m1, pin 'shift pin # of bits into mask m1 mov outa, m1 'preset outa to output p0 = 1 via m1 mov dira, m1 'set p0 to an output mov time, cnt add time, delay loop mov outa, m1 'set p0 to 1 waitcnt time, delay 'wait for aprx 2.5 uS mov outa, m0 'set p0 to 0 waitcnt time, delay 'wait for aprx 2.5 uS jmp #loop 'loop back to do again pin long 0 'pin# p0-p31 goes here delay long 200 'amount of delay 200*12.5nS=2.5uS m0 res 1 m1 res 1 time res 1
org entry mov m1, #1 'mov a 1 into mask m1 shl m1, pin 'shift pin # of bits into mask m1 or outa, m1 'preset outa to output p0 = 1 via m1 or dira, m1 'set p0 to an output mov time, cnt 'get current cnt add time, delay 'add delay time loop or outa, m1 'set p0 to 1 waitcnt time, delay 'wait for aprx 2.5 uS andn outa, m1 'set p0 to 0 waitcnt time, delay 'wait for aprx 2.5 uS jmp #loop 'loop back to do again pin long 0 'pin# p0-p31 goes here delay long 200 'amount of delay 200*12.5nS=2.5 micro seconds m1 res 1 time res 1
You can use the same pin-mask to set and clear a portbit with or and andn. Your m0 mask make no sense, it will always stay at 0 (a 0 shifted left will stay a 0).
Don't set the pins with mov, this will affect all pins together (in this example it will work but what if there is an other cog that will use the port?). Use or/andn or mux.
waitcnt dest,src waits until the counter reaches the value of dest and adds then the value of src. In the code above the time value will be set to cnt+delay before the loop and in the loop the time value will be set to time+delay after every match for the next waitcnt instruction. The addition is done in the same cycle as the match occure - this gives a very exact timing.
Of course the inner loop can be made even shorter if you don't care about the initial state:
loop· xor········ outa,m1
······ waitcnt· ·time,delay
······ jmp······ ·#loop
·
Having trouble seeing why any of the above would work properly.
To me you all grab the cnt time value once as you start up but never grab it again.
See below
mov time, cnt 'get current cnt
add time, delay 'add delay time
Then you all loop without grabbing the cnt value again ???
Am I missing something here ??
Ronald
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ D Rat
The source field of the WAITCNT is automatically added to the destination after the wait is satisfied. This sets up the destination for the next WAITCNT at precisely the same time interval every time. For example:
mov temporary,#1000 ' Set up for initial delay of 12.5us add temporary,cnt waitcnt temporary,#1000 ' Wait until the time in "temporary", then set up for next 12.5us delay waitcnt temporary,#2000 ' Wait for another 12.5us to elapse, then set up for a 25us delay waitcnt temporary,#0 ' Wait for the 25us, then don't do anything, we're done for now
Note that the WAITCNT waits for the current delay time, then sets up for the next delay time
Thanks Mike!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ D Rat
Post Edited (ratronic) : 4/14/2007 3:19:37 AM GMT
Thnx for that pointer.
That will shorten my code in a few spots.
Just verified the manual re your pointer .. yep your right.
That makes that a powefull instruction .. doing 2 things .
Cheers
Ronald Nollet Australia