Re: Using port 5 as I/O's
Bryan Armstrong <bryan.armstrong-6tN4nzCoH/[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <[email protected]> |
Chris Harrison wrote:
> com.dalsemi.system.BitPort. This seemed relatively slow so i wrote
> comparative C code which directly programmed the register, which
> unsurprisingly was faster and took about 2.3 micro sec (400kHz). This
> however seems disproportional faster. So was wondering if anyone could
> give me a explanation to what is taking the time when using the BitPort
> class implementation and if there is any better way of using the bits on
> port 5 as I/O's using Java?
If you program the bit toggling in assembly, it will get even faster.
Probably sub 1 microsecond.
Toggling a bit in Java goes through a few layers of goo:
1. invokevirtual opcode BitPort.set()
2. More java opcodes (iload, bastore, etc.) to setup parameters
3. invokestatic opcode bitPortNative()
4. Use passed in parameters to determine which port pin is
being accessed as well as what state to set the pin.
5. Change state of pin (setb P?.?)
Items 1-3 consume 99% of the 1.7ms. The other 1% is item 4 and 5, the
actual pin toggle code. Most of the overhead occurs because a full
featured 32 bit JVM is running on an 8-bit microcontroller. If you use
C, you are removing the virtual machine, but are still hindered by any
compiler inefficiencies on a small platform. Once you get down to the
bare metal, you can really burn some useful clock cycles. :)
--
--
Bryan Armstrong
bryan.armstrong-6tN4nzCoH/[email protected]
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini