DSPRelated.com
Forums

A Puzzle for Today

Started by Tim Wescott April 5, 2009
On Mon, 06 Apr 2009 12:18:55 -0400, Jerry Avins wrote:

> Vladimir Vassilevsky wrote: >> >> >> >>> Vladimir Vassilevsky wrote: >>> >>>> We have to transmit RS-232 by the AC coupled line. Hence the signal >>>> has to be DC balanced, i.e. have equal amount of ones and zeroes. How >>>> many bit combinations like that can be made of one byte? How about >>>> the general case of the block of N bytes? >> >> [...] >> >> You guys are professionals, so the quiz appeared to be too basic for >> you. Here is more complicated: >> Suggest a systematic procedure to map the natural numbers 0...N into >> the abovementioned DC balanced code and back for the general case of M >> bit words. LUT is not a solution. >> >> >> Vladimir Vassilevsky >> DSP and Mixed Signal Design Consultant http://www.abvolt.com > > RS-232 is a partial connector specification (25 pins) and a voltage > specification (respond to so-and-so, withstand such-and-such) amd stuff > about start and stop bits. The number of data bits is not part of the > specification, nor is the inclusion of parity or any other error > control. This is an interesting problem, but poorly put. As posed, 256 > codes can be achieved by using one start bit (space), one stop bit > (mark), eight data bits, and even parity. Many UARTs can be so > configured. > > Jerry
But the one parity bit won't DC balance the other eight bits. You'd need eight bits to DC balance an arbitrary 8-bit pattern. -- http://www.wescottdesign.com
On Mon, 6 Apr 2009 07:55:29 -0700, Mark Borgerson
<mborgerson@comcast.net> wrote:

>In article <ffoCl.25951$YU2.25005@nlpi066.nbdc.sbc.com>, >antispam_bogus@hotmail.com says... >> >> >> >> > Vladimir Vassilevsky wrote: >> > >> >>We have to transmit RS-232 by the AC coupled line. Hence the signal has >> >>to be DC balanced, i.e. have equal amount of ones and zeroes. How many >> >>bit combinations like that can be made of one byte? How about the >> >>general case of the block of N bytes? >> >> [...] >> >> You guys are professionals, so the quiz appeared to be too basic for >> you. Here is more complicated: >> Suggest a systematic procedure to map the natural numbers 0...N into the >> abovementioned DC balanced code and back for the general case of M bit >> words. LUT is not a solution. >> >> >If you're not worried about channel bandwidth, why not simply transmit >N, followed by N^0xFFFF (to as many bytes width as required)? You >balance the line and you get a simple method to check for single-byte >transmission errors. > >Mark Borgerson
That scheme essentially groups bits into pairs. Not surprisingly, the more bits you group together, the higher the efficiency:- 2/4 => 0.50 6/16 => 0.64 20/64 => 0.72 70/256 => 0.77 252/1024 => 0.80 924/4096 => 0.82 3432/16384 => 0.84 12870/65536 => 0.85 48620/262144 => 0.86 etc.
Tim Wescott wrote:
> On Mon, 06 Apr 2009 12:18:55 -0400, Jerry Avins wrote: > >> Vladimir Vassilevsky wrote: >>> >>> >>>> Vladimir Vassilevsky wrote: >>>> >>>>> We have to transmit RS-232 by the AC coupled line. Hence the signal >>>>> has to be DC balanced, i.e. have equal amount of ones and zeroes. How >>>>> many bit combinations like that can be made of one byte? How about >>>>> the general case of the block of N bytes? >>> [...] >>> >>> You guys are professionals, so the quiz appeared to be too basic for >>> you. Here is more complicated: >>> Suggest a systematic procedure to map the natural numbers 0...N into >>> the abovementioned DC balanced code and back for the general case of M >>> bit words. LUT is not a solution. >>> >>> >>> Vladimir Vassilevsky >>> DSP and Mixed Signal Design Consultant http://www.abvolt.com >> RS-232 is a partial connector specification (25 pins) and a voltage >> specification (respond to so-and-so, withstand such-and-such) amd stuff >> about start and stop bits. The number of data bits is not part of the >> specification, nor is the inclusion of parity or any other error >> control. This is an interesting problem, but poorly put. As posed, 256 >> codes can be achieved by using one start bit (space), one stop bit >> (mark), eight data bits, and even parity. Many UARTs can be so >> configured. >> >> Jerry > > But the one parity bit won't DC balance the other eight bits. You'd need > eight bits to DC balance an arbitrary 8-bit pattern.
Duh! Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
Mark Borgerson wrote:
> antispam_bogus@hotmail.com says... >>> Vladimir Vassilevsky wrote: >>> >>>> We have to transmit RS-232 by the AC coupled line. Hence the >>>> signal has to be DC balanced, i.e. have equal amount of ones >>>> and zeroes. How many bit combinations like that can be made of >>>> one byte? How about the general case of the block of N bytes? >> >> [...] >> >> You guys are professionals, so the quiz appeared to be too basic >> for you. Here is more complicated: >> >> Suggest a systematic procedure to map the natural numbers 0...N >> into the abovementioned DC balanced code and back for the >> general case of M bit words. LUT is not a solution. > > If you're not worried about channel bandwidth, why not simply > transmit N, followed by N^0xFFFF (to as many bytes width as > required)? You balance the line and you get a simple method to > check for single-byte transmission errors.
Why all that trouble? I am assuming constant bit speed, as in the most normal RS232 transmissions. Simply differentiate the signal, and transmit that. That way each 0..1 transition is balanced by a 1..0 transition. Considering the stop and start bits means that each byte signal is a balanced set of 0..1 and 1..0 transitions. The receiver just sets/resets a single bit with the differentiated signals. You can avoid most high speed problems over the transmission line by shaping the differentiated pulses into 1/2 bit period pulses of the appropriate sign. input __------______------------------____________------____ din/dt __|_____ _____|_________________ ___________|_____ ___ | | | shaped __---___ ___---_______________ _________---___ _ --- --- --- Bits start 0 1 1 1 0 0 1 stop Note that the asynchronous operation of RS232 is preserved. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.

CBFalconer wrote:
> Mark Borgerson wrote: > >>antispam_bogus@hotmail.com says... >> >>>>Vladimir Vassilevsky wrote: >>>> >>>> >>>>>We have to transmit RS-232 by the AC coupled line.
> Simply differentiate the signal, and transmit that.
What if the input is 0xFF or 0x00 ?
> That way each 0..1 transition is balanced by a > 1..0 transition. Considering the stop and start bits means that > each byte signal is a balanced set of 0..1 and 1..0 transitions. > The receiver just sets/resets a single bit with the differentiated > signals.
There is a crude way for recovering the unbalanced binary signal from the AC channel using a Schmidt trigger in the receiver. If the hysteresis is set properly, the signal can be recovered by 0/1 and 1/0 transitions. However this is very unreliable and prone to noise.
> You can avoid most high speed problems over the transmission line > by shaping the differentiated pulses into 1/2 bit period pulses of > the appropriate sign.
You can make all kinds of diffent things but a simple UART is something that is always available and already there. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Vladimir Vassilevsky wrote:
> CBFalconer wrote: >> Mark Borgerson wrote: >>> antispam_bogus@hotmail.com says... >>>
... snip ...
>>>> >>>>> We have to transmit RS-232 by the AC coupled line. > >> Simply differentiate the signal, and transmit that. > > What if the input is 0xFF or 0x00 ?
Look at the diagram (which you snipped). Each character is separated by a quiet period, minimum length the stop-bit. So the transitions always match. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.
On Mon, 06 Apr 2009 13:46:46 -0400, Spehro Pefhany
<speffSNIP@interlogDOTyou.knowwhat> wrote:

>On Mon, 6 Apr 2009 07:55:29 -0700, Mark Borgerson ><mborgerson@comcast.net> wrote: > >>In article <ffoCl.25951$YU2.25005@nlpi066.nbdc.sbc.com>, >>antispam_bogus@hotmail.com says... >>> >>> >>> >>> > Vladimir Vassilevsky wrote: >>> > >>> >>We have to transmit RS-232 by the AC coupled line. Hence the signal has >>> >>to be DC balanced, i.e. have equal amount of ones and zeroes. How many >>> >>bit combinations like that can be made of one byte? How about the >>> >>general case of the block of N bytes? >>> >>> [...] >>> >>> You guys are professionals, so the quiz appeared to be too basic for >>> you. Here is more complicated: >>> Suggest a systematic procedure to map the natural numbers 0...N into the >>> abovementioned DC balanced code and back for the general case of M bit >>> words. LUT is not a solution. >>> >>> >>If you're not worried about channel bandwidth, why not simply transmit >>N, followed by N^0xFFFF (to as many bytes width as required)? You >>balance the line and you get a simple method to check for single-byte >>transmission errors. >> >>Mark Borgerson > >That scheme essentially groups bits into pairs. Not surprisingly, the >more bits you group together, the higher the efficiency:- > >2/4 => 0.50 >6/16 => 0.64 >20/64 => 0.72 >70/256 => 0.77 >252/1024 => 0.80 >924/4096 => 0.82 >3432/16384 => 0.84 >12870/65536 => 0.85 >48620/262144 => 0.86 >etc. >
In general, for a word with 2n bits and the same number of 0's and 1's, there are (2*n)!/(n!*n!) possible numbers, so you can approach efficiency of 1 arbitrarily closely. An 2048-byte number should only need one extra byte to be DC balanced, when optimally mapped. Of course a LUT would not be practical for this, in most cases ;-) Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
Le Sun, 05 Apr 2009 18:36:35 -0500, Tim Wescott a &eacute;crit&nbsp;:

> You have a Very Large Number, expressed as an binary integer, in the > memory of a machine that allows for byte-wide operations. For some > unfathomable reason, you need to determine if this number is evenly > divisible by 17.
Is the % operator (modulus) of the C language can do the trick ? HBV
Habib Bouaziz-Viallet wrote:
> Le Sun, 05 Apr 2009 18:36:35 -0500, Tim Wescott a &eacute;crit : > >> You have a Very Large Number, expressed as an binary integer, in the >> memory of a machine that allows for byte-wide operations. For some >> unfathomable reason, you need to determine if this number is evenly >> divisible by 17. > > Is the % operator (modulus) of the C language can do the trick ? > > HBV
First, the underlying operation is a divide, which I ruled out, and second the % operator only works for data that is within the word size of the machine. Good thinking, though. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
On 8 avr, 16:44, Tim Wescott <t...@seemywebsite.com> wrote:
> Habib Bouaziz-Viallet wrote: > > Le Sun, 05 Apr 2009 18:36:35 -0500, Tim Wescott a &#4294967295;crit : > > >> You have a Very Large Number, expressed as an binary integer, in the > >> memory of a machine that allows for byte-wide operations. &#4294967295;For some > >> unfathomable reason, you need to determine if this number is evenly > >> divisible by 17. > > > Is the % operator (modulus) of the C language can do the trick ? > > > HBV > > First, the underlying operation is a divide, which I ruled out, and > second the % operator only works for data that is within the word size > of the machine.
oooh i see, may be you're focused on performance/size code to achieve this ? A very large number ... what is a very large number ? (long long int) type (64bits) seems as large as a universe for me :-) Habib
> > Good thinking, though. > > -- > > Tim Wescott > Wescott Design Serviceshttp://www.wescottdesign.com > > Do you need to implement control loops in software? > "Applied Control Theory for Embedded Systems" was written for you. > See details athttp://www.wescottdesign.com/actfes/actfes.html