Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how programing distance with RS485 using mikroc

Status
Not open for further replies.

picdad

Newbie level 4
Newbie level 4
Joined
May 6, 2014
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
56
Hello everyone,
I'm new here and I need help.
I found rs485 can go to 1200 meters with a speed of 100 kbps. I found an example of mikroC rs485 but the thing I do not understand is how to program RS485 for 1200 meters?
thank you in advance
 

The distance is governed by the driver/receiver ICs and the quality of cable, not by programming.
They work using standard serial data from a USART and if necessary, a direction control signal from an I/O pin. RS485 is just the electrical specification, not the data.

Brian.
 
  • Like
Reactions: picdad

    picdad

    Points: 2
    Helpful Answer Positive Rating
Hi,

Baudrate and distance depend on each other. The higher the baud rate, the shorter the distance.

You don't have to program the distance, just set the baudrate to 100kbps or less.
Mind to use a 120 Ohms twisted pair cable, enough wire diameter and to use terminating resistors.

Hope this helps.
Klaus
 
  • Like
Reactions: picdad

    picdad

    Points: 2
    Helpful Answer Positive Rating
What Factors Limit the RS-485 Data Rate?
The following factors affect how far one can reliably transmit at a given data rate:
- Cable length: At a given frequency, the signal is attenuated by the cable as a function of length.
- Cable construction: Cat5 24AWG twisted pair is a very common cable type used for RS-485 systems. Adding shielding to the cable enhances noise immunity, and thereby increases the data rate for a given distance.
- Cable characteristic impedance: Distributed capacitance and inductance slows edges, reducing noise margin and compromising the 'eye pattern'. Distributed resistance attenuates the signal level directly.
- Driver output impedance: If too high, this limits drive capability.
- Receiver input impedance: If too low, this limits the number of receivers that the driver can handle.
- Termination: A long cable can act like a transmission line. Terminating the cable with its characteristic impedance reduces reflections and increases the achievable data rate.
- Noise margin: Bigger is better.
- Slew rate of driver: Slower edges (lower slew rates) enable transmission over longer cable lengths.

Some Empirical Data

The most common cable for RS-485 systems: EIA/TIA/ANSI 568 Cat5 twisted pair.
The data rates obtained for cable lengths of different quality from 300feet to 900feet range from 1Mbps to 35Mbps

Consider all the above you can expect a product term for the speed limit on RS-485 100m*1Mbps = 100 m-Mbps.
Thus 100kbps will go 1000 m. You can get more with Cat6 cable but expensive. The reason is Cat6 is stiffer and more controlled impedance and less likely to have kinks which cause group delay distortion, which translates into jitter on the data edges for random patterns.

Termination load will depend on driver/cable but varies from 100 to 150 Ohms.. Fieldbus uses 54 Ohm single-ended or 108 differential.
 
Last edited:
  • Like
Reactions: picdad

    picdad

    Points: 2
    Helpful Answer Positive Rating
thanks for reply .
but how can i set the baudrate to 100kbps or less ?is it with a 120 Ohms ?
 

huh? baud rate is not determined by R, except as I described.

R is determined by choice of cable & driver.
Baud Rate is set by software and limited by 100m-Mbps product with proper selection of cable and R.
Improper selection will reduce this maximum.
 

how can I fix baud rate to 100 kbps in this program example .


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
char dat[10];                          // buffer for receving/sending messages
char i,j;sbit  rs485_rxtx_pin  at RC2_bit;               // set transcieve pin
sbit  rs485_rxtx_pin_direction at TRISC2_bit;   // set transcieve pin direction
// Interrupt routinevoid interrupt() {  RS485Master_Receive(dat);}void main(){
  long cnt = 0;
  ANSEL  = 0;                          // Configure AN pins as digital I/O
  ANSELH = 0;  C1ON_bit = 0;                        // Disable comparators
  C2ON_bit = 0;    PORTB  = 0;  PORTD  = 0;  TRISB  = 0;  TRISD  = 0;
  UART1_Init(9600);                    // initialize UART1 module
  Delay_ms(100);
  RS485Master_Init();                  // initialize MCU as Master
  dat[0] = 0xAA;  dat[1] = 0xF0;  dat[2] = 0x0F;
  dat[4] = 0;                          // ensure that message received flag is 0
  dat[5] = 0;                          // ensure that error flag is 0
  dat[6] = 0;  RS485Master_Send(dat,1,160);
  RCIE_bit = 1;                        // enable interrupt on UART1 receive
  TXIE_bit = 0;                        // disable interrupt on UART1 transmit
  PEIE_bit = 1;                        // enable peripheral interrupts
  GIE_bit = 1;                         // enable all interrupts  while (1){
                                       // upon completed valid message receiving
                                       //   data[4] is set to 255    cnt++;
    if (dat[5])  {                     // if an error detected, signal it
      PORTD = 0xAA;                    //   by setting portd to 0xAA    }
    if (dat[4]) {                      // if message received successfully
      cnt = 0;
      dat[4] = 0;                      // clear message received flag
      j = dat[3];      for (i = 1; i <= dat[3]; i++) {  // show data on PORTB
        PORTB = dat[i-1];
      }                                // increment received dat[0]
      dat[0] = dat[0]+1;               // send back to master      Delay_ms(1);
      RS485Master_Send(dat,1,160);    }   if (cnt > 100000) {      PORTD ++;
      cnt = 0;      RS485Master_Send(dat,1,160);
      if (PORTD > 10)                  // if sending failed 10 times
        RS485Master_Send(dat,1,50);    //   send message on broadcast address
     }  }}

 
Last edited by a moderator:

Hi

In your line UART_Init(9600) you set the baudrate to 9600 bps. That is lower than 100kbps. You are safe with that.

Done.

Klaus
 
  • Like
Reactions: picdad

    picdad

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top