CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Modbus RTU mode on faster PICs

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Modbus RTU mode on faster PICs
PostPosted: Fri Jan 24, 2014 7:05 am     Reply with quote

I have been debugging Modbus RTC on a PIC18F46K80. This is a new processor to me, and its the first time I've run a PIC above 40MHz; I'm running this one at 64MHz.

modbus.c in RTU mode uses timer 2 to generate end of message timeouts. It sets timer 2 up to timeout after approximately 4ms regardless of baudrate. 4ms is about right for the commonest modbus baudrate of 9600baud. The Modbus spec states it should be a multiple of the character time, and therefore depends on baudrate, but its common to use a fixed time as modbus.c does.

There is a problem that with faster clock rates, timer 2 cannot generate 4ms with the timer parameters modbus.c uses. It appears that modbus.c can set up the timer correctly at up to 20MHz - the offset needs to be more than eight bits at higher clock rates. Modbus.c could be modified, by altering the postscale value, to run at up to 64MHz. Also if higher baudrates are used then, in theory, the timeout could be reduced to match, again by modifying modbus.c.

Instead of trying to modify modbuc.c, I adopted an alternative approach: change formats to Modbus ASCII. This doesn't use timeouts and no timer is used in modbus.c, thus freeing up PIC resources and allowing faster baudrates and PIC clock rates.

I am not sure how this relates to 24 series PICs, which may have different timer implementations.

Here's my advice: use Modbus ASCII where possible with PIC clocks above 20MHz.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jan 29, 2014 12:21 pm     Reply with quote

I have worked on MODBUS drivers for the PIC but I created my own. I have multiple sensors sharing the modbus and they support different baud rates and bus configuration. To deal with this as I interrogate different sensors I use the CPU clock rate and the current UART clock divisor to derive a timer value for the modbus timing. In this way I maintain modbus timing irrespective of CPU speed and the current baud rate.

And, for the record, supporting different baud rates on the same modbus is a crazy thing to do.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Feb 01, 2014 3:28 am     Reply with quote

Quote:
And, for the record, supporting different baud rates on the same modbus is a crazy thing to do.

And surely beyond the scope of the specification.

Regarding the problem in the original post, I understand that RF_Developer refers to the "old"
CCS MODBUS driver. The new layered 2011 drivers are supporting different timer options.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group