Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to assign hex value to a variable

Status
Not open for further replies.

j hemangini

Member level 1
Joined
Jul 21, 2008
Messages
35
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,573
assign hex value

I want to creat a code in which there is variabe name let Data_Byte and want assign hex value 0x41, initially to this variable. Binary equivalent of this value is
01000001. According to my requirement after every 100 clock cycle only one bit should be on out pin (from bit no 0 to 7 one by one after every 100 clock cycle).

So the main thing i want to ask is that how can i define this variable and how one bit can be transferred from this value.

thank you.
 

llopacinski2

Newbie level 2
Joined
Aug 8, 2008
Messages
2
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,294
assign hex values in vhdl

If I understood:

vhdl:

signal Data_Byte : std_logic_vector( 7 downto 0) := x"41";

fifth bit:
one_bit <= Data_Byte(5); --(data conversion can be needed)

verilog:

reg [7:0] Data_Byte = 8'h41;

fifth_bit = Data_Byte[ 5];
 

saikat

Member level 2
Joined
Oct 21, 2005
Messages
51
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,286
Location
mumbai
Activity points
1,598
vhdl assign hex

You have to use "signal" not "variable" in order to put it on FPGA pin.

first declare it..
signal Data_Byte : std_logic_vector(7 downto 0);

hex value assignment..
Data_Byte <= x"BC";

For your problem first initialize..
Data_Byte <= x"01";

then every 100th clock edge, left rotate (by one bit) the whole register content.
 

j hemangini

Member level 1
Joined
Jul 21, 2008
Messages
35
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,573
vhdl assign value

thanks for your reply.
now i understood how to define hex value.
But what instruction should i write for shift right.
Thank you.
 

saikat

Member level 2
Joined
Oct 21, 2005
Messages
51
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,286
Location
mumbai
Activity points
1,598
assigning hex values to #define

Shift operators:

Let A = “10010101”

A sll 2 = “01010100” --shift left logical, filled with ‘0’
A srl 3 = “00010010” --shift right logical, filled with ‘0’
A sla 3 = “10101111” --shift left arithmetic, filled with right bit
A sra 2 = “11100101” --shift right arithmetic, filled with left bit
A rol 3 = “10101100” --rotate left by 3
A ror 5 = “10101100” --rotate right by 5

where sll, srl, sla, sra, rol, ror are vhdl keywords.

For your application, you have to use: "A rol 1"
 

j hemangini

Member level 1
Joined
Jul 21, 2008
Messages
35
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,573
shift left logical for hexadecimal

your reply was very helpful for me.
I m very greatful to u.
thank you.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top