New faster arduino sketch, 61Ks/s and 94Ks/s

912 views
Skip to first unread message

quag27

unread,
Jun 4, 2012, 10:35:43 PM6/4/12
to xoscillo
I wrote this sketch that instead of reading each analog value and
sending it through serial, it stores the values in RAM and then sends
them which it is a lot faster. With a 16 prescaler i could achieve
61Ks/s and with a 8 prescaler 94Ks/s but this is over the maximum spec
ADC clock of 1Mhz stated in the datasheet, so it must be done under
your own risk. For me it worked grate.

here is the file: https://www.box.com/s/50860b6dcef77407fa0e

How I measured the sample rate: i had a ds1307 breakout board so i set
the square wave output to a frequency of 4096hz and using a serial
console i sent the commands and counted the samples per waveform.
Results:
16 prescaler: 15 samples per wave form
8 prescaler: 23 samples per wave form

Limitations
Only one channel A0
Disabled PWM output
Max 1024 samples (could be more but risking it to eat all available
RAM)
Because the change in the sample rate the software shows incorrect
frequency and time values because it has a fixed setting to 12Ks/s, so
if you want to actually measure time or frequency yo have to do the
math to correct the value that is shown.

Useful feature i would like to have but i dont know how:
Setting to change the 12ks/s in the pc software
Overlapping waveform
Waveform averaging

PD: May this project is not any more in development, if this is the
case maybe someone could orient me to other similar projects

Sorry for my english, im from Argentina
and Thanks for this great software.

cosmok82

unread,
Jun 30, 2012, 8:51:20 AM6/30/12
to xosc...@googlegroups.com
Hi, I used the fast version on the Arduino 2009 that I possess and I have to say that works very well. Before it visualized frequencies due to harmonic that weren't present, but I must say that even if it works, the results aren't shown in the right scale (into oscilloscope and into fft).
Why?

quag27

unread,
Jul 2, 2012, 12:02:19 AM7/2/12
to xosc...@googlegroups.com
It is because the pc program uses a the fixed 12ks/s to calculate frequency and time. So for the pc program the data points are spaced at 83us (1/12ks/s = 83 us) this is correct for the original sketch but sampling at 94Ks/s the time between sample is 10us, but the pc program still calculates the time scale and frequencies scale using the 83us.

A simple conversion can be done by multiplying the the shown frequency by the real sample rate and dividing it by the fixed 12ks/s. 
example: sampling a 1Khz waveform at 94Ks/s will show up as 127.6 hz

frequency = 127.6hz * 94Ks/s / 12ks/s = 1000hz

Converting the time scale is done by multiplying it by 12ks/s and dividing it by 94ks/s

I hope this was help full

Goran Grubić

unread,
Jul 22, 2014, 4:12:28 PM7/22/14
to xosc...@googlegroups.com
I have a ad-hock C# code hack for you.

download VisualStudio C# solution (source code),
open: XOScillo > VizForms > arduino > AnalogArduino.cs 
and change code like this:

 class AnalogArduino : SerialArduino
    {
        const Int32 actualSampleRate = 94000;

        public AnalogArduino() 
            //: base(115200, 12000)
            : base(1000000, actualSampleRate, 2)
        {
            
            //needs tunning
            //baudrate = 1000000;
            SetSampleRate(actualSampleRate); 
        }

Where actualSampleRate is the samplerate you want.
compile and run!

Raul Aguaviva

unread,
Aug 14, 2014, 7:30:49 AM8/14/14
to xosc...@googlegroups.com
Hi Goran,

Sorry for the delay!

Actually changing actualSampleRate alone wont do it, you really need the arduino to send you the data at a higher rate too! :)

Cheers
Raul


--
You received this message because you are subscribed to the Google Groups "xoscillo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xoscillo+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Орвас Дрен

unread,
Feb 2, 2015, 1:31:55 AM2/2/15
to xosc...@googlegroups.com


вторник, 5 июня 2012 г., 8:35:43 UTC+6 пользователь quag27 написал:


Give me, please, the exe file of xoscillo which is working with new version of sketch. I failed with compilation. It's not working.

Brett Cooper

unread,
Feb 2, 2015, 1:35:49 AM2/2/15
to xosc...@googlegroups.com
arduinos don't use exe files.

--
Reply all
Reply to author
Forward
0 new messages