|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| module lif_neuron #(
|
| parameter DATA_WIDTH = 16,
|
| parameter THRESHOLD = 16'd1000,
|
| parameter LEAK_RATE = 16'd2,
|
| parameter RESTING_POT = 16'd0,
|
| parameter REFRAC_CYCLES = 4
|
| )(
|
| input wire clk,
|
| input wire rst_n,
|
| input wire enable,
|
| input wire signed [DATA_WIDTH-1:0] synaptic_input,
|
| output reg spike,
|
| output reg [DATA_WIDTH-1:0] membrane_pot
|
| );
|
|
|
| reg [DATA_WIDTH-1:0] potential;
|
| reg [3:0] refrac_counter;
|
|
|
| wire in_refractory = (refrac_counter > 0);
|
|
|
| always @(posedge clk or negedge rst_n) begin
|
| if (!rst_n) begin
|
| potential <= RESTING_POT;
|
| spike <= 1'b0;
|
| refrac_counter <= 4'd0;
|
| membrane_pot <= RESTING_POT;
|
|
|
| end else if (enable) begin
|
| spike <= 1'b0;
|
|
|
| if (in_refractory) begin
|
| refrac_counter <= refrac_counter - 1;
|
| potential <= RESTING_POT;
|
|
|
| end else begin
|
| if (potential + synaptic_input > THRESHOLD) begin
|
| spike <= 1'b1;
|
| potential <= RESTING_POT;
|
| refrac_counter <= REFRAC_CYCLES[3:0];
|
| end else if (potential + synaptic_input < RESTING_POT + LEAK_RATE) begin
|
| potential <= RESTING_POT;
|
| end else begin
|
| potential <= potential + synaptic_input - LEAK_RATE;
|
| end
|
| end
|
|
|
| membrane_pot <= potential;
|
| end
|
| end
|
|
|
| endmodule
|
|
|