Loop time is always 1ms

Hello there,

we try to measure some sensor datas over a photon and send them via TCP to our laptop.

To plot the sensor values over time, we measure the time with micros(); and write it as well into our printed string. We tried to increase our speed with setADCSampleTime(); but nothing changed. It is strange that the loop always need exactly 1ms to run through.

Is it a default setting of particle that the loop takes exactly 1ms or is it adjustable.

We wrote our data into a txt.file, which is printed every loop:

counter 1, zeit 56974204 , piezo1 3899, piezo2 3868, piezo3 4005, volumeValue 124

counter 2, zeit 56975173 , piezo1 3772, piezo2 3773, piezo3 3900, volumeValue 127

counter 3, zeit 56976173 , piezo1 3656, piezo2 3681, piezo3 3799, volumeValue 124

counter 4, zeit 56977173 , piezo1 3549, piezo2 3598, piezo3 3707, volumeValue 126

counter 5, zeit 56978173 , piezo1 3448, piezo2 3519, piezo3 3622, volumeValue 127

counter 6, zeit 56979173 , piezo1 3354, piezo2 3444, piezo3 3538, volumeValue 126

counter 7, zeit 56980173 , piezo1 3265, piezo2 3371, piezo3 3461, volumeValue 127

counter 8, zeit 56981173 , piezo1 3179, piezo2 3302, piezo3 3385, volumeValue 126

counter 9, zeit 56982173 , piezo1 3103, piezo2 3235, piezo3 3317, volumeValue 125

counter 10, zeit 56983173 , piezo1 3028, piezo2 3171, piezo3 3251, volumeValue 127

Thanks for your help :slight_smile:

The thread scheduler in FreeRTOS has a minimum time slice of 1 millisecond.

In order to reliably read the ADC more than 1000 times per second you’ll need to use a hardware timer or ADC DMA. Both techniques are described here:

The example is for audio, but it really works for any sampling.

1 Like

In addition to what Rick said if you are not using SYSTEM_THREAD(ENABLED) the cloud tasks are performed between iterations of loop() and on the Photon that takes about 1ms (on Electron that takes considerably longer).

1 Like