Time = what
bennettdan
Posts: 614
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?
Thanks for comment or correction.
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
An instruction can only handle immediate constant values from 0..511 (9bit) for higher values you need an additional long with the constant:
Andy
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?
[HTML] [/HTML]
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.
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.