Shop OBEX P1 Docs P2 Docs Learn Events
Misprint in manual causing confusion — Parallax Forums

Misprint in manual causing confusion

William GuynesWilliam Guynes Posts: 5
edited 2005-12-04 21:30 in General Discussion
Funny math in the manual on p.167.

The return value and the timeout value are actually unsigned. Even though integers nominally range only to
32767, these values actually extend beyond, but the compiler treats them as negative numbers. There are
several ways to deal with this problem. One easy way is to use shifts, but it does cut your timing resolution in
half. For example, suppose you want to wait for 195.3 ms. This corresponds to a timeout argument of 45000
– too big for a signed integer. However, what if you pretended, the actual resolution was not 8.68us, but double
that (8.68 us). Now the timeout argument for 195.3 ms would be 22500 – an acceptable number.


The manual says 8.68us in a lot of places, so I must assume that every "tick" is actually 8.68us. But, 195.3ms/45000 is actually 4.34us. So, either the chip USED to be 4.34us resolution and it never got updated, or there's some wonky math going on. Could someone shed some light on what it should be saying?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-04 14:54
    Yes, that is strange. I think the text should read

    The return value and the timeout value are actually unsigned. Even though integers nominally range only to
    32767, these values actually extend beyond, but the compiler treats them as negative numbers. There are
    several ways to deal with this problem. One easy way is to use shifts, but it does cut your timing resolution in
    half. For example, suppose you want to wait for 390.6 ms. This corresponds to a timeout argument of 45000
    – too big for a signed integer. However, what if you pretended, the actual resolution was not 8.68us, but double
    that (17.36 us). Now the timeout argument for 390.6 ms would be 22500 – an acceptable number.


    I think the javelin was originally designed for a 50MHz clock, but due to power issues, that
    was changed to 25MHz. The example line below that text does show 390.6 ms.

    There is an easier way to accomplish what they do. Just use (short)45000
    and you get the same result.

    regards peter
  • William GuynesWilliam Guynes Posts: 5
    edited 2005-12-04 21:30
    Ah, yes. The knowledge that the javelin was originally intended to have a 50Mhz clock puts the misprint in perspective. Your correction was exactly what I was suspecting.
Sign In or Register to comment.