I have ABSOLUTELY no background in verilog (or digital designs for that matter). Just for ease of simulations of larger analog systems, I thought it would be better to provide hex inputs instead of long chains of binary values. So I decided to write veriloga code that spectre can understand. I know veriloga is superset of verilog and so i wrote the basic code in verilog.
Like I said, I am not a digital designer and from internet tutorials, I picked basic instructions about verilog in an hour and wrote this. Of course this is wrong and gives error.
In addition to having named the variable bcd either as wire and output with the same name (which I presume is not allowed), what other errors have been identified by compiler?
you have a whole bunch of assignments that are all incorrectly done as assignment have to either be done using the assign keyword or done within an always/intial block. If you want to do these assignments as shown, then you have to have to use the always with a begin end block.
e.g.
Code Verilog - [expand]
1
2
3
always@*begin// @* makes the block sensitive to any changes on any of the inputs to the block//... assignment statementsend
Just assigning bcd = code won't convert from hex to bcd.
Hex has numbers from 0000-1111 (0x0 to 0xF)
BCD has numbers from 0000-1001 (0x0 to 0x9) there is no 0xA-0xF
You need to perform the shift and add3 algorithm to do the conversion.
- - - Updated - - -
I get the impression you are trying to get a 32-bit number to be readable as a decimal value.
If this is the case you should just make the simulation display the 32-bit number as an unsigned decimal value or force the simulation to display the value as decimal to the transcript/log window using the $display system task.
e.g.
Code Verilog - [expand]
1
$display("My hex value: %h, the equivalent unsigned decimal %d", hex,{1'b0,dec});
I see some of the mistakes I have made in writing this. Thank you everyone. I will try and fix those!
- - - Updated - - -
Nah,
I am trying to write a hex vector in input for a system which can only take binary bits as inputs. I want to define a box in verilog which will take a hex input from user and will parse it into equivalent binary bits to the system.
I am trying to write a hex vector in input for a system which can only take binary bits as inputs. I want to define a box in verilog which will take a hex input from user and will parse it into equivalent binary bits to the system.
I'm not sure exactly how you expect to use this "user interface". Verilog/VerilogA isn't a user interface language it's a modeling language for simulating. I'm not sure how you expect someone to enter hex inputs and parse them, Verilog doesn't have support for taking input from the keyboard (or at least none that I've found in the LRM). Also as FvM pointed out Hex to binary is simply converting 0-F to 0000-1111. Unfortunately your thread title says you're trying to convert from hex to bcd.