Inntele

Modbus CRC16 in any FX PLC

4 posts in this topic

As well known, FX3U-serie in its instruction list has a special instruction FNC188 for Modbus CRC16 calculation, while lower models doesn't have. The library, developed by me, allow to realize the same function in any lower model of PLC, e.g. FX1S, occupying a minimum of program memory, system variables, processing time. In contrast to libraries of other developers, the algorithm of CRC calculation is original and specially sharpened to meet PLC computing capabilities. It does not use traditional methods like rotary shift in FOR-NEXT loop or pre-calculated CRC table, but achieves the same result just using a simple sequence of basic instructions. Below you can see the results for GX IEC Developer (ver.7.03 of compiler): Program memory: FX1S, FX1N, FX2N - 130 steps for entire project + 20 steps for each FB instance FX3S, FX3G - 105 steps for entire project + 20 steps for each FB instance System variables: D - 1 word; Z - 1 word, M - 33 bits, P - 1 label (for entire project) A processing time for different PLCs can be calculated by following formula: T = T1 + T2*nn, where the 'nn' is a quantity of bytes in array, which should be processed into CRC. Thus, for example, with FX3S PLC a processing time to calculate CRC for 124-bytes array will be equal to 9,59 + 20,56*124 = 2559,03 [usec] = 2,56 [ms]. The FB_CRC operates in 16- or 8-bit mode, according to a state of M8161 special flag: 16-bit at M8161=OFF 8-bit at M8161=ON Edited by Inntele
3 people like this

Share this post


Link to post
Share on other sites
On 8/9/2015 at 3:06 PM, Inntele said:

As well known, FX3U-serie in its instruction list has a special instruction FNC188 for Modbus CRC16 calculation, while lower models doesn't have. The library, developed by me, allow to realize the same function in any lower model of PLC, e.g. FX1S, occupying a minimum of program memory, system variables, processing time. In contrast to libraries of other developers, the algorithm of CRC calculation is original and specially sharpened to meet PLC computing capabilities. It does not use traditional methods like rotary shift in FOR-NEXT loop or pre-calculated CRC table, but achieves the same result just using a simple sequence of basic instructions. Below you can see the results for GX IEC Developer (ver.7.03 of compiler): Program memory: FX1S, FX1N, FX2N - 130 steps for entire project + 20 steps for each FB instance FX3S, FX3G - 105 steps for entire project + 20 steps for each FB instance System variables: D - 1 word; Z - 1 word, M - 33 bits, P - 1 label (for entire project) A processing time for different PLCs can be calculated by following formula: T = T1 + T2*nn, where the 'nn' is a quantity of bytes in array, which should be processed into CRC. Thus, for example, with FX3S PLC a processing time to calculate CRC for 124-bytes array will be equal to 9,59 + 20,56*124 = 2559,03 [usec] = 2,56 [ms]. The FB_CRC operates in 16- or 8-bit mode, according to a state of M8161 special flag: 16-bit at M8161=OFF 8-bit at M8161=ON

Hello,

I am using FX3G-PLC with and wrongly selected FX3G-485 BD for modbus connection with meter but finally I realized that modbus communication is not possible with this module.

I am trying to do with RS instruction I need to caluclate CRC for the same I saw you have developed a code for the same kindly help me calculate CRC.

I am using GXworks 2 software Ladder logic and my project is almost completed.

 

 

Share this post


Link to post
Share on other sites

Perhaps a bit late.

but is does work.. from fx3n on there is a function called CRC but this is het crc calculation according to modbus standard. The plc has also Modbus functions, and when you use these the crc is automatically calculated and added. So mo me this CRC function will nog B3 used very often outside an Modbus command.

ik had a similar need for CRC calculation but for modem protocol, this uses another polygon number. These calculations are everywhere on the net in C languages.

I reversed engineered it and wrote this an common ladder, piece of cake and… it works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now