• AVR Freaks

AnsweredHot!How does parity bit work ?

Author
Djsarkar
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: offline
2020/08/02 03:59:01 (permalink)
0

How does parity bit work ?

I don't have idea how parity bit work in UART communication. It's look parity bit is use for error detection

Lets assuming we are sending one byte from UART Transmitter to UART receiver

Lets consider frame formats:

• 1 start bit
• 8, data bits
• even parity bit
• 1 stop bits

Could someone explain with example how parity bit detects error?
#1
Jim Nickerson
User 452
  • Total Posts : 6736
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: How does parity bit work ? 2020/08/03 09:24:52 (permalink)
+7 (7)
Homework ? Smile: Smile  Maybe google can help.
#2
crosland
Super Member
  • Total Posts : 2041
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: offline
Re: How does parity bit work ? 2020/08/03 12:19:43 (permalink)
+5 (5)
JANickerson
Maybe google can help.



It definitely can, I checked :)
 
#3
Jim Nickerson
User 452
  • Total Posts : 6736
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: How does parity bit work ? 2020/08/03 12:37:31 (permalink)
0
Smile: Smile
#4
Djsarkar
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: offline
Re: How does parity bit work ? 2020/08/03 21:07:34 (permalink)
0
This is not homework. Lets assuming a situation where we are sending a data from pic microcontroller to computer.

We have configured hardware

• 1 start bit
• 8, data bits
• even parity bit
• 1 stop bits

Baud rate 9600

When have to send two bytes to computer. We send start bit then 8 bit data and then even parity bit.

As it is said, the parity bit is used to detect error. I don't have idea how error will detect. Which type of it detects ? Did this detects when data not be delivered successfully? How does it do?
#5
ric
Super Member
  • Total Posts : 28385
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: How does parity bit work ? 2020/08/03 21:12:33 (permalink)
+3 (3)
Have you bothered reading what parity is yet?
Start at https://en.wikipedia.org/wiki/Parity_bit
You have not revealed WHICH PIC device you are thinking about.
Most 8 bit PICs do NOT have parity generating/checking hardware. You have to write software to calculate parity of a value.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#6
Djsarkar
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: offline
Re: How does parity bit work ? 2020/08/03 23:55:29 (permalink)
0
ric
Have you bothered reading what parity is yet?Start at https://en.wikipedia.org/wiki/Parity_bitYou have not revealed WHICH PIC device you are thinking about.Most 8 bit PICs do NOT have parity generating/checking hardware. You have to write software to calculate parity of a value. 

I have already looked this page. I don't understand all details given in the page If we take an example it can be easy to understand

Assuming we are sending two bytes 0110 1100 and 1001 1100 to Computer

With no parity micro will send total 20 bits to computer like 0 01101100 1 0 10011100 1

What type of error can parity detect?

Does parity check if byte has been transferred or received?
#7
ric
Super Member
  • Total Posts : 28385
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: How does parity bit work ? 2020/08/04 00:08:41 (permalink)
+1 (1)
I assume you are showing the start and stop bits there, so you are only sending 8 data bits.
Is your data actually 8 bits (in which case you need a ninth bit to hold the parity), or is it only 7 bit data, so you can use the 8th bit to hold the parity information?
 
Your two example bytes have different parity, so it's not valid 7 bit data with a parity bit.
 
Parity is extra information that you include with the sent data, that the receiver can check to see if one bit got corrupted.
It is a very weak check. If two bits get corrupted, a parity check won't detect it.
This is all explained in excruciating detail on that Wikipedia page.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#8
Djsarkar
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: offline
Re: How does parity bit work ? 2020/08/04 00:38:32 (permalink)
0
ric
. Parity is extra information that you include with the sent data, that the receiver can check to see if one bit got corrupted.It is a very weak check. If two bits get corrupted, a parity check won't detect it.This is all explained in excruciating detail on that Wikipedia page. 

Assuming micro sending two byte to computer

Physical communication :
start bit, one byte, even parity bit, stop bit, start bit, second byte ,even parity bit, stop bit

In term of binary

0, 1101 1000, 0, 1, 1001 1100, 0, 1

As you said parity detects any currupted bit in the byte. How does it detect currupted bit in a byte. In the communication, if the fourth bit of last byte is currupted how the receiver will know?
post edited by Djsarkar - 2020/08/04 00:49:56
#9
ric
Super Member
  • Total Posts : 28385
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: How does parity bit work ? 2020/08/04 01:39:07 (permalink) ☄ Helpfulby Djsarkar 2020/08/04 02:40:06
+5 (5)
Djsarkar
....
0, 1101 1000, 0, 1, 1001 1100, 0, 1

As you said parity detects any currupted bit in the byte. How does it detect currupted bit in a byte. In the communication, if the fourth bit of last byte is currupted how the receiver will know?

if 1001 1100 0 changes to 1000 1100 0
then the whole value now has an odd number of one bits, so it has changed to odd parity, so the receiver would know there is an error.
Really this is explained in great detail on the Wikipedia page. I am having trouble believing you have read it.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#10
Djsarkar
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2020/07/27 01:14:06
  • Location: 0
  • Status: offline
Re: How does parity bit work ? 2020/08/04 02:08:36 (permalink)
0
ric

if 1001 1100 0 changes to 1000 1100 0then the whole value now has an odd number of one bits, so it has changed to odd parity, so the receiver would know there is an error.believing you have read it. 


Thank you for helping me, now I have understood how parity bit is used.

But now the question arises that how do we set parity bit for particular bit posion ?

How do we know for which bit position in a byte is the parity bit set?
#11
ric
Super Member
  • Total Posts : 28385
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: How does parity bit work ? 2020/08/04 02:15:02 (permalink) ☼ Best Answerby Djsarkar 2020/08/04 02:39:47
+2 (2)
Djsarkar
How do we know for which bit position in a byte is the parity bit set?

You don't know which bit has the error AS IS SPELT OUT ON THE WIKIPEDIA PAGE!
All parity tells you is that there is an error somewhere.
It is the transmitter's job to calculate if the parity bit should be 0 or 1 to make the parity for the whole word even (or odd, whichever you decide to use).
The receiver then checks to see if the parity for the whole word is still even (or odd).
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#12
NorthGuy
Super Member
  • Total Posts : 6295
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: How does parity bit work ? 2020/08/04 07:42:18 (permalink)
+3 (3)
Djsarkar
How do we know for which bit position in a byte is the parity bit set?



For that, you would need several parity bits, also known as Hamming Codes. They're not used in UART.
#13
nigelwright7557
Super Member
  • Total Posts : 471
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: How does parity bit work ? 2020/08/04 10:03:31 (permalink)
0
for error correction you can use hamming codes.
 
#14
Hen
Senior Member
  • Total Posts : 92
  • Reward points : 0
  • Joined: 2018/10/24 04:01:44
  • Location: 0
  • Status: offline
Re: How does parity bit work ? 2020/08/04 20:53:04 (permalink)
0
I find parity in this context quite useless except when you have a tiny baud rate missmatch when either your stop bit or the parity bit may fail, and that is pretty useless anyway...
 
Haamming gets you a little bit longer but if you use the 8-bit size codes you end up loosing alot of *bandwidth*.
 
If you have got freedom and packet oriented communication can be implemented that offers some great features only limited by imagination and effort.
#15
isoar
Starting Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2015/11/23 23:43:41
  • Location: Ottawa, Canada
  • Status: offline
Re: How does parity bit work ? 2020/08/08 16:52:56 (permalink)
+1 (1)
Parity can detect an error of a single bit, but cannot correct it.  If there are more bit errors, parity may not detect it.
 
Even parity:  the number of '1' bits in the set of all data and parity bits is an even integer.
 
Example:
  data 0x55 = 0b01010101 has 4x '1' bits, which is even, so the parity bit is '0' to make the count even.
  data 0x54 = 0b01010100 has 3x '1' bits, which is odd, so the parity bit is '1' to make the count even.
 
If a single-bit in the data or parity bits is flipped upon reception, that's a parity error.  Either a bit in the data, or the parity bit itself, is wrong.  Error recovery depends on the protocol being used, example:  ignore the received character, and / or tell the transmitter to re-transmit the data.
 
Example of calculating even parity on a 8-bits of data in C:
    parity = data;
    parity ^= parity >> 4; // lower 4 bits:  (7^3), (6^2), (5^1), (4^0)
    parity ^= parity >> 2; // lower 2 bits:  (7^5^3^1), (6^4^2^0)
    parity ^= parity >> 1; // lower 1 bit:  (7^6^5^4^3^2^1^0)
    parity &= 1;

In some applications the 9th bit is not used for parity, but for other functions, like addressing two different listening devices.
 
If a CPU supports memory parity generation and detection, and an error is detected in memory (cosmic rays historically caused single bit errors in old dynamic 'DRAM' memory, but modern dynamic memory is much more resistant), it would cause a parity error fault to be triggered, and the application using the memory at the fault address would be aborted.
 
post edited by isoar - 2020/08/08 17:43:38
#16
Jump to:
© 2020 APG vNext Commercial Version 4.5