How to mesure baudrate of RS485 and "jitter" in signal - Page 1
Forum section: electronics / beginners

author: Sorama
author_rank: Frequent Contributor
timestamp: August 13, 2024, 08:02:23 am
content: Hello,First time message here...goodmorning from Belgium to everyone !I'm trying to understand my RS 485 domotic system (master/slave) with 8 RS485 buses and 1 UART.First question:I have an Siglent 2104X Plus scope with all the decode options but do not succeed in getting a stable signal: the A and B outputs of the RS 485 driver are shifting horizontally when trigger is set to Normal.That makes it difficult to decode.However, when triggering is set to Pulse than of course there is no jitter, but I feel I have to know what makes this signal dancing.Second question:although I know that the UART (RS232) has 8 bits, 1 stop bit and that communication with RS232 and Hyperterminal software works perfectly, I don't succeed in knowing the baudrate of the RS485 buses.When I mesure the smallest bit (according to me) , the baudrate is something around 344k (see screenshot).I do happen to know that the slave device (a control panel; just one is connected), when communicating, has 3 bytes for RX (7f 3f 00) and 1 byte for TX: 04.I haven't been able to get those bytes properly decoded, as you can see in the attachments.Anyone out there that can help me?any help would be very much appreciated as the manufacturer is no longer....tnx.

author: Siwastaja
author_rank: Super Contributor
timestamp: August 13, 2024, 09:01:52 am
content: Usual RS485 gotchas:1) RS485 is a three-wire bus. Ground (or return) wire is absolutely mandatory. Some devices use mains protective earth as RS485 ground, which is confusing and usually causes EMC/EMI failure, but communication still often works even with such designs; but if you don't haveeven that, but have completely floating grounds, it's likely not going to work at all.2) Additionally to termination (the need of which is probably well known even to young players), you also need biasing. Termination resistors are used twice (once at each end of the bus); biasing resistors are used once at the bus (where exactly does not matter, but often at master). Google for "RS485 fail-safe biasing" for application notes how to calculate them, but do note the name is absurd, fail-safe biasing has absolutely nothing to do with fail-safe, it's a normal operational requirement.3) Note how there are two differing ways to label A and B; basically Wikipedia + a few others, versus most of the manufacturers. There is still enough disagreement about what the standard originally meant and who is right and who is wrong, so that only practical way is to always test swapping these two signals until the communications work. If you need to try out other parameters, too, this doubles the number of permutations; for each experiment you make, you need to test it with A&B swapped and non-swapped.Your way of finding the shortest bit and measure it's period seems correct to me. Expect to see any weird baud rates in RS485 systems. And also any stop bit and parity settings. And remember that even if a standard such as the modbus standard says something about the required parity setting, that does not mean anyone follows these requirements.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 13, 2024, 09:47:04 am
content: Tnx.I’m aware of the gotchas, but these devices are working perfectly.As the bus speed is rather low and cabling is short, (50cm), termination nor grounding is an issue nor will it influence the decoding.As said, at the Uart side I have no issues in decoding correctly.It is before the uart, the RS485 buses who seem to work at a higher baudrate than the uart (uart =19200 baud) that I need to decode the communication (on RS485 level).Because of the horizontal shifting of the signal (A line), I am not sure in what way this influences the decoding.

author: PGPG
author_rank: Frequent Contributor
timestamp: August 13, 2024, 01:19:25 pm
content: Quote from: Sorama on August 13, 2024, 09:47:04 amI probably differently understand UART term as for me speed at UART have to be the same as at RS485.For me UART is typically integrated in microcontroller section controlling serial communication. So microcontroller has TXD and RXD pins connected then to RS485 transceiver. And at UART level (TXD and RXD pins) speed is the same as at RS485 level as RS485 transceiver only changes unbalanced signal TXD into balanced at A and B wires and than back balanced into unbalanced at RXD.Quote from: Sorama on August 13, 2024, 08:02:23 amSerial communication is not periodic signal so you can't get stable view if you trigger several times. You should set Trigger to Single.If you have terminal resistors at both bus ends and you insert a serial resistors in both lines then using oscilloscope you can distinguish frames sent in one direction and the other.

author: tooki
author_rank: Super Contributor
timestamp: August 13, 2024, 01:35:16 pm
content: Quote from: Sorama on August 13, 2024, 09:47:04 amThis cannot be.RS-485 describes ONLY the physical interface — that is, the voltage levels and electrical requirements. It says absolutely nothing about the protocol, speed, etc.An RS-485 transceiver does NOTHING except convert signal levels and drive the bus. You can think of it as some slightly specialized comparators (which is why the schematic symbol is in fact an amplifier). So whatever baud rate goes in is what comes out.Or are the RS-485 buses completely separate from the UART, in which case there’s a microcontroller or something in between?Are you sure the RS-485 buses are evenasynchronous serialat all? They could be some completely unrelated protocol, like DMX.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 13, 2024, 03:32:13 pm
content: tnx.the microcontroller is a (Dallas) DS87C530 (ain't that a 8051 ?), good old stuff with 2 full duplex serial controllers built in.The RS 485 drivers are (behind a mux/demux) going to 1 serial input in the controller, the RS232 (UART) is going to the other.So That explains why 2 different speeds can be maintained, right?As the RS485 is in fact a serial communication, I set the scope to decode UART and the measurement (look at the attachment) of a single bit clearly tells the baudrate is somewhere near 342kbaud.I hope this can help in further analysis?

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 13, 2024, 03:53:38 pm
content: Quote from: Sorama on August 13, 2024, 03:32:13 pmThis microcontroller is indeed 8051 instruction set compatible.Quote from: Sorama on August 13, 2024, 03:32:13 pmCorrect, using two separate UART's for both type of serial communication interfaces means there can be two different speeds.Quote from: Sorama on August 13, 2024, 03:32:13 pmI would not use the term "fact" when stating that RS485 is "a" serial communication. RS485 is a specification for a hardware interface to support serial data transfer.You should connect your scope to the TXD line before the RS485 transceiver to get a better signal to trigger UART (universal asynchronous receiver-transmitter) decoding on. This way you can be sure it is the actual transmission you are looking at and not the balanced copy of it where possible collision can take place.

author: PGPG
author_rank: Frequent Contributor
timestamp: August 13, 2024, 03:57:27 pm
content: Quote from: Sorama on August 13, 2024, 03:32:13 pmOne of the (less common) used baudrate speeds is 3 x 115200 = 345600.https://vesc-project.com/node/391

author: Sorama
author_rank: Frequent Contributor
timestamp: August 13, 2024, 04:03:55 pm
content: Quote from: PGPG on August 13, 2024, 03:57:27 pmHiI have indeed for the moment set the baudrate at 345600, but that still doesn't give me an good decoding (scope says: over length )

author: Sorama
author_rank: Frequent Contributor
timestamp: August 13, 2024, 04:04:56 pm
content: Quote from: pcprogrammer on August 13, 2024, 03:53:38 pmI tried input as well output on the RS485 drivers (output is A, idle high, no need to map both channels and do the math).No difference in behavior of decoding.Shouldn't it be possible to count all the bits to know the content of that diagram?But I find it difficult to do that, given there is also a start and a stop bit somewhere.(And of course a lack of experience :-)

author: tooki
author_rank: Super Contributor
timestamp: August 13, 2024, 04:08:14 pm
content: Quote from: pcprogrammer on August 13, 2024, 03:53:38 pmWhile this is 100% true today from any practical standpoint, I will point out for completeness’ sake that in the past, we also had parallel buses using the RS-485 physical layer, namely Ultra SCSI. TheSN75971BSCSI transceiver chip is essentially just a 9-channel RS-485 transceiver!

author: tooki
author_rank: Super Contributor
timestamp: August 13, 2024, 04:09:45 pm
content: Quote from: Sorama on August 13, 2024, 04:03:55 pmHave you made sure the serial decode settings are actually correct? Not just baud rate, but the polarity, parity, word length, bit order, and stop bits? It may be necessary to play around with these.

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 13, 2024, 05:02:15 pm
content: Very good point from tooki.Read the manual of your scope before trying to use this kind of features. I don't own a Siglent but can imagine that it needs other settings then just selecting UART decoding as a trigger option.

author: tooki
author_rank: Super Contributor
timestamp: August 13, 2024, 05:30:07 pm
content: I don’t know if it has UARTtriggering. I don’t think most scopes do. So you’d want to trigger on a pulse or edge or whatever, ideally using triggering settings like pulse width and holdoff to get a stable trigger before even bothering to try decoding.

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 13, 2024, 06:05:09 pm
content: I would have to look in the manual of the Rigol MS5070 I own to be sure, but if I remember correctly from some experiments you can set a data value to trigger on. If you are expecting a sequence of data that always starts with, for instance, 0xAA you can setup your scope to start recording when it encounters that value.This is what I think of when "using UART triggering" is stated.But as I wrote, read the manual to find out the capabilities of the scope in question.

author: tooki
author_rank: Super Contributor
timestamp: August 13, 2024, 06:12:12 pm
content: Sure, but for trigger-on-data to work, decoding has to work first. Until decoding is set up properly, OP needs to set up a stable edge or pulse trigger.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 14, 2024, 05:31:03 am
content: Quote from: tooki on August 13, 2024, 04:09:45 pmThat’s the actual problem: I don’t know these settings but I have tried all combinations, but to no avail.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 14, 2024, 05:34:41 am
content: Quote from: tooki on August 13, 2024, 05:30:07 pmI have this scope for some years now and indeed, it has uart triggering.But technically this is not a prerequisite, as one can simply trigger on edge on the A of B output of the rs485 driver.Single triggering works perfectly, standard works but with some horizontal shift.I use Single trigger and then tried all combinations of uart decoding settings.

author: rteodor
author_rank: Frequent Contributor
timestamp: August 14, 2024, 06:15:45 am
content: In my experience MSO decoding on I2C fails badly where a cheap LA works well with 5x sampling.I would go medieval on this signal: use vertical cursors to find the bit duration then slide it until you find the correct character size and parity.It could be hard if there is lots of well timed data but otherwise it should be quite easy after a bit of practice.Later clarification: I did not tried UART decoding but I expect it to perform as worse. I got a sense that decoding is done on the "display signal" and not on the actual samples: zoom out too much and it gets confused, slide horizontally and it looses track of the start condition.

author: tooki
author_rank: Super Contributor
timestamp: August 15, 2024, 12:04:27 am
content: Quote from: rteodor on August 14, 2024, 06:15:45 amThat depends entirely on the design of the oscilloscope. The Rigol DS1054Z, for example, decodes from the display data. But most models from the “big” manufacturers (Keysight, LeCroy, Tek, Rhode & Schwarz) decode directly from acquisition memory and thus decode regardless of the zoom level.

author: tooki
author_rank: Super Contributor
timestamp: August 15, 2024, 12:09:31 am
content: Quote from: Sorama on August 14, 2024, 05:34:41 amI assume by “some horizontal shift” you just mean that it’s not necessarily triggering on the same edge in each character. I already said how to fix this: learn to use trigger holdoff (and possibly pulse width trigger) to get a stable trigger on the first edge.Without trigger holdoff you’re just triggering at some random edge or pulse within the character. Holdoff lets you delay rearming the trigger so that it skips the subsequent edges or pulses within the same character.All combinations? You sure about that? That’s a lot of permutations!

author: tooki
author_rank: Super Contributor
timestamp: August 15, 2024, 12:30:16 am
content: Here’s a lousy sketch of what holdoff does. You figure out how long one character is, here apparently around 550 microseconds. You want it to trigger on the first falling edge, but ignore all the others in the character, so you set the holdoff to a bit more, like 700 microseconds. This means that after the first falling edge (where it triggers), the trigger is “paused” until 700 microseconds later, when we are in the pause between characters. Then the trigger rearms and triggers on the first falling edge of the next character. This gives you a nice stable trigger that’s always triggering on the same place.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: August 15, 2024, 02:32:56 am
content: Try sending the bit pattern 10101010This can make it easier to figure out what you're doing wrong.

author: Shay
author_rank: Regular Contributor
timestamp: August 15, 2024, 04:34:14 am
content: Recently I had to "decode" unknown differential protocol. I tried using my rigol scope but I faced the same issue as you, which is a lot of timing jitter. I am not certain what is causing this, might be just bad triggering, but I am certain the device it is connected to samples it at the correct baud rate at the middle of each bit, with or without timing jitter. So, using logic analyzer really helps here as it basically emulates the slave, and it allows you to find patterns and perform quick testing of the protocol, much more comvinent. Next, figure out what is the start byte, as it will always repeat itself, and try to find if there is a CRC - this will help decoding the frame.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 15, 2024, 11:01:13 am
content: Quote from: tooki on August 15, 2024, 12:30:16 amTnx very much.I tried it, but didn’t change the outcome.I tried different delta’s, but triggering never got better.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 15, 2024, 11:04:33 am
content: Quote from: Shay on August 15, 2024, 04:34:14 amAny suggestion regarding a LA?I still wonder wat the first packet is about (see screenshot): it has less bits than what follows later on.Anyone who can translate that first sequence into binary?I'm more of an analog guy, never got into digital.

author: Siwastaja
author_rank: Super Contributor
timestamp: August 15, 2024, 12:26:04 pm
content: Try to decode by eye. That removes one "how to use this feature" uncertainty and forces you to find normal triggering conditions which consistently trigger to the start bit. And of course, first try to send just a single byte.Automatic decoding is a convenience feature since decoding bits by eye is tedious for anything more than a few bytes.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 15, 2024, 12:50:20 pm
content: Quote from: Siwastaja on August 15, 2024, 12:26:04 pmI can’t send anything as it is a domotic system: besides the master system, I have control panels and relay boards but nothing that allows me to send a particular datagram.I tried to decode by eye this first byte attached, but as said, I don’t feel comfortable enough to be sure.That’s why I would appreciate if someone else could, so that I can learn how to read it properly.

author: rteodor
author_rank: Frequent Contributor
timestamp: August 15, 2024, 03:54:25 pm
content: Quote from: Sorama on August 15, 2024, 11:04:33 amIs the width matching on all 6 chars ?To me it looks like 0xA0 followed by a pause and then 5 times 0x00.LE: For the first char I assume that is: 1 start bit + 8 bit data + 1 stop bit (classic 8N1).Please check on the next ones if they have the same duration (cca.460us26us as it looks from over here).With the above assumptions the bit is46us2.6us and that is a bit rate of about21k384615.I would presume this is1920038400 8N1 but I need to see better measurements and more data.LE2: I mixed up the timebases: so its more like 384000 bit rate (as somebody I think mentioned above).

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 15, 2024, 04:53:01 pm
content: Jitter is not so likely, but (semi) static differences in baudrates are unfortunately quite common.For 8-bit data the maximums absolute error between the baudrates of receiver and transmitter is around 4.5% Start bit + 8 data + stop bit = 10 bits, and at the end you must have accumulated less then half a bit time of error.And that error budget gets divided and eaten up in various ways.* Laziness or incompetence for using the right crystal (Especially arduino is notorious for this. 16MHz is quite bad for most baudrates).* Drift when using an internal RC oscillator clock. (Mostly drifts with temperature)* Fractional baud rate generators (These introduce jitter in bit timing but also average out the error, and the total result is mostly quite acceptable)Also, some manufacturers of equipment do about everything to reduce BOM cost. 20+ years ago I bought a PCI card with 2 serial ports, and it's baudrates were about 2.4% off. That's acceptable if the receiving end is perfect, but if the receiving end deviates by the same amount in the other direction then it does not work at all anymore.Also, it does not matter whether you have a high or a low baudrate. If it's over 5% off between transmitter and receiver, then it simply does not work anymore. At lower baudrates you do have to set a bigger divisor in your uC, and this allows for a bit higher resolution in setting the baudrate, but it's not always enough. Atmel used to print big tables with usable baudrates in their datasheets (for example ATMEGA328) Fractional baudrate generators are much better in this regard. Resolution is high enough that any crystal can be used up to quite high baudrates, but there is a limit.More modern communication standards use bit stuffing to guarantee that there is always a signal transition after a certain amount of bits, and this is combined with hardware to re-synchronize on the bits.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 18, 2024, 09:56:59 am
content: Quote from: rteodor on August 15, 2024, 03:54:25 pmI'm sorry, I don't speak Hex :-)I'm not sure I understand you at all: the baudrate is for sure 345600 baud.What do you mean by six chars? Are you sure it is a total of six we're seeing here on the screen ?The first (I don't know which term to use exactly,...diagram, char ?) is for sure an address (87 bits data + 1 parity): it never changes when I press a button on the (slave) control panel.So would you mind to decipher all the bits (including start/stop) in this "address" into binary ?tnx.

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 18, 2024, 05:07:11 pm
content: 1010 0000 = A 0Hexadecimal is very easy. 0 - 9 and A - F for 0 - 15 in decimal or 0000 - 1111 in binary.Works the same as base 2, 8 or 10, but uses 16 as its base.The scope image you provided was zoomed in on the first data set and in the zoomed out version you can see 5 sets of what appear to be all zeros.Edit: The data goes from left to right.start bit is lowmost significant bit is high, then low, high, low, low, low, low, lowstop bit is high

author: rteodor
author_rank: Frequent Contributor
timestamp: August 19, 2024, 04:57:43 pm
content: Quote from: Sorama on August 18, 2024, 09:56:59 am"You must know that you have 16 fingers at your hands."I had this joke on me and now I'm passing it on to youYou also must know: vertical cursors are your friend. Use them.Is the following drawing helping you ?

author: Sorama
author_rank: Frequent Contributor
timestamp: August 20, 2024, 08:28:40 am
content: @rteodor & @pcprogrammer,Now I understand you :-)tnx both of you for explaining this 'bit by bit".Didn't know Hex was in two subsets.Although I have an electronics degree (bachelor, 3 yr) from the late eighties, I can't even remember we talked about hex.Hell, there is a lot I don't remember (anymore)tnx again.

author: rteodor
author_rank: Frequent Contributor
timestamp: August 20, 2024, 09:19:06 am
content: Quote from: Sorama on August 20, 2024, 08:28:40 amThey are often called nibbles.Quote from: SoramaAnd still you are able to handle that scope well.

author: Sorama
author_rank: Frequent Contributor
timestamp: August 20, 2024, 09:53:01 am
content: "And still you are able to handle that scope well."Out of nostalgia I bought this Siglent 2104X Plus in 2021 but actually never used itBecause suddenly I wanted to know how my domotic system works, I got the scope out a few days ago and started reading EEVblog forum.I would love to get into electronics again (you never forget your first love, do you?), but I'm a building 'physicist' now (as a court expert).Nevertheless, I might contact some companies (if there are any left) that do repair of boards as a freelancer (which I am since 1998).Guess it doesn't pay as well as being a court expert.Only one way to find out

author: PGPG
author_rank: Frequent Contributor
timestamp: August 20, 2024, 01:56:34 pm
content: Quote from: Sorama on August 20, 2024, 08:28:40 amNot subsets but digits and nothing limits HEX numbers to two digits.HEX number AA55 equals 43605 decimal and FFFFFFFF equals 4294967295.You can use Windows standard Calculator application to check it.Many years ago when buying calculator I selected CITIZEN SR-135 only because it has HEX numbersAnd one note about decoding that transmission. Typically bytes are send low bit first. So the 1010 0000 would mean not A0 but 05 and if it is an address on bus it is more logical to expect number like 5 than 160 (=A0).

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 20, 2024, 03:35:47 pm
content: Quote from: PGPG on August 20, 2024, 01:56:34 pmDamned you are right. For SPI you can set the bit order and I2C uses msb first. Not sure if there are UART peripherals that allow you to change the bit order.

author: m k
author_rank: Super Contributor
timestamp: August 20, 2024, 03:53:40 pm
content: Start bit is down, stop bit up and lsb first.But from left to right is forward.