In what year - count, in what land - guess, asked questions. How much faster is ARM than AVR? Which Modbus protocol is "faster"? ASCII or RTU?
By "speed", in this case, we mean the number of processor machine cycles required to execute all actions of the protocol.
The performance study will be carried out on the ModBus Slave RTU / ASCII library, widely known in narrow circles , ported to the ATMega48 and STM32L052 microcontrollers. We will output information via the Modbus protocol to the Weintek panel emulator. Testing will be done on a demo example . In addition to the test results, the panel displays the states of Modbus registers: discrete inputs, discrete outputs, registers for reading and registers for reading / writing. The panel also calculates the number of errors in data exchange with the microcontroller. The test window is shown in the figure.
We will evaluate the performance by measuring the execution time of the protocol message processing function. We will measure the execution time using the worker-peasant method. Before starting the function, we reset the hardware timer, the counting frequency of which is equal to the clock frequency of the microcontroller, after executing the function, we read the timer values ββand process the measurement results. We calculate the minimum, maximum and average value of the execution time of the function of processing messages of the Modbus protocol.
while(1)
{
TIM6->CNT=0;
ModBusRTU();
//ModBusASCII();
tcurent=TIM6->CNT;
if(tcurent<tmin)tmin=tcurent;
if(tcurent>tmax)tmax=tcurent;
avg32=avg32-(avg32>>16)+tcurent;
tavg=avg32>>alfa;
...
The research results are summarized in the table. The research was carried out with various library options:
- ModBusUseTableCRC - Use table CRC calculation;
- ModBusUseErrMes - Use messages about logical protocol errors;
And also with different compiler optimization strategies.
The ModBus Slave RTU / ASCII library supports, in some cases, an important function - a pause between receiving a request from the Modbus Master and the response of the Modbus Slave. The research was carried out with pause values ββof 2 milliseconds and 0 (that is, no pause), these values ββare indicated in the column of the table "Pause P / P". The "Size" column indicates the size of the module, which includes both functions for processing Modbus messages (ModBusRTU (), ModBusASCII ()).
In the author's opinion, it is most expedient to evaluate the performance by the worst case, that is, by the maximum execution time of the function.
Having thought deeply about the research results, the following conclusions can be drawn:
- AVR is not that slow !!! On average, it is one and a half times slower than ARM at the same clock speed. And in the case of optimization in size (for example, variants 13 and 15), it practically approaches ARM.
- The ASCII protocol, in comparison with RTU, is not only slower in transmission speed, but also takes up much more microcontroller resources.
- The use of messages about logical errors of the protocol does not affect performance in any way.
- The tabular method for calculating the CRC allows you to reduce the use of the computing resources of the microcontroller by more than one and a half times.
- Using a pause between receiving a request and transmitting a response allows not only avoiding conflicts on the RS-485 bus, but also reducing the blocking function of processing messages of the Modbus protocol.
What other conclusions can be drawn?