• Well, the average resolution of setInterval is actually very high (1 uS) but the speed of execution of JavaScript is really going to cause you problems - so while you could maybe get nearer 8kHz with a few lines of the inline assembler, other bits of JavaScript that run will get in the way of it.

    It's a bit difficult really... You can get an accurate, very high pulse rate using the built-in timers and analogWrite, but crucially you won't be able to accurately count how many pulses have been sent out.

    So if you really want the higher speeds with Espruino I guess you have three options - none of which is great:

    • Use peek and poke to set up one of the hardware timers as a counter, then use that counter to count the number of pulses that have been sent with the analogWrite command.
    • Some of the hardware timers have a register for 'repeat count'. I don't know if you could somehow set/query that with peek and poke in order to make sure that you sent out only the amount of pulses that you wanted.
    • Modify Espruino's source so that you can use the software timer (in jstimer.c) to do what you want. It's what is used for digitalPulse/Waveform/etc and is capable of sending repeated pulses at relatively high (~50kHz?) rates. You'd have to add something such that it could keep track of how many pulses had been sent, and so that you could also change the interval between them.
  • Gordon,

    Have you seen the new NXP dual-core mcu[1] which starts at $2(for 256K/108K flash/ram) ? it might be a good fit to enable Espruino with real-time :

    1 core could run Espruino with all it's benefits especially with high ram. Another core run Arduino/Mbed,exactly for those real-time tasks. People who don't care to learn Arduino/Mbed, but want to add some real-time stuff can easily copy code from the net.

    I believe there are even ports of the mbed to the lpc4500(a board called bambino-200) , which is another dual core chip from nxp, so it might make the job easier.

    [1]http://www.eetimes.com/document.asp?doc_­id=1324539&

About

Avatar for jack.kryden @jack.kryden started