4-20mA R current loop Arduino tutorial Part III: receiver

0

Today we come to the third and last part of the 4-20mA communication tutorial using Arduino UNO boards and the pair of 4-20mA R  and 4-20mA T  click boards from MikroElektronika. In this post I will describe the calibration procedure and I provide the code for the receiver. I will also show a method to implement open loop and short circuit detection using the above click boards.

This blog post is more than two years old.

So. we begin with the calibration procedure. We need to know the ADC output for the situation when the current through the loop is 4mA, and the ADC output for the situation when the current through the loop is 20mA. First, both transmitters and receivers must be powered. Then the calibration code on the transmitter is used to set the current through the loop is 4mA. The following code was used to output the ADC result:

An average of 100 measurements was taken into account. One might observe that the INA196 current shunt has some variations in the output voltage, even if the current through the loop is stable up to microamps level. A method to calculate the accuracy variations is given in the INA196 datasheet, pages 17-18.

So, for 4mA through the loop I’ve got an average of 788, with a minimum of 775 and a maximum of 800.

For 20mA through the loop the ADC average output was 3964, with a minimum of 3952 and a maximum of 3982.

With the above values we can now write the receiver code:

In the receiver code I have implemented a simple detection routine for open loop and shortcircuit conditions. With an open loop the ADC output is somewhere around 5, so the threshold I’ve set should be more than enough. The output of the ADC in shortcircuit situations depends on where the shortcircuit is located. The worst situation is with a very long loop cable and the shortcircuit near the transmitter. Again, the threshold level must be set as to allow for the detection of shortcircuits while minimizing false indications.

Last, but not least, there’s a good idea to re sample the result to a lower resolution. In the MikroElektronika examples only 100 discrete levels are used. I guess that resampling to 8 bits should be enough for most applications.

Also in this tutorial

4-20mA current loop Arduino tutorial Part I: hardware
4-20mA current loop Arduino tutorial Part II: transmitter

[Update 9 January 2019] Minor fix of the receiver code: no longer prints values if loop is open or in short circuit.

Advertisements
Share.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: