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

INTRODUCTION

If you want to activate an output of your Raspberry PLC and you want to know exactly how long it will take to activate, learn in this blog post how to calculate the speed of a duty cycle with an average of 1000 loops!

Latest Posts

REQUIREMENTS

Raspberry PLC >

Power Supply >

Either SSH or HDMI connection with an extra monitor

RPIPLC-PYTHON3-LIB

In order to do a speed test of the Raspberry PLC outputs, we will need to download the rpiplc-python3-lib.

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 defineset 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 is done. Then, we will substract 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. 

Odoo • Text and Image

DIGITAL OUTPUTS

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

Odoo • Image and Text
In this case, we get an output of 0.006 seconds. 
So, 6 milliseconds.

Odoo • Image and Text

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 the digital outputs, and run again the application.

Odoo • Image and Text
In this case, we get an output of 0.004 seconds. 
So, 4 milliseconds.

Odoo • Image and Text
Speed Test Raspberry PLC Outputs
Boot & Work Corp. S.L., Fernandez Queralt Martinez
24 November, 2021
Share this post
Archive

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 >>>

Do you want more information?

Just fill the form!

Tell me more!