Searching \ for '[PIC]: how to use parity checking without effectin' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'how to use parity checking without effectin'.

Exact match. Not showing close matches.
'[PIC]: how to use parity checking without effectin'
2005\12\06@141705 by

Hi to all engineers,

as soon as I add parity checking in main PS2 routine the clock
timing gets shifted that is because of adding more clock cycle.
My question is what is the best way of doing parity checking without
effecting the clock ?
should parity checking be done outside the routine ?
any suggestion will appreciate.

here is the code I came up so far

void ps2_out(BYTE data)
{
BYTE i;
int parity = 1;           // 1=ODD, 0=EVEN         <<< 1st time
int data_copy;     //
data_copy = data;         // copy of data
output_low(PS2_CLK_OUT);  // <<< start bit
output_low(PS2_DATA_OUT); // <<<
delay_us(35);
data_copy &= 0x7f;            // <<< Parity "trim to 7 bit ASCII"
parity ^= (data_copy & 1);    // <<< Parity "2nd time"
for(i=0; i<8; i++)
{
parity ^= ((data_copy >> i) & 1);  // <<< Parity "3rd time"
output_bit(PS2_DATA_OUT, shift_left(&data,1,0)); //  shift data
LSB first
output_high(PS2_CLK_OUT); // data can be changed on clock high
delay_us(35);
output_low(PS2_CLK_OUT); // data is valid when clock is low
delay_us(35);
}
if (parity==0){output_low(PS2_DATA_OUT);} // odd
if (parity==1){output_high(PS2_DATA_OUT);} // even
output_high(PS2_CLK_OUT); // clock for parity 9-th bit
delay_us(35);
output_low(PS2_CLK_OUT); // clock for parity 9-th bit
delay_us(35);
//
output_high(PS2_CLK_OUT);  // stop bit
delay_us(35);
output_low(PS2_CLK_OUT);
output_high(PS2_DATA_OUT); // release data line
delay_us(200);
}

thank you

Andre

Andre Abelian wrote:
> as soon as I add parity checking in main PS2 routine the clock
> timing gets shifted that is because of adding more clock cycle.

Whether using a parity bit or not is part of the low level protocol that
both sides must agree on up front.  You can't just decide on one side to
send an extra parity bit when you feel like it.  This is no different than
both sides must agree on the baud rate too.

I would not bother with per-byte parity.  If you're worried about data
integrity over a serial link, add checksums to the higher level protocol.

******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

On Dec 6, 2005, at 11:16 AM, Andre Abelian wrote:

> My question is what is the best way of doing parity checking without
> effecting the clock ?
> should parity checking be done outside the routine ?
>
Either do it outside the routine, or arrange for the the parity
calculation to be done for each bit synchronously and quickly in

parity ^= ((data_copy >> i) & 1);
output_bit(PS2_DATA_OUT, shift_left(&data,1,0));

This is quite slow, and you're duplicating effort.  Something like:
thisbit = shift_left(&data, 1, 0);
parity ^= thisbit;
output_bit(PS2_DATA_OUT, thisbit);

Does it actually MATTER that your clock is being shifted?  I
didn't think the PS2 interface required that the waveform be
very "square" as long as edges were in the right places...

if (parity==0){output_low(PS2_DATA_OUT);} // odd
if (parity==1){output_high(PS2_DATA_OUT);} // even

Surely "output_bit(PS2_DATA_OUT, parity)" ?

BillW
Olin,

PS2  requires to send or receive parity 9th bit on each byte.

thanks

Andre

Olin Lathrop wrote:

{Quote hidden}

Andre Abelian wrote:
> PS2  requires to send or receive parity 9th bit on each byte.

Then what's the problem?  It sounds like there is already a time slice or
clock pulse allocated to parity, so just fill it in.  The comment about the
clock getting messed up doesn't make any sense then.

******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...