Shop OBEX P1 Docs P2 Docs Learn Events
Javelin units — Parallax Forums

Javelin units

JiggsJiggs Posts: 26
edited 2004-07-29 20:30 in General Discussion
Why is everything with the Javelin in 8.68us units? For example, pulseIn() returns the length of the high or low pulse in 8.68us units. Because of this, we must multiply the value that pulseIn() returns by 8.68 in order to get the true length of the pulse. For example, if pulseIn() returns a 2, the actual length of the pulse was 17.36us (8.68*2). Of course, the Javelin cannot do floating point math without the help of a cumbersome external class (please note, I am simply referring to the fact that initializing an external class, especially to do something as simple as, for example, 1.1 + 2.2, is cumbersome). What's the logic behind this seemingly random number?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
~Jiggs

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-07-29 20:30
    The javelin runs on a 25 MHz oscillator.

    The javelin creates a 115200 Hz timebase to support uarts.

    So the divider is 25000000/115200 = 217.013...

    which is rounded to 217.

    The interrupt frequency then becomes 25000000/217.

    Interrupt time is the reciprocal value i.e.

    interrupt time is 217/25000000 sec = 8.68 usec.

    Delays and VP measurements are in number of interrupt loops,

    i.e. units of 8.68 usec.



    regards peter
  • RussRRussR Posts: 11
    edited 2004-07-29 20:30
    Jiggs,

    Keep in mind that behind the Java language there is an interpreter doing the real work on "tokens" generated by the compiler. This interpreter is running at the clock speed of the actual host microprocessor. Trying to line things up to make it nice and tidy is rather problematical. Then think of all the other things going on, lke the Virtual Peripherals ....

    You can use a trick from the "Old Days", that is, from before there even was such a thing as "floating point" arithmetic on computers. It is called "scaled decimal arithmetic".

    Consider the 8.68 us as 868. You have to remember that the decimal is placed between the first 8 and the 6. Now multiply this value from what pulseIn returns and you get 1736. Again, the assumed decimal place is in the same spot. You can add scaled decimals so long as their assumed decimal place is the same. Multiplication and division get hairy, but can be done. One of the greatest shortcomings of the Javelin is the lack of 4 byte arithmetic, far more limiting than no real arithmetic.

    If you really want to mess around with IEEE real arithmetic, i suggest adding a co-processor to your project.

    Russ
Sign In or Register to comment.