module Perceptron(x, y, z, out, error)
input x, y, z
output out
wire x, y, z
wire out
wire error
reg bias
reg weight1
reg weight2
reg weight3
reg weight4
bias = 1;
weight1 = 1;
weight2 = -1;
weight3 = -1;
weight4 = -1;
always @(x, y, z)
begin
reg sum
sum = 0
sum = (x*weight1)
sum = (y*weight2)+sum
sum = (z*weight3)+sum
out = (bias*weight4)+sum
end
if (error !=(Z or 0))
begin
reg correction
correction = .001
weight1 = (x*error*correction)+weight1
weight2 = (y*error*correction)+weight2
weight3 = (z*error*correction)+weight3
weight4 = (bias*error*correction)+weight4
end
endmodule
sum = (y*weight2)+sum;
sum = 0
sum = (x*weight1)
sum = (y*weight2)+sum
sum = (z*weight3)+sum
out = (bias*weight4)+sum
module Perceptron(x, y, z, out, error);
input x, y, z;
output out;
wire x, y, z;
wire out;
wire error;
reg correction;
reg bias;
reg weight1;
reg weight2;
reg weight3;
reg weight4;
reg weightedinput1, weightedinput2, weightedinput3, weightedbias;
bias <= 1;
weight1 <= 'd1;
weight2 <= 'd-1;
weight3 <= 'd-1;
weight4 <= 'd-1;
always @(*);
begin
weightedinput1 <= (x*weight1);
weightedinput2 <=(y*weight2);
weightedinput3 <= (z*weight3);
weightedbias <= (bias*weight4);
out = weightedinput1+weightedinput2+weightedinput3+weightedbias;
end
if (error !=(Z or 0))
begin
correction = 'd.001;
weight1 <= (x*error*correction)+weight1;
weight2 <= (y*error*correction)+weight2;
weight3 <= (z*error*correction)+weight3;
weight4 <= (bias*error*correction)+weight4;
end
endmodule
TSLexi
Would mind answering a couple of questions?
1) Do you intend to ever implement this code in an FPGA?
2) What tools are you using to synthesize or otherwise error-check your code?
3) Could you describe for us, in words or a diagram, how your Perceptron would be represented in hardware? What is the data flow? What hardware elements (i.e. memories, flip flops, lookup tables, etc) are required to make one?
The reason I ask is that your code still does not represent hardware in any way and has many syntactical errors.
For example:
1) there are no semi-colons after always statements
2) I had mentioned that always @(*) is for combinatorial blocks. For synthesizeable RTL, combinatorial blocks may only have blocking (i.e. =) assignments
3) Sequential blocks (i.e. always @ (posedge clock)) , for synthesizeable RTL, should only use non-blocking assignments (i.e. <=)
4) Non blocking assignments should not be used outside of an always block
5) You cannot mix blocking and non-blocking assignments in an always block
6) You are still using real numbers. OK, if you just want to simulate, bad for synthesis
I suggest you check out a site like fpga4fun that has lots of code examples and tutorials that will guide you in creating proper combinatorial and sequential templates for synthesis, and give you an idea of the types of hardware that often get implemented.
I assume you will eventually want to implement this code in hardware, as your goal is to learn about hardware. In order to best do this, take a breath and take the time to get the hardware and Verilog basics down by checking out sites like fpga4fun
r.b.
module Perceptron(x, y, z, out, error);
input x, y, z, error;
output out;
wire x, y, z;
wire out;
wire error;
real correction;
real bias;
real weight1;
real weight2;
real weight3;
real weight4;
real weightedinput1, weightedinput2, weightedinput3, weightedbias;
initial
begin
assign weight1 = 1;
assign weight2 = -1;
assign weight3 = -1;
assign weight4 = -1;
assign bias = 1;
assign correction = .001;
end
always(x or y or z);
begin
assign weightedinput1 <= (x*weight1);
assign weightedinput2 <= (y*weight2);
assign weightedinput3 <= (z*weight3);
assign weightedbias <= (bias*weight4);
assign out = weightedinput1+weightedinput2+weightedinput3+weightedbias;
end
always(error);
if (error !=(Z or 0))
begin
assign weight1 <= (x*error*correction)+weight1;
assign weight2 <= (y*error*correction)+weight2;
assign weight3 <= (z*error*correction)+weight3;
assign weight4 <= (bias*error*correction)+weight4;
end
endmodule
HI
Your diagram is a pretty high level system diagram and does not show the feedback that you verbally describe, in which the weights are modified and the result stored. This storage means you will need sequential circuitry (i.e. flip flops). The code you wrote has no sequential blocks in it.
Just a bit to learn. No IP core will work with real variables. Float can be used, but not in simple behavioral statements as you are writing. Scaling the calculation to use integer or fixed point values would be the next step in a HDL design dedicated for synthesis in hardware.I'm going to do simulation on my CIS lab's computer until I buy a device board, and then just use an IP core to do the math.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?