My way of doing things is to use vim to edit the source files right on the BBB, then use "node file.js" to run my server, which then dishes out file.html to a browser, which then uses JQuery and socket IO to run my GUI. This works out great and I am basically working at full speed without being hindered by some stupid buggy IDE.
b.digitalWrite ( bit, 1); b.digitalWrite ( bit, 0 );I get out my oscilloscope, wrap a loop around the above code and measure that this gives me a pules 0.7 milliseconds (700 microseconds) wide. Certainly wide enough to trigger my stepper controller, but it is a concern that this takes almost as long as the loop interval when I am running a loop every 1 ms using:
var delay = 1; setInterval ( ticker, delay );Since I have the scope hooked up, I measure some other pulse widths. Lets call the following a "2 instruction" pulse:
b.digitalWrite ( bit, 1); b.digitalWrite ( bit, 1); b.digitalWrite ( bit, 0 );It is about 1.1 ms wide. So the pulse width timings look like this:
1 instruction pulse: 0.7 ms 2 instruction pulse: 1.1 ms 3 instruction pulse: 1.8 ms 4 instruction pulse: 2.0 ms 5 instruction pulse: 2.2 ms 10 instruction pulse: 3.7 ms
var delay = 1; function ticker () { b.digitalWrite ( bit, 1); b.digitalWrite ( bit, 0 ); } setInterval ( ticker, delay );The results are as follows:
1000 gives a 1000 ms (1 Hz) loop (good!) 100 gives a 100 ms (10 Hz) loop (good!) 50 gives a 50 ms (20 Hz) loop (good!) 20 gives a 20 ms (50 Hz) loop (decent) 10 gives a 12 ms delay (83 Hz, not 100) 5 gives a 8 ms delay (125 Hz, not 200) 2 gives a 5 ms delay (200 Hz, not 500) 1 gives a 2.4 ms delay (417 Hz, not 1000)So, things are coming unglued at fast loop rates. This is not totally shocking, but I am glad I checked this while I had the scope out.
Performance using Javascript and Node.js on the BBB (as a user process running under the linux kernel) is interesting to contrast with simple code running on an AVR microcontroller (similar to an Arduino). On the AVR microcrontroler the timing was dead on and solid. The code running on the AVR was compiled C, running on a bare microprocessor (no kernel, no other processes).
Each has its strong points. The BBB provides a wonderful development environment, ethernet, and a nice path to a GUI. The AVR provides direct access to hardware, but only a USB connection in the usual configuration, making GUI development more challenging, but hardly impossible.
What the BBB really needs is a real time kernel like the Skidoo (TM) real time kernel I wrote for my thesis project.
Tom's Computer Info / [email protected]