How fast is analogRead() #5231
Replies: 1 comment
-
Posted at 2014-03-20 by @gfwilliams analogRead is limited more by the speed of execution than anything else. You might be looking at 2000 samples/sec? There is however the Waveform class which will do what you want (it even contains an example of making a sound meter) - but I wouldn't push that much beyond 20kHz. Having said that, if you try doing a spectrum analyser in Espruino you may find that you hit issues with Espruino's processing speed pretty quickly. It's not going to be great at doing realtime FFTs in JavaScript :) I've implemented things like Posted at 2014-03-20 by Owen Do you know any good FFT libraries in JavaScript? Posted at 2014-03-20 by @gfwilliams Yes, the MSGEQ7 would be the easiest solution, and it looks like it would be pretty easy to use with Espruino... I'll see about adding that convolve function in Espruino 1v58 though, so you should be able to get a few bands of EQ quite easily. I just gave FFT (using an LCD screen) a quick go:
It's only managing around 2 FPS at the moment. I guess with LEDs it would be significantly faster though... Posted at 2014-03-20 by tage I was briefly looking into the analog sampling speed when working on a solar panel diagnostics circuit. With the STM32F4 Discovery board I managed to collect my 100 samples at 12 bit resolution with a sampling speed of 5kHz. I also tried the Waveform which gives 8 bit data, at 100kHz, and I am still scratching my head trying to see if I can use the 8 bit resolution for the type of measurement I am doing. it may be possible but I need to figure out how to process the data. In my case I can collect the data and process it afterwards, so the delays in Espruino is not a major issue. It would be nice to be able to increase the sampling speed at 12 bit resolution with a factor of 5 or more, that would open up other applications. Posted at 2014-03-20 by @gfwilliams Just FYI after having played with this, I'm not sure it can reach the 100kHz I'd guessed when doing it initially. It looks to be nearer 20kHz now - although maybe more on the F4 board. I'd have to look into getting 12 bit. It's definitely possible though. Posted at 2014-03-21 by tage I did not actually time the Waveform capture, so I would need to repeat the test to know the actual capture rate. The AnalogRead spent 0.0196s to capture 100 samples. Posted at 2016-03-18 by user63183 I know this thread is 2 years old. Has there been any progress? The chip spec says it can sample 12 bits st 2 MHz! Posted at 2016-03-18 by @gfwilliams The speed is really limited by either the execution speed of the JavaScript in the case of analogRead, or the speed of the timer system for Waveforms - it's not really a hardware issue. If you absolutely require the speed it'd be possible to use Poke commands to set the hardware up to use DMA with analogRead (or you could compile in your own code that did this in C, which might be easier). What do you need it for though? Since Espruino doesn't execute JavaScript that quickly, you would struggle to actually do much with data captured at 2MS/sec unless you were just capturing it for use with something else. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-03-20 by Owen
Hello,
I'm wondering how fast analogRead() is at getting results?
I want to be able to sample analogue audio to build a spectrum analyser. What kind of sampling rates do you think I can get from the Espruino?
Beta Was this translation helpful? Give feedback.
All reactions