Misprint in manual causing confusion
William Guynes
Posts: 5
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?
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
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