Open pacmac opened 11 years ago
You actually just need to export the header once. In the ready callback, run dq.set(0, function(){ dq.set(1, function(){ cb(dq.value); }); }); I'm on my iPad so it's a bit hard to type, hope that makes sense.
Most browsers (including Chrome) has a minimum countdown around 5-8ms with setTimeout(..., 0)
, which is considered an artifact of some kind of complicated theory and is yet to be resolved.
I don't know if V8 has fixed this, better use the internal Timer
class in nodejs IMO.
I have a fork that takes an array of 1
and 0
s for SPI bit banging, which pipes them directly into C for a way more reasonable output.
@EnotionZ Do you think µs preciseness can be done in javascript?
@vicary you can. Use process.hrtime()
or the microtime module.
You can run as fast as your cpu clock does + T(V8 runloop) + T(your code).
@vicary the bottleneck is probably the fact that we're using node's filesystem to write header values. I bet if we wrote a node c++ module that wraps the wiringPi library, we'd get faster timing. As @kilianc said, we can take a high resolution (nanosecond) timestamp with process.hrtime()
to validate.
I am not very sure about how gpiolib.c
works, I guess it bypasses the filesystem writes? If that's true, can nodejs works directly with that layer instead of writing through the filesystem?
Hi;
Using a scope to monitor the pin, I seem to be unable to get a pulse faster than 10ms using the following code, but I really need the pulse width to be in microseconds rather than milliseconds, hence the setTimeout value of 0, which I was hoping would last a few clock cycles. Even if I remove the SetTimeout() function, the pulse width is still 10ms.
there is a 1K pullup on gpio.4.
The following code is intended to pull gpio4 low for 500us, then release it and then read whether the connected device has pulled the line low (presence) and log the result to the console, however I am unable to get a pulse width less than 10ms, any ideas why ??