Henrick,
The "method" looks OK, but I think you'll have some problems with the math due to integer truncation.
#define nS_per_cycle #v((1000/(OSC/4)))
That line will work ok IF the OSC freq. is an exact multiple of 4mhz.
But if OSC is 10mhz then (OSC/4) is 2.5 and the .5 gets dropped. Then nS_per_cycle would be 500, which is wrong for 10mhz.
Same as with PBP, do the multiplication first to avoid the integer problem.
#define nS_per_cycle #v(1000*4/OSC)
Of course, they are constants, so you could just (4000/OSC).
The same thing happens with ...
#define MB_Frame_Timeout_ns #v((100000000/(MODBUS_BAUDRATE / 11)) * 35)
There are no banking issues to deal with in your code.
hth,




Bookmarks