Analysis of the M-DUINO PLC pinout time response

Technical analysis of the M_DUINO PLC pinout performance
June 20, 2023 by
Analysis of the M-DUINO PLC pinout time response
Boot & Work Corp. S.L., Ricard Franch Argullol

 Introduction

M-Duino PLC

In this post, you will learn more about the performance of the M-DUINO PLC pinout time response, examining its ability to detect and respond to changes in inputs,  as well as the ability to output signals.

The measurements in this blog have been made using the default Arduino IDE functions. Faster speeds could be achieved by using other libraries such as the digitalWriteFast, or by directly manipulating the pins through the Arduino registers.

 Requirements

If you want to measure the PLC characteristics, you will also need a precise oscilloscope capable of reading at the 100ns scale.

 Digital output

The digital outputs of the M-DUINO PLC are connected to the Arduino Mega direct pins, using some circuitry to adapt the voltage levels. Remember the output voltage depends on the QVdc pin, you can learn more about them on this post about digital outputs.

The digital outputs can be analysed with an oscilloscope and this simple code, where we make multiple writes to the Q0.0 pin every 100µs.

void setup() {}
void loop() {
  digitalWrite(Q0_0, LOW);
  delayMicroseconds(100);
  digitalWrite(Q0_0, HIGH);
  delayMicroseconds(100);
}

Using an oscilloscope, you can observe that the output signal timing are the following:

  • Rise time: 476ns
  • Fall time:  42.8µs

The fall time is considerably longer than the rise time, which affects the maximum output frequency we can achieve.  Here are some measurements:

Output Frequency
PeriodPulse Width
Delay
6.849kHz
146µs
106µs70µs
4.866kHz
205.5µs
136.5µs
100µs
1.953kHz
512µs286µs250µs

Using a delay of 70µs, a switching prequency of 6.849 kHz can be achieved in any digital output, although with a 72% duty cycle. If a duty cycle of 50% is strictly needed, the delay will need to be increased up to 250µs, for a 1.953 kHz 55.86% duty cycle signal. Although it is possible to utilize shorter delays, doing so may yield a signal that deviates from the square pulse shape. Specifically, with no delay, the signal transitions from 5V to 4.3V before rising back to its original voltage level. 

 Digital input

The digital inputs of the M-DUINO PLCs are also connected to direct pins of the Arduino Mega. These inputs interpret voltages between 0-5V as LOW and voltages between 5-24V as HIGH, and are opto-isolated. In addition, I0.5 and I0.6 are interrupt pins, which means they can trigger Arduino interrupts.

The following code can be used to measure the sampling time of a digital input using the digitalRead() function. We take 10^6 readings and calculate the average execution time and the maximum time.

#define N_TIMES 1000000

unsigned long t1, t2, t_max, t_average;

void setup() {
Serial.begin(115200);

t_max = 0;
t_average = 0;

for (long i = 0; i<N_TIMES; i++) {
t1 = micros();
digitalRead(I0_5);
t2 = micros();
t_average += (t2-t1);
if (t_max < t2-t1) t_max = t2-t1;
}

Serial.print("Max time: ");
Serial.println(t_max);
Serial.print("Average time: ");
Serial.println(t_average/(float)N_TIMES);
}

void loop() {}

The results for the I0.0 input are a maximum run time of 12µs and an average of 5.65µs. This translates to a maximum sampling rate of 176.9 kHz.

The I0.5 (interrupt) input has a maximum run time of 16 µs and an average of 8.23 µs. This translates to a maximum sample rate of 121.51kHz. Most samples take 8µs, but there are some that take 16µs.

The analogue inputs (I0.7 - I0.12) can also be used as digital inputs (7-24V), so their speed can be tested using this same code. Their maximum and average read time is the same as normal digital inputs: 12µs and 5.65µs, respectively.

 Analog output

The M-DUINO PLCs features analog output between 3 and 9 analog outputs, depending on the PLC model, each connected to an Arduino direct pin. These outputs can take any value between 0V and 10V, with 8 bits of resolution. To learn more, visit our blog about analog outputs.

In order to measure the response time of the analog outputs we can use an oscilloscope and the following code to measure the rise and fall times of the signal:

void setup() {}
void loop() {
  analogWrite(A0_5, 255);
  delay(150);
  analogWrite(A0_5, 0);
  delay(150);
}

Measuring with an oscilloscope we get the following times:

  • Rise time: 150ms
  • Fall time: 252ms

Considering 252ms as the worse time, we can achieve a signal frequency output of 2Hz.

 Analog input

Analogue inputs allow to measure voltages between 0V and 10V, returning a value with a resolution of 10 bits (0-1023). You can find more information in this blog post on analogue inputs.

This code, which measures the maximum and average execution time of the analogRead() function, can be used to find out its sampling time:

#define N_TIMES 1000
unsigned long t1, t2, t_max, t_average;
void setup() {
  Serial.begin(115200);
  t_max = 0;
  t_average = 0;
  for (long i = 0; i<N_TIMES; i++) {
    t1 = micros();
    analogRead(I0_7);
    t2 = micros();
    t_average += (t2-t1);
    if (t_max < t2-t1) t_max = t2-t1;
  }
  Serial.print("Max time: ");
  Serial.println(t_max);
  Serial.print("Average time: ");
  Serial.println(t_average/(float)N_TIMES);
}
void loop() {}

As a result, we get a maximum runtime of 204µs and an average of 112.89µs. Therefore, we can reach a maximum sampling frequency of 8858.2Hz.

 Direct Pins

The M-DUINO PLCs also have some pins directly connected to the Arduino Mega inside, which work at 5V levels:

  • RX0

  • TX0

  • RX1

  • TX1

  • MISO

  • MOSI

  • SCK

  • Pin 2

  • Pin 3

  • SCL

  • SDA

Output

The maximum output frequency we can achieve using the Arduino IDE and the digitalRead() function is 77kHz, which can be observed with an oscilloscope by running this code:

void setup() {
  pinMode(2, OUTPUT);
}

void loop() {  
  digitalWrite(2, HIGH);
  digitalWrite(2, LOW);
}

Input

The direct pins can also be used as an input, in which case the digitalRead() function has this characteristics:

  • Average read time: 8.23µs.
  • Maximum read time: 16µs.

 Summary

Inputs

Input type
Sampling frequency - Average
Sampling frequency - Highest read time
Digital Interrupt (IX.5-6)121.51kHz (8.23µs)62.5kHz (16µs)
Digital Opto-isolated (IX.0-4)
176.99kHz (5.65µs)
83.3kHz (12µs)
Digital Non Opto-isolated (IX.7-12)
176.99kHz (5.65µs)83.3kHz (12µs)
Analog (IX.7-12)8.858kHz (112.89µs)4.9kHz (204µs)
Direct pins
121.51kHz (8.23µs)62.5kHz (16µs)

Outputs

Output type
Signal frequency - Maximum Stable
Signal frequency - Maximum
Rise time
Fall time
Digital (QX.0-7)1.953kHz (55.86%)
6.849kHz (72.6%)476ns
42.8µs
Analog (AX.5-7)2Hz (50%)
2.48Hz (37.31%)150ms
252ms
Direct pins
77kHz (53.7%)77kHz (53.7%)200ns
200ns

 Conclusion

Conclusion

In this post, you have learned about the performance of the M-DUINO PLC pinout time response, examining its ability to detect and respond to changes in inputs, as well as the ability to output signals.

You have seen:

  • how the digital outputs can achieve a switching frequency of up to 6.849 kHz,
  • how the digital inputs can sample at a rate of up to 176.9 kHz, and
  • how the analog outputs can produce a voltage range of 0-10V.

You have also learned how to measure these characteristics using an oscilloscope and some simple code.

By understanding the capabilities and limitations of the M-DUINO PLC pinout, you can use it more effectively for your projects and applications!

​Search in our Blog

Analysis of the M-DUINO PLC pinout time response
Boot & Work Corp. S.L., Ricard Franch Argullol June 20, 2023
Share this post

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