Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Pulse #19

Open
pacmac opened this issue Aug 21, 2013 · 5 comments
Open

Fast Pulse #19

pacmac opened this issue Aug 21, 2013 · 5 comments

Comments

@pacmac
Copy link

pacmac commented Aug 21, 2013

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 ??

var dq;
function dqinit(cb){
    dq = gpio.export(4, {
       ready: function() {
          dq.set(0);
          setTimeout(function() {
            dq.set();
            dq = gpio.export(4, {
               direction: "in",
               ready: function() {
                    cb(dq.value); 
               }
            });         
          },0);
       }
    }); 
}

dqinit(function(val){
    console.log(val);
});
@EnotionZ
Copy link
Owner

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.

@vicary
Copy link

vicary commented Sep 3, 2013

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 0s 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?

@kilianc
Copy link

kilianc commented Sep 14, 2013

@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).

@EnotionZ
Copy link
Owner

@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.

@vicary
Copy link

vicary commented Sep 19, 2013

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants