It's pretty obvious you are trying to write Verilog code without even knowing anything about the language. You need to read at minimum a tutorial on basic syntax.
Here are the first three that show up on google.
http://www.ece.umd.edu/class/enee359a.S2008/verilog_tutorial.pdf
http://euler.ecs.umass.edu/ece232/pdf/03-verilog-11.pdf
Interesting observation is they are all from Universities, so maybe your university has one too?
Use 2001 port declarations avoids missing ports.
Code Verilog - [expand] |
1
2
3
4
| module demux(DataIn,Initch,packsize,newpack,DataOut);
input [7:0] DataIn;
output [7:0] DataOut;
input newpack; |
would instead be:
Code Verilog - [expand] |
1
2
3
4
5
6
7
| module demux (
input [7:0] DataIn,
????? Initch, // based on later code is this an output?
????? packsize, // based on later code is this an output?
input newpack,
output reg [7:0] DataOut // includes reg declaration in the port, don't need to repeat DataOut multiple times.
); |
Unnecessary and wrong stuff, you are also missing some required declarations for active and CurrentCh.
Code Verilog - [expand] |
1
2
| wire newpack; // unnecessary, wire is the default
reg[7:0] DataIn; // wrong can't do this, reg cannot be applied to an input port |
This is wrong too.
Code Verilog - [expand] |
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
| always @(posedge clk) // when positive edge is one
begin:demux
if (newpack == 1'b1) begin // when newpack is 1
// can't use assign inside a procedural block
assign Initch=DataIn[4:7];
assign Packsize=DataIn[0:3];
assign active=1;
assign CurrentCh=Initch;
// use non-blocking assignments in registered (FF) code
Initch <= DataIn[4:7];
Packsize <= DataIn[0:3];
active <= 1; // active is not declared, Verilog unless a compiler is informed otherwise will automatically create active VERY BAD CODING STYLE.
CurrentCh <= Initch; // same problem as active.
// this is plain wrong, You are using the for loop for software code, it's not software it's for replication.
// this occurs instantly in 0 time and is therefore exactly the same as:
// DataOut = 8'b0;
for (i=0; i<=7; i=i+1) begin // for next column to be zero as in figure1
DataOut[i]= 0;
end
// this code will then reassign in the SAME CLOCK CYCLE the DataOout[CurrentCh] with DataIn,
// which means the previous assignment of DataOut = 8'b0; never happens.
DataOut[CurrentCh]=DataIn; // should be non-blocking
CurrentCh=CurrentCh+1; // shoudl be non-blocking
end |
Never use blocking assignments (=) in edge triggered (clocked) code use non-blocking assginments (<=), which do emulated the behavior of a registers (FFs). Use blocking assignments only in combinational code.
You need to get and read a Verilog book your entire code is filled with numerous syntax errors and wrong thinking (software) of how to use Verilog.
Also you should know what the circuit described looks like in terms of FFs, logic, and pipeline before writing code. Otherwise it's much more difficult to write the description of the circuit in an HDL (Hardware
Description Language).