Hi Shawn,
TMR2 interrupts when its value matches what's in PR2. I don't see anything being written to PR2 in the code you posted so I'm assuming that its 0 and therefor TMR2 interrupts when it rolls over from 255 to 0.
You have calculated that the timer "ticks" at 3.2us which is correct but it needs 256 ticks before it interrupts so there's 3.2*256=819.2us between each interrupt. The ISR then counts 120 interrupts so 0.819ms*120=~100ms..... Hmm I must be doing something wrong...
Anyway, you should know that according to the MODBUS specification the correct interframe delay or timout depends on the baudrate at which the network is run. For baudrates of 19200 and below the interframe delay should equal 3.5 characters and for baudrates over 19200 the delay should be fixed at 1750us.
So to meet the specification the delay at 9600baud should be 1/9600*11bits*3.5 = 4ms.
/Henrik.
Bookmarks