# FPGA Implementation of IEC-61131-3-Based Hardware Aided Counters for PLC
## 3 FPGA Counters Implementations
### Software-Like Counters

Table 3: Direct comparison of designed counter block. The comparison of execution times for proposed in the paper units is presented in Table 5.

Most often, control programs do not use all the functionality of counters. An example of a program that only realizes counting up events (CU), allows clearing the counter state (R), and also reads its binary output (QU)--indicating that the setpoint (PV) has been reached--is presented in Table 6.

As can be seen from Table 6, the program executed with the use of operators for the circuits of Figures 7 and 8 has the best time performance. It is also worth noting that in the case of solutions from Figures 12 and 13, only one operator command containing the default CAL instruction can be used, while the remaining commands can be as in the solution from the middle columns. The execution time of the program so written will then be equal to the execution time of the program from the middle column. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & **Hard** & **Soft-Like** & **Hard** & **Soft-Like** & **Hard** & **SOft-Like** \\  & **Figure 7** & **Figure 8** & **Figure 12** & **Figure 13** & **Figure 12** & **Figure 13** \\  & **(OPs)** & **(OPs)** & **(one CAL)** & **(one CAL)** & **(OP + CAL)** & **(OP + CAL)** \\ \hline Frequency [MHz] & 300 & 200 & 300 & 200 & 300 & 200 \\ Basic instruction & 3.33 & 5 & 3.33 & 5 & 3.33 & 5 \\ Execution time [ns] & 26.67 & 40 & 30 & 45 & 36.65/30 & 55/45 \\ Program & \multicolumn{2}{c}{Listing 7a} & \multicolumn{2}{c}{Listing 7b} & \multicolumn{2}{c}{Listing 7c/Listing 7d} \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Example program execution times. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & **S7-319** & **S7-319** & **S7-315** & **S7-315** & **S7-121 AC** & **S7-1516** & **S7-1516** \\  & **Classical** & **IEC Counter** & **Classical** & **IEC Counter** & **Classical** & **IEC Counter** \\  & **Counter** & **I6 bit** & **Counter** & **I6 bit** & **32 bit** & **Counter** & **32 bit** \\ \hline Full Counter & 957/106 & 1228/136 & 7700/59 & 26,730/206 & 7050/176 & 720/65 & 932/85 \\ Only CU Input & 137/15 & 108/12 & 1050/8 & 19,630/151 & 1430/36 & 100/9 & 162/15 \\ Only CD Input & 133/15 & 40/4/5* & 1140/9 & 1000 /7-5* & 90/70 /24* & 90/8 & 120/11* \\ Present Counter & 197/22 & 80/*9 & 1350/10 & 2200 /17* & 1800 /45* & 100/9 & 147/13* \\ Reset Counter & 114/13 & 80/*9 & 790/6 & 1500 /11.5* & 1240 /31* & 100/9 & 143/13* \\ Read QU & N\_A & 40/*/5* & N\_A & 900 /7 * & 410 */10* & N\_A & 120 /11* \\ Read QD & 41/45 & 30/*3* & 510/4 & 500 */4 & 200 /5* & 70/6 & 130 */12* \\ Read CV & 114/13 & 20 */2* & 1050/8 & 100 */7.5* & 1000 */25* & 70/6 & 110 */10* \\ Basic instr.: & & & & & & & \\ load memory bit & 9 & 130 & 130 & 40 & 11 & 11 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Comparison times of counters operators’ execution times for Simatic Controllers. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & **Hard** & **Hard** & **Hard** & **Soft-Like** & **Soft-Like** & **Soft-Like** \\  & **Figure 7** & **Figure 8** & **Figure 12** & **Figure 13** & **Figure 13** \\  & **(OPs)** & **(one CAL)** & **(OP + CAL)** & **(OP)** & **(one CAL)** & **(OP + CAL)** \\ \hline Frequency [MHz] & 300 & 300 & 300 & 200 & 200 \\ Full Counter & 53.28/16 & 56.61/17 & 113.4/32 & 80/16 & 85/17 & 160/32 \\ Only CU Input & 6.67/2 & 10/3 & 10/3 & 10/2 & 10/2 & 10/2 \\ Only CD Input & 6.67/2 & 10/3 & 10/3 & 10/2 & 10/2 & 10/2 \\ Preset Counter & 6.67/2 & 10/3 & 10/3 & 10/2 & 10/2 & 10/2 \\ Reset Counter & 6.67/2 & 10/3/ & 10/3 & 10/2 & 10/2 & 10/2 \\ Reset Counter & 6.67/2 & 6.67/2 & 6.67/2 & 10/2 & 10/2 & 10/2 \\ Read QU & 6.67/2 & 6.67/2 & 6.67/2 & 10/2 & 10/2 & 10/2 \\ Read QD & 6.67/2 & 6.67/2 & 6.67/2 & 10/2 & 10/2 & 10/2 \\ Read CV & 6.67/2 & 6.67/2 & 6.67/2 & 10/2 & 10/2 & 10/2 \\ Basic instr.: & & & & & & \\ load memory bit & 3.33 & 3.33 & 3.33 & 5 & 5 & 5 \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Comparison of execution times for proposed in the paper units.