Shop OBEX P1 Docs P2 Docs Learn Events
Time = what — Parallax Forums

Time = what

bennettdanbennettdan Posts: 614
edited 2010-12-22 15:41 in Propeller 1
Hello,
I would like to see if I understand a few things correctly.
I want to use "waitcnt" instruction in assembly but want to make sure I am setting the instruction up for the correct time amount.
I want a .4 ms / 400us pause
If I divide my clock of 80000000 by 1000 i get milliseconds
80000000/1000= 80000
so their are 80000 ticks in a millisecond (ms)
now if I divide 80000 by 1000 i should get the amount of ticks in a microsecond (us)
80000/1000= 80
so if 80 ticks is a microsecond then 80 times 400 should get the ticks needed to wait?
400*80=32000
something like this should give me the 400us pause?
              mov         counter,cnt
              add         counter, 32000
              waitcnt    counter,0  


Thanks for comment or correction.

Comments

  • AribaAriba Posts: 2,690
    edited 2010-12-20 19:49
    Your calculation is correct, but the Assembly code is not possible in this form.
    An instruction can only handle immediate constant values from 0..511 (9bit) for higher values you need an additional long with the constant:
    mov counter,cnt
      add counter, us400
      waitcnt counter,#0
      ...
    
    us400  long  32000
    

    Andy
  • bennettdanbennettdan Posts: 614
    edited 2010-12-20 19:59
    Thanks for the input Ariba I actually use a constant "hold" for the 32000 value I was just showing 32000 as an example. I was just new to assembly and wanted to make sure my train of though was right.
    Thanks again
    Also if anyone reads this I have not been on the forum much lately how do you post the code in a gray block i see some people doing?
  • Nick McClickNick McClick Posts: 1,003
    edited 2010-12-20 20:27
    use the code tag
    [HTML]
    some code here
    
    [/HTML]
  • bennettdanbennettdan Posts: 614
    edited 2010-12-20 23:55
    Thanks Nick....my post is now edited
  • ericballericball Posts: 774
    edited 2010-12-21 06:25
    		mov	counter, l32k
    		add	counter, CNT
    		waitcnt	counter, #0
    
    l32k		long	32_000
    
    counter		res	1
    
  • bennettdanbennettdan Posts: 614
    edited 2010-12-21 22:53
    Ok I think I understand the time relation now. One more question if say I have an assembly loop and it does 2 timed operations and I always want it to finish at the same time no matter how long the 2 operations last can I do something like this and always have it to finish within 50ms.
                             add           totalcounter, CNT
                    mov        	counter, 123k                               'first operation
                   	   add        counter, CNT
    		waitcnt	counter, #0
                    mov	counter, l32k                                 'second operation
    		add	counter, CNT
    		waitcnt	counter, #0
                                    add          counter, CNT              
                                    sub          countter, totalcounter
                                    waitcnt      counter, #0
    
    l23k		long	32_000
    321k                         long          50_000
    counter		res	1
    totalcounter	res	1
    
    
  • ericballericball Posts: 774
    edited 2010-12-22 05:46
    bennettdan wrote: »
    Ok I think I understand the time relation now. One more question if say I have an assembly loop and it does 2 timed operations and I always want it to finish at the same time no matter how long the 2 operations last can I do something like this and always have it to finish within 50ms.

    The PASM instruction "waitcnt cntval, nxtdelay" does two things. First it halts processing until CNT equals cntval. Second it adds nxtdelay to cntval. So normally you don't have to keep calculating cntval past the first one.

    Looking at your code, I'm not sure what you are trying to accomplish. Maybe if you provided a timing description.
  • bennettdanbennettdan Posts: 614
    edited 2010-12-22 15:41
    ericball,
    What I want to do is to be able to send my 2 signals which are a variable pulse width and will never be longer than 2ms each but can vary from .7ms to 2ms and I always want the send loop to repeat itself within 50ms.
    example: 1st signal is 1ms and the second is 2ms so I want to send them and then wait untill the 50ms total has elapsed.
    example2: 1st signal is .7ms and the second is 1.7ms so I send them then wait untill the 50ms total has elasped.
    So what I want to do is repeat my signals every 50ms no matter what the pulse width is on the 1st and 2nd signals.
    I will make sure the signals are always less than the 50ms loop. I hope this helps explain this.
Sign In or Register to comment.