
8 Programming with NanoJ
8 Programming with NanoJ
NanoJ is a programming language similar to C or C++. NanoJ is integrated in the Plug & Drive Studio
software. You can find further information in document Plug & Drive Studio: Quick Start Guide at
us.nanotec.com.
8.1 NanoJ program
A NanoJ program makes a protected runtime environment available within the firmware. Here, the user
can create his own processes. These can then trigger functions in the controller by, for example, reading or
writing entries in the object dictionary.
Through the use of protective mechanisms, a NanoJ program is prevented from crashing the firmware. In the
worst case, the execution is interrupted with an error code stored in the object dictionary.
If the NanoJ program was loaded on the controller, it is automatically executed after the controller is switched
on or restarted.
8.1.1 Available computing time
A NanoJ program receives computing time cyclically in a 1 ms clock (see following figure). Because
computing time is lost through interrupts and system functions of the firmware, only approx. 30% – 50% of
computing time is available to the user program (depending on control mode and application). In this time,
the user program must run through the cycle and either complete the cycle or yield the computing time by
calling the
yield()
function. In the former case, the user program is restarted with the start of the next 1 ms
cycle; the latter results in the program being continued on the next 1 ms cycle with the command that follows
the
yield()
function.
...
1
2
3
0
t in ms
NanoJ
Idle
Operating
system
Read inputs
Write outputs
If the NanoJ program needs more time than was allotted, it is ended and an error code set in the object
dictionary.
Tip
When developing user programs, the runtime behavior must be carefully examined, especially for
more time-intensive tasks. For example, it is therefore recommended that tables be used instead of
calculating a sine value using a
sin
function.
Version: 2.0.1 / FIR-v1650
95