Skip to content

analogWrite slow when writing the value 0 #53

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

Closed
Aidan275 opened this issue Sep 9, 2018 · 4 comments
Closed

analogWrite slow when writing the value 0 #53

Aidan275 opened this issue Sep 9, 2018 · 4 comments

Comments

@Aidan275
Copy link

Aidan275 commented Sep 9, 2018

Hi,

Since upgrading from bonescript 0.6.3 to 0.7.0 I have found that the analogWrite method takes 2-5 seconds to write the value 0 after writing any other value greater than 0.
There is also a large delay when writing to any other value greater than 0 from 0.

Please see the example below which illustrates the issue.

The following code was run after boot on a BeagleBone Black in node v8.11.4 and with kernel 4.14.49-ti-r54.

const b = require("bonescript");

b.pinMode('P8_19', b.ANALOG_OUTPUT);

function write(val) {
    const start = Date.now();
    b.analogWrite('P8_19', val, 2000, x => {
        if (x.err) {
            console.log(x.err);
        } else {
            console.log((Date.now() - start) + "ms");
        }
    });
}

write(0);
write(0);
write(0);
write(0);
write(1);
write(1);
write(1);
write(1);
write(1);
write(0);
write(0);
write(0);
write(0);
write(1);
write(1);
write(1);
write(1);
write(1);

The output from this code is:

> const b = require("bonescript");
>
> b.pinMode('P8_19', b.ANALOG_OUTPUT);
> 
> function write(val) {
...     const start = Date.now();
...     b.analogWrite('P8_19', val, 2000, x => {
.....         if (x.err) {
.......             console.log(x.err);
.......         } else {
.......             console.log((Date.now() - start) + "ms");
.......         }
.....     });
... }
> 
> write(0);
39ms
> write(0);
11ms
> write(0);
7ms
> write(0);
11ms
> write(1);
13ms
> write(1);
111ms
> write(1);
6ms
> write(1);
6ms
> write(1);
2ms
> write(0);
4481ms
> write(0);
4437ms
> write(0);
3602ms
> write(0);
3172ms
> write(1);
3681ms
> write(1);
2ms
> write(1);
2ms
> write(1);
2ms
> write(1);
3ms

If you exit nodejs after this and then run it again, the first write(0) calls also have a large delay (sometimes 15+ seconds for the first one).

Please let me know if you need anymore infromation from me.

Thanks

@riptho
Copy link

riptho commented Sep 12, 2018

he analogWrite method takes 2-5 seconds to write the value 0 after writing any other value greater than 0.
There is also a large delay when writing to any other value greater than 0 from 0.

Also having this issue

@vaishnavachath
Copy link

Hi @Aidan275 @riptho I have tried to fix this issue , could you also please test and confirm whether it is fixed?

@Aidan275
Copy link
Author

Hi @Vaishnav98, I've tested your new code and so far it appears to be working fine.

Thank you for your speedy fix :)

@vaishnavachath
Copy link

Thank you @Aidan275 :)

jadonk pushed a commit to jadonk/bonescript that referenced this issue Aug 15, 2019
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

Successfully merging a pull request may close this issue.

3 participants