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

Inter-frame delays in modbus RTU

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



Joined: 04 Nov 2012
Posts: 15

View user's profile Send private message

Inter-frame delays in modbus RTU
PostPosted: Sat Mar 09, 2013 12:02 am     Reply with quote

Hi,

I am working with a device which has RS-485 communication (modbus protocol).

I have used modbus_slave.c example file for this.

Now I have to interface this device with PLC. But while doing this I am facing a problem of inter-frame delays in modbus RTU.

PLC manufacturer is asking for 100 ms of inter-frame delay.

I have checked the modbus.c file and found the delay of 4ms.

What i need to do to make it 100 ms.

Also please let me know that it is advisable or not??

Thanks,
paddy
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Mar 09, 2013 3:41 am     Reply with quote

MODBUS specification requires an inter-frame delay of 3.5 character times to determine end of transmission.
A value of about 100 ms calculates for a baud rate of 300.

A slave has to wait at least for the inter-frame delay after the last character of the master's request before
starting a response. There's no problem to extend this time as long you don't exceed the response timeout.

A commercial PLC can be expected to keep the MODBUS specifications, so it must work with the standard
inter-frame delay. It might optionally accept a longer inter-frame delay from a peer.
polilies



Joined: 24 Dec 2009
Posts: 1

View user's profile Send private message MSN Messenger

adding onewire read func stops modbus
PostPosted: Mon Jun 09, 2014 9:32 am     Reply with quote

compiler version 4.084

Hi !

i'm working on a project that has two PWM out and two ds18B20 temp sensor m and modbus communication . I use 16F877A as micro. one pwm is using pwm module and one is soft pwm. soft pwm uses ccp compare interrupt with timer1. And i use modbus protocol to set separate pwm frequency, duty cycles and read ds18B20 temp values.
But there is a problem with reading ds18B20 temp value and modbus communication. With ds18B20 read command pic doesn't answer any of my modbus query. Without ds18B20 read commands it's all fine. Even device response my queries every 50ms. it's prety perfect for me. (for one register query) i'm adding my code and i'm sorry if it's too confused.

Code:
//#define USE_WITH_PC 1

#include <16f877a.h>
#device *=16
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=4M)
//#use fast_io(D)
//#use fast_io(A)
//#use fast_io(C)


#define MODBUS_TYPE MODBUS_TYPE_SLAVE
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_BAUD 19200
#define MODBUS_SERIAL_ENABLE_PIN PIN_D1
#define MODBUS_SERIAL_RX_ENABLE PIN_D0
#define MODBUS_ADDRESS 23
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define ONE_WIRE_PIN PIN_B2
#define LCD_POWER  PIN_D7
#include <math.h>
#include "1wire.c"
#include "ds1820.c"
#include "Flex_LCD.c"
int1 Ton = 1;
int i = 0;
unsigned int16 pr2 = 254,event_count = 0,pwm_freq_iter = 0,pwm_freq_reminder = 0,duty2_reminder = 0;
unsigned int8 prescalex = 1,dutyx[]= {0,0,0,0};
int8 coils = 0b00000101;
int8 inputs = 0b00001001;   
unsigned int16 hold_regs[] = {25600,25600,65280,0x5500,0x4400,0x3300,0x2200,0x1100};
unsigned int16 input_regs[] = {0x1100,0x2200,0x3300,0x4400,0x5500,0x6600,0x7700,0x8800};
unsigned int16 freq_old = 255,maxduty = 0,freq = 255,freq2 = 255,freq2_old = 255;   
unsigned int16 exc_input[] = {0x1100,0x2200,0x3300,0x4400,0x5500,0x6600,0x7700,0x8800},exc_hold[] = {100,100,255,0x5500,0x4400,0x3300,0x2200,0x1100};
unsigned int8 address = 0,prescale[] = {1,4,16},prescaler[] = {4,5,6},rate = 100,rate2 = 100,rateold = 100,rate2old = 100,temp[] ={0,0,0,0};//,value1 =0,value2 =0,value3 =0;//index=0;//duty_h=0,duty_l=0,duty2_h=0,duty2_l=0,value0 =0,value1 =0,value2 =0,value3 =0,;
unsigned long duty  = 0,duty2 = 0;

#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\modbus.c"
#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\pwm.c"
#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\eeprom_startup.c"
#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\ds1820.c"
/*
#int_ext
void ext_kesmesi()
{
   for(i=0;i<3;i++){
   write_eeprom(i,dutyx[i]);
   delay_us(20);}
   
   write_eeprom(4,make8(pr2,0));
   delay_us(20);
   write_eeprom(5,prescalex);
   delay_us(20);
}
*/
#INT_CCP2
void compare_isr()
{
   if(Ton){//get_timer1()<pwm_freq_iter){
      Ton = 0;
      ccp_2 = pwm_freq_iter - duty2;
      output_low(pin_C1);
   }
   else{
      Ton = 1;
      ccp_2 = duty2;
      output_high(pin_C1);//pinout up buzzer
   }   
   set_timer1(0);
}

void main()
{   
   unsigned int16 *index,ds_counter = 0;   
   unsigned int32 value32;
   signed int16  temp1 = 0, temp2 = 0;
   float value = 5.0;     
   
   set_tris_c(0b10110000);
   //port_b_pullups(TRUE);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);   
   set_timer0(248);                                                               //modbus timer                                                                   
   modbus_init();
   setup_ccp1(CCP_PWM); // Interrupt on compare mode // RC2 buzzer
   setup_ccp2(CCP_COMPARE_INT ); // RC1
   //ext_int_edge(H_TO_L);
   //enable_interrupts(INT_EXT);
   enable_interrupts(INT_CCP2); // Enable interrupt CCP1
   enable_interrupts(GLOBAL);
   ///////////////eeprom//////////////
   //eeprom_startup();
   //set_timer1(0);
   //ccp_2 = duty2;
   //index = &value;   
   ///////////////lcd/////////////////
   
   //output_high(LCD_POWER);  // Turn on power to LCD
   //output_low(LCD_RW);      // Set R/W pin on LCD to a low level
   //lcd_init();              // Initialize the LCD

   //lcd_putc("\fHello World\n");
   //lcd_putc("Line Number 2");
   
   /////////////lcd/////////////////
   
   /*
   // Modbus Adresi dip switch ile belirleme noktası
   if(INPUT(PIN_D2)){
      BIT_SET(address,0);
   }
   if(INPUT(PIN_D3)){
      BIT_SET(address,1);
   }
   if(INPUT(PIN_C4)){
      BIT_SET(address,2);
   }
   if(INPUT(PIN_C5)){
      BIT_SET(address,3);
   }
   if(address = 0){
      #define MODBUS_ADDRESS 0xF7   
   }else{   
      #define MODBUS_ADDRESS address
   }
   */
   while(TRUE)
   {
      if(modbus_kbhit()){modbus_check();}
      for(i=0;i<8;i++){exc_hold[i] = maker(hold_regs[i]);}                             //byte exchange 0 to 1, 1 to 0
      for(i=0;i<8;i++){input_regs[i] = maker(exc_input[i]);}                           //byte exchange 0 to 1, 1 to 0     
      pwm1_conf();
      pwm2_conf();
     
         /*
         #define ONE_WIRE_PIN PIN_D7
         value = ds1820_read();                                                  //DS18B20 read procedure
         printf(lcd_putc,"Temp : %3.1f %cC   ", value, 223);
         temp1 = (signed int16) value*10;
         exc_input[0] = temp1;
         /*
         index = &value;
         for(i=0;i<4;i++)
         value0=make8(value32,0);
         value1=make8(value32,1);
         value2=make8(value32,2);
         value3=make8(value32,3);
         exc_input[0] = make16(value1,value0);
         exc_input[1] = make16(value3,value2);
         */
         //#define ONE_WIRE_PIN PIN_B6
         
         if(ds_counter >= 250){
            ds_counter = 0;
            value = ds1820_read();                                                 //DS18B20 read procedure
            exc_input[0] = (signed int16)(value*10);
            //lcd_gotoxy(1,1);
            //printf(lcd_putc,"Temp : %3.1f %cC   ", value, 223);
         //temp2 = (signed int16) value*10;         
         }else{ds_counter++;}
         /*
         for(i=0;i<4;i++){
            temp[i]=*(index+i);
         }
         exc_input[0] = make16(temp[1],temp[0]);
         exc_input[1] = make16(temp[3],temp[2]);
         //exc_input[2] = make16(make8(value,1),make8(value,0));
         //exc_input[3] = make16(make8(value,3),make8(value,2));
           */       
         rateold = rate;
         rate2old = rate2;
         freq_old = freq;         
         freq2_old = freq2;
   
   }   

}


Modbus.c


++++++++++++++++++++++++++++
Modbus.c, ex_modbus_slave.c, code deleted.

Reason: Forum rule #10
10. Don't post the CCS example code or drivers
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

- Forum Moderator
++++++++++++++++++++++++++++

_________________
just think
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