|
|
View previous topic :: View next topic |
Author |
Message |
greenbridge
Joined: 14 May 2018 Posts: 19
|
Modbus poll period |
Posted: Tue Nov 17, 2020 4:42 am |
|
|
Hi,
What would be a physical limitation for the code below in terms of how often the slave unit can be polled by the master ? Previously polling was once per second.
In the new setup polling occurs each 30 milliseconds and the slave does not respond properly.
Any ideas?
Last edited by greenbridge on Thu Mar 25, 2021 3:33 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Tue Nov 17, 2020 5:34 am |
|
|
Generally speaking, as I don't use Modbus, you need to do some basic 'math'.
1st consider the actual baudrate of the connection (19K2 in your case). Now 'do the math'', and see how long it takes a single byte of data to be sent (hint..10 bits are needed, not 8).
2nd decide how big the 'data packet' is and do more 'math' (packet size x transmit time of a byte). That gives you a rough idea of the MINIMUM time to send or receive data.
3rd x2 to x5 that number ! The PIC program has to 'process' the data. As long as there's no floating point calculations, complicated testing, etc., the 'process' should be fast, but it takes time. Having a faster PIC clock will help, though it costs energy to run faster.
As a simple bench test, since it was fine polling at 1 second, cut the time in 1/2, retest. If fine, cut the time in 1/2 again, retest. Eventually it'll fail. When that happens, 2x the time and it'll be working again.....
also..
I see you take 10 ADC samples and float point math. If you use 'Olympic average' you'll get a better reading (it tosses out high and low). Using scaled integers instead of floating point will really speed up the 'math' ! PICs don't do FP very well.... |
|
|
greenbridge
Joined: 14 May 2018 Posts: 19
|
|
Posted: Tue Nov 17, 2020 7:19 am |
|
|
Ok. Thanks. I will check. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Tue Nov 17, 2020 7:32 am |
|
|
And add that if you are 'polling' a modbus slave, you have to send a
complete packet requesting what you want, which has the station address,
the command code, and the CRC. With modbus RTU, there must be at least
3.5 byte times between packets. Then the slave responds, and again
has to send a complete packet. You don't tell us how much data you
are requesting, but obviously this changes the packet size involved.
100mSec is considered quite a fast polling period for serial modbus. On
systems where lots of sensors require polling at this sort of interval, you
end up having to have more masters to avoid congestion on the bus. |
|
|
Jerson
Joined: 31 Jul 2009 Posts: 125 Location: Bombay, India
|
|
Posted: Tue Nov 17, 2020 8:36 pm |
|
|
I have some experience with Modbus and can confirm what Ttelmah has said. The fastest you would want to poll Modbus RTU is 100mS. Going faster than that brings into account all the number crunching that you do on the slave(PIC). Assuming you're getting 30mS hit and miss, I think your code is efficient already.
Looking over your code, the candidate for improvement is adc_read() where you take 10 samples in a loop(check time consumed). I usually do a running average of continuous adc readings. |
|
|
|
|
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
|