Shop OBEX P1 Docs P2 Docs Learn Events
generate pulse in asm — Parallax Forums

generate pulse in asm

ratronicratronic Posts: 1,451
edited 2007-04-14 03:23 in Propeller 1
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!


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Fix it if ain't broke·
D Rat

Post Edited (ratronic) : 4/14/2007 12:53:25 AM GMT

Comments

  • mirrormirror Posts: 322
    edited 2007-04-14 02:34
    ·I didn't try your code, but rewrote·to the following and it worked OK. By reading the counter and adding a delay before every waitcnt you would have got·a pulse output that was slower than expected in any case.
    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
    
  • AribaAriba Posts: 2,685
    edited 2007-04-14 02:35
    Here is a version that works:
                           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.
  • mirrormirror Posts: 322
    edited 2007-04-14 02:44
    Ariba said...
    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.
    Although in general I agree, this is not entirely correct.·Each cog has its own copies of the registers (dira outa etc). The mov is OK in this instance, the only problem arises if you want to control multiple port pins from the SAME cog - in which case andn and or are probably the best ways to go.

    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

    ·
  • OzStampOzStamp Posts: 377
    edited 2007-04-14 03:01
    Hi all.

    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
  • ratronicratronic Posts: 1,451
    edited 2007-04-14 03:07
    Thanks everyone! That does work. I still don't quit get the waitcnt, but I will figure it from your examples. But using the mask to set your out and inputs does work , I thought I was losing it! Thanks again Dave!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Fix it if ain't broke·
    D Rat
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-14 03:12
    Ronald,
    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
  • ratronicratronic Posts: 1,451
    edited 2007-04-14 03:15
    Ozstamp , just begining to figure out prop asm! I do appriecate all of your help , Thanks again Dave

    Thanks Mike!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Fix it if ain't broke·
    D Rat

    Post Edited (ratronic) : 4/14/2007 3:19:37 AM GMT
  • OzStampOzStamp Posts: 377
    edited 2007-04-14 03:23
    Hi Mike

    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
Sign In or Register to comment.