Shop OBEX P1 Docs P2 Docs Learn Events
How do I...... — Parallax Forums

How do I......

Paul MPaul M Posts: 95
edited 2008-08-28 18:47 in Propeller 1
Some pseudo code:
.
.
repeat
  .
  .  'do stuff
  .
  if <somecondition>
    now:=cnt
  .
  . 'do more stuff
  .
  if cnt > now + 5*80_000_000
    ' 5 seconds should have elapsed since <somecondition>
  .
  .   

This doesn't work properly presumably due to the signed arithmetic(??)

How do you do this?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-28 17:12
    It works much better to do

    if cnt - now > 5*80_000_000

    It's also more reliable to do

    if cnt - now > 5 * clkfreq

    You may not always run your program with a 80MHz clock.
  • Paul MPaul M Posts: 95
    edited 2008-08-28 18:47
    Thanks Mike,

    After reading your reply I realised that·I had used the difference method elsewhere in my code to get·'time between events'.

    You say "..works better.." but actually you mean works always.

    and yes, I neglected to note in my pseudo code .. "assuming an 80MHz clock.."

    Thanks again
Sign In or Register to comment.