Speed Test Raspberry Pi PLC Outputs

Calculate the speed of the complete duty cycle for industrial Raspberry PLC Outputs
November 24, 2021 by
Speed Test Raspberry Pi PLC Outputs
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

Do you want to activate an output of your industrial Raspberry Pi PLC and to know how long it will take? Learn in this blog post how to calculate the speed of a duty cycle with an average of 1000 loops!

Latest Posts

Your Dynamic Snippet will be displayed here... This message is displayed because you did not provided both a filter and a template to use.

Requirements

Raspberry PLC >

Power Supply >

Either SSH or HDMI connection with an extra monitor

PYTHON3-LIBRPIPLC

In order to do a speed test of the Raspberry PLC outputs, we will need to download the python3-librpiplc. You can check the Python library for Raspberry PLC blog post to help you download the library.

Testing

1. Once the library is already installed, let's create a new file called test.py:

nano test.py

2. Then, copy this code:

from rpiplc_lib import rpiplc
import time
def main():
        rpiplc.init("RPIPLC_21")
        rpiplc.pin_mode("Q0.0", 1)
        rpiplc.pin_mode("Q0.1", 1)
        rpiplc.pin_mode("Q0.2", 1)
        rpiplc.pin_mode("Q0.3", 1)
        rpiplc.pin_mode("Q0.4", 1)
        rpiplc.pin_mode("A0.5", 1)
        rpiplc.pin_mode("A0.6", 1)
        rpiplc.pin_mode("A0.7", 1)
        start = time.time()
        for i in range(1000) :
                rpiplc.digital_write("Q0.0", rpiplc.HIGH)
                rpiplc.digital_write("Q0.0", rpiplc.LOW)
                rpiplc.digital_write("Q0.1", rpiplc.HIGH)
                rpiplc.digital_write("Q0.1", rpiplc.LOW)
                rpiplc.digital_write("Q0.2", rpiplc.HIGH)
                rpiplc.digital_write("Q0.2", rpiplc.LOW)
                rpiplc.digital_write("Q0.3", rpiplc.HIGH)
                rpiplc.digital_write("Q0.3", rpiplc.LOW)
                rpiplc.digital_write("Q0.4", rpiplc.HIGH)
                rpiplc.digital_write("Q0.4", rpiplc.LOW)
                rpiplc.digital_write("A0.5", 4095)
                rpiplc.digital_write("A0.5", 0)
                rpiplc.digital_write("A0.6", 4095)
                rpiplc.digital_write("A0.6", 0)
                rpiplc.digital_write("A0.7", 4095)
                rpiplc.digital_write("A0.7", 0)
        end = time.time()
        res = ( int(end) - int(start) ) / 1000
        print(res)
if __name__ == "__main__":
        main()

Explanation

Now, we are going to explain the code above line by line.

  1. First of all, we are going to import the rpiplc library.
  2. Then, we are going to define the pin mode of the outputs to 1, in order to set them as outputs and not inputs.
  3. After that, we will loop 1000 times for 1000 duty cycles.
  4. In order to measure this time, we will get the time before doing the loop, and the same once it is done. Then, we will subtract the end and the start time, and we will divide it by 1000, to get the speed of the duty cycle.
  5. Finally, we will print the result, and we will execute the main function to run everything explained.

Run the test

Now, run the following command in order to get the speed resolution for the outputs when all of them are running:

python3 test.py

What we get is a speed of 10 milliseconds with all of them running. 

Python3 test - Speed Test Raspberry Pi PLC Outputs

Digital outputs

If you would like to know the speed of the outputs when only all of the digital outputs are running, just comment on the analog outputs, and run again the application.

Digital outputs 1 - Speed Test Raspberry Pi PLC Outputs
In this case, we get an output of 0.006 seconds. So, 6 milliseconds.

Digital outputs 2 - Speed Test Raspberry Pi PLC Outputs

Analog outputs

And the opposite with the analog outputs: If you would like to know the speed of the outputs when only all of the analog outputs are running, just comment on the digital outputs, and run again the application.

Analog outputs 1 - Speed Test Raspberry Pi PLC Outputs
In this case, we get an output of 0.004 seconds. So, 4 milliseconds.

Analog outputs 2 - Speed Test Raspberry Pi PLC Outputs

​Search in our Blog

Speed Test Raspberry Pi PLC Outputs
Boot & Work Corp. S.L., Fernandez Queralt Martinez November 24, 2021

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>