01-29-2020 07:34 PM
Hello Members:
I am using LabVIEW with Arduino UNO board to read encoder digital signals at 5V TTL. I was able to wire the encoder sensor and I provided external excitation of 5V to my encoder with common ground to Arduino UNO board. The encoder is 32 Pulses Per Revolution and is of the optical incremental type of encoder. The count results read from Arduino UNO were OK for slow hand speed rotation but counts were missed when rotating faster. Eg by quickly rotating encoder by a quick hand push or strike about 10 counts were missed. This made me suspect the speed of Arduino UNO in running a loop.
Testing the Arduino UNO Loop Time
To do this I created an empty while loop and I only placed the Arduino microsecond timer functions to capture the minimum loop time. I also added Serial Write function so that Arduino UNO could report back a snapshot of what the loop time was. I compiled the Arduino UNO LabVIEW VI using Arduino Compatible Compiler for LabVIEW and downloaded that to the Arduino UNO. I used baud rate of 115200 and reported the time snap shot at 50msec intervals.
On the LabVIEW side I created a LabVIEW Serial Read VI using same Baud rate of 115200. The LabVIEW VI showed that the fastest loop time that the Arduino UNO could do was 64 microseconds. And this means 1/0.000064 loops per second or 15.625kHz.
Is this correct? The documented clock speed for Arduino UNO is 16MHz. I thought that the loop time would also be the same. Or am I missing something here?
NOTE: All LabVIEW VIs are in LabVIEW 2014
Regards
Anthony L.
01-30-2020 01:47 AM - edited 01-30-2020 01:47 AM
Hi Anthony,
@Anthony_L wrote:
The documented clock speed for Arduino UNO is 16MHz. I thought that the loop time would also be the same. Or am I missing something here?
You miss: "clock speed" <> "execution speed of a single assembler command (may take several clocks per command!)" <> "execution of several assembler command related to your while loop"…
@Anthony_L wrote:
Hello Members:
I am using LabVIEW with Arduino UNO board to read encoder digital signals at 5V TTL. I was able to wire the encoder sensor and I provided external excitation of 5V to my encoder with common ground to Arduino UNO board. The encoder is 32 Pulses Per Revolution and is of the optical incremental type of encoder. The count results read from Arduino UNO were OK for slow hand speed rotation but counts were missed when rotating faster. Eg by quickly rotating encoder by a quick hand push or strike about 10 counts were missed. This made me suspect the speed of Arduino UNO in running a loop.
For encoder pulses you should not use software to count them. Use hardware instead!
Most NI DAQ devices support hardware counters able to count pulses at upto 10MHz. What does the microcontroller on your Arduino support? Does it provide any hardware counters you can employ?
01-30-2020 02:14 AM
Hello GerdW:
I assumed that Arduino UNO would run as a near realtime OS and that it would have reliable or deterministic while loop clock intervals.
This assumption is based on the consideration that there seemed to be no other software running on the Arduino once I downloaded my own program. Thus Arduino OS would dedicate itself solely to that program.
I also assumed that by running almost nothing in the while loop, the loop time will approach the CPU clock tick.
The overhead for reading a clock microsecond, and subtracting the previous shift registered clock reading to get loop time did not seem to be so much instruction as to tax the Arduino to run at 64 microseconds per loop.
But I guess those assumptions were OFF. And looking at the VI again are there about 64 instructions to perform per loop?
In my current projects I am using cRIO 9063 and the exact same LabVIEW VI is downloaded to FPGA to read two encoder digital input signals and convert those to counts. I am getting solid 11 ticks per loop from the 40MHz cRIO clock.
the Arduino UNO micro-controller has digital inputs, pin 7 and 8, that I read for this same purpose.
GerdW: Thanks for your advice and any further advice that you can provide.
Anthony
01-30-2020 03:05 AM
Hi Anthony,
@Anthony_L wrote:
In my current projects I am using cRIO 9063 and the exact same LabVIEW VI is downloaded to FPGA to read two encoder digital input signals and convert those to counts. I am getting solid 11 ticks per loop from the 40MHz cRIO clock.
In a cRIO9063-FPGA the reading of DI signals mostly depends on the speed of the DI module used. I mostly use NI9403, they only allow ~140kHz sample rate…
@Anthony_L wrote:
I assumed that Arduino UNO would run as a near realtime OS and that it would have reliable or deterministic while loop clock intervals.
This assumption is based on the consideration that there seemed to be no other software running on the Arduino once I downloaded my own program. Thus Arduino OS would dedicate itself solely to that program.
I also assumed that by running almost nothing in the while loop, the loop time will approach the CPU clock tick.
The overhead for reading a clock microsecond, and subtracting the previous shift registered clock reading to get loop time did not seem to be so much instruction as to tax the Arduino to run at 64 microseconds per loop.
I don't know the Arduino in detail, but I guess:
- the Arduino does not provide an "OS", its microcontroller just executes your compiled code
- the microcontroller might use a 8-bit based CPU, which needs more than just one command to do a 32 (or 64) bit based integer operation
- reading DI pins in the Arduino microcontroller might also be speed limited
All those details about my assumptions can be found in the manual of the microcontroller used in your Arduino. According to Wikipedia Arduino Uno uses a MicroChip ATMega microcontroller!?
01-31-2020 01:36 PM
Hello Gerd:
Correct, Arduino UNO is a microcontroller. I posted same question on TSExperts community forum and I was asked to remove the subVIs and leave exposed code in one VI. This precaution alone cut down the loop time by 43%. from 216 to 124 microseconds. I am at a point where it looks like the Arduino UNO will work to read counts with low resolution incremental Encoders such as 32 Pulses per rev.
There is another advice of using interrupts to read digital input pins that will cut down the loop latency time further. I am pursuing that avenue now.
Again thanks for the reply
Anthony
08-03-2021 04:12 PM
Hi Anthony_L,
How are you? I read your posts and I was wondering if you were successful at cutting down even further the loop time of the arduino Uno board. I am trying to lower the loop cycle but I am not sure what I am supposed to do.
I have see that in one of the earlier posts you mentioned something about "TSExperts community forum" and I am wondering what you ended up doing or what exactly they recommended.
Please share any information you may have regarding this topic.
Best, Massimo
08-08-2021 09:43 PM
Hello Massimo:
Further discussion on this topic can be found here:
I tried using interrupts to measure pulse peaks and the speed was faster than having a VI detect Voltage rise and fall edges. But still not fast enough to allow reading encoder counts at a modest frequency of 500kHz.
In the end, I determined that the Arduino was not fast enough to cover worse case scenarios for encoder count readings. So I ended up using the MCC DAQ 1808 ($750) and US Digital USB4 DAQ ($550) which all have FPGA capability and perform really well in returning encoder counts up to 5MHz.
Note that there is a suggestion to use the Arduio Due which has frequency clock at 80MHz. But the fact that Arduino DUE would only do up to 3.3 VDC peak voltage was a no go for me.
Regards
Anthony L.
08-09-2021 12:28 PM
@Anthony_L wrote:
Hello Massimo:
Further discussion on this topic can be found here:
I tried using interrupts to measure pulse peaks and the speed was faster than having a VI detect Voltage rise and fall edges. But still not fast enough to allow reading encoder counts at a modest frequency of 500kHz.
In the end, I determined that the Arduino was not fast enough to cover worse case scenarios for encoder count readings. So I ended up using the MCC DAQ 1808 ($750) and US Digital USB4 DAQ ($550) which all have FPGA capability and perform really well in returning encoder counts up to 5MHz.
Note that there is a suggestion to use the Arduio Due which has frequency clock at 80MHz. But the fact that Arduino DUE would only do up to 3.3 VDC peak voltage was a no go for me.
Regards
Anthony L.
It would have been cheaper to go with a dedicated optical encoder chip like the LS7166A 24-BIT QUADRATURE COUNTER and an Arduino