Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - swapping bits in a byte

 
Thread Tools Search this Thread
Old 04-04-2007, 03:50 PM   #1
Default swapping bits in a byte


Hi Folks!

We have an XC2C64A cpld here. It is used as a bit more complex Bus
buffer, lets say an enhanced 74xx245
It is buffering the lower (D0 - D7) of the databus from 1.8V to 3V
side.
Now we realized one Chip selected by CS4 is connected with its bits
swapped

D0 - D7
D1 - D6
....
D7 - D0

Now we realize that we are too stupid to pimp our exisiting

p18_MD(7 downto 0) <= p33_DATA(7 downto 0) when ( ... )

(the omitted ( ... ) part is mainly bus logic including the
chipselects.)

We need to do an extra part for that regarding CS4, thats clear, but
how do we mirror the data bits in a most efficient manner?

Kind Regards, Konsti


Konstantin Kletschke
  Reply With Quote
Old 04-04-2007, 04:19 PM   #2
Andy
 
Posts: n/a
Default Re: swapping bits in a byte
You can try declaring one of the ports with the reverse range, i.e.
instead of (7 downto 0), use (0 to 7). and then assign as follows:

p18_md <= p33_data when ...

If you are assigning and/or referencing the entire vector, there is no
need to explicitly specify the range (whether you are reversing the
connection or not).

Vector assignments are made bitwise, left to right, regardless of
indexing. However you cannot specify a range on a vector that is the
reverse of the direction with which that vector was declared.

But check your final pinout, since some tools seem to have problems
with reversed range declarations on ports.

If that does not work, write and use a function with a loop to reverse
the bits. Something like:

function reverse_bits (arg: std_logic_vector) return std_logic_vector
is
variable result: std_logic_vector(arg'reverse_range);
begin
for i in arg'range loop
result(i) := arg(i);
end loop;
return result;
end reverse_bits;

Then you can assign:

p18_md <= reverse_bits(p33_data) when ...

Andy



On Apr 4, 9:50 am, Konstantin Kletschke <kon...@ku-gbr.de> wrote:
> Hi Folks!
>
> We have an XC2C64A cpld here. It is used as a bit more complex Bus
> buffer, lets say an enhanced 74xx245
> It is buffering the lower (D0 - D7) of the databus from 1.8V to 3V
> side.
> Now we realized one Chip selected by CS4 is connected with its bits
> swapped
>
> D0 - D7
> D1 - D6
> ...
> D7 - D0
>
> Now we realize that we are too stupid to pimp our exisiting
>
> p18_MD(7 downto 0) <= p33_DATA(7 downto 0) when ( ... )
>
> (the omitted ( ... ) part is mainly bus logic including the
> chipselects.)
>
> We need to do an extra part for that regarding CS4, thats clear, but
> how do we mirror the data bits in a most efficient manner?
>
> Kind Regards, Konsti





Andy
  Reply With Quote
Old 04-07-2007, 02:49 PM   #3
Dave Pollum
 
Posts: n/a
Default Re: swapping bits in a byte
On Apr 4, 9:50 am, Konstantin Kletschke <kon...@ku-gbr.de> wrote:
> Hi Folks!
>
> We have an XC2C64A cpld here. It is used as a bit more complex Bus
> buffer, lets say an enhanced 74xx245
> It is buffering the lower (D0 - D7) of the databus from 1.8V to 3V
> side.
> Now we realized one Chip selected by CS4 is connected with its bits
> swapped
>
> D0 - D7
> D1 - D6
> ...
> D7 - D0
>
> Now we realize that we are too stupid to pimp our exisiting
>
> p18_MD(7 downto 0) <= p33_DATA(7 downto 0) when ( ... )
>
> (the omitted ( ... ) part is mainly bus logic including the
> chipselects.)
>
> We need to do an extra part for that regarding CS4, thats clear, but
> how do we mirror the data bits in a most efficient manner?
>
> Kind Regards, Konsti


1)
signal data : std_logic_vector(7 downto 0);
signal cs4_data : std_logic_vector(7 downto 0);
....
data(7 downto 0) <= cs4_data(0 to 7);

2) Or as Andy suggested:
signal data : std_logic_vector(7 downto 0);
signal cs4_data : std_logic_vector(0 to 7);
....
data <= cs4_data;

-Dave Pollum



Dave Pollum
  Reply With Quote
Old 04-09-2007, 01:38 PM   #4
Andy
 
Posts: n/a
Default Re: swapping bits in a byte
On Apr 7, 8:49 am, "Dave Pollum" <vze24...@verizon.net> wrote:
> On Apr 4, 9:50 am, Konstantin Kletschke <kon...@ku-gbr.de> wrote:
>
>
>
> > Hi Folks!

>
> > We have an XC2C64A cpld here. It is used as a bit more complex Bus
> > buffer, lets say an enhanced 74xx245
> > It is buffering the lower (D0 - D7) of the databus from 1.8V to 3V
> > side.
> > Now we realized one Chip selected by CS4 is connected with its bits
> > swapped

>
> > D0 - D7
> > D1 - D6
> > ...
> > D7 - D0

>
> > Now we realize that we are too stupid to pimp our exisiting

>
> > p18_MD(7 downto 0) <= p33_DATA(7 downto 0) when ( ... )

>
> > (the omitted ( ... ) part is mainly bus logic including the
> > chipselects.)

>
> > We need to do an extra part for that regarding CS4, thats clear, but
> > how do we mirror the data bits in a most efficient manner?

>
> > Kind Regards, Konsti

>
> 1)
> signal data : std_logic_vector(7 downto 0);
> signal cs4_data : std_logic_vector(7 downto 0);
> ...
> data(7 downto 0) <= cs4_data(0 to 7);
>
> 2) Or as Andy suggested:
> signal data : std_logic_vector(7 downto 0);
> signal cs4_data : std_logic_vector(0 to 7);
> ...
> data <= cs4_data;
>
> -Dave Pollum


#1 won't work, since it is not legal VHDL. You cannot specify a range
on an object that is the reverse direction of how the object was
declared.

Andy



Andy
  Reply With Quote
Old 04-10-2007, 11:45 AM   #5
Benjamin Todd
 
Posts: n/a
Default Re: swapping bits in a byte
How about using a simple mux?

err, in a process create

if cs4_sel = '1' then
data <= data_swapped_around;
else
data <= data_not_swapped_arround;
end if;

then inside your code tie the data_swapped_around to the pins as required by
the chip on CS4, data_not_swapped_around should be connected to the original
data.

You'll have to make sure you don't violate any timing requirements with the
added latency of a mux though.

or if you need a fully synchronous design you might add a register on the
output. Even so, I think an eight bit mux is pretty compact for a CPLD.

Ben




Benjamin Todd
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bits from Bill: Death to the DVD Disc is Coming Ablang DVD Video 34 01-25-2008 02:52 AM
Anyone encountered this Problem yet???? (Digital Bits Report) Film Buff DVD Video 8 10-16-2005 11:51 PM
Where is Digital Bits? Are they down???? Film Buff DVD Video 1 06-17-2005 02:42 PM
Digital Bits? anon DVD Video 3 10-02-2004 04:51 AM
DVD Verdict reviews: PABLO FRANCISCO: BITS AND PIECES and more! DVD Verdict DVD Video 0 09-08-2004 10:06 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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 36 37 38 39 40 41 42 43 44 45 46