module LeakyIntegrateFireNeuron(
input clk, // Clock signal
input reset, // Asynchronous reset, active high
input [7:0] input_current, // Input current (I_ext)
input [7:0] threshold, // Firing threshold (V_thresh)
input [7:0] decay, // Decay value adjusted based on membrane potential sign
input [7:0] refractory_period, // Refractory period in number of clock cycles, now 8 bits
output reg spike_out // Output spike signal, renamed from 'fired'
);
code
reg [7:0] membrane_potential = 8'b0; // Membrane potential (V_m), initialized to 0
reg [7:0] refractory_counter = 8'b0; // Counter to handle the refractory period, initialized to 0
wire signed [9:0] potential_update; // Use a wire for immediate calculation, now 10 bits
// Correctly perform sign extension when computing potential_update
assign potential_update = $signed({membrane_potential[7], membrane_potential[7], membrane_potential}) +
$signed({input_current[7], input_current[7], input_current}) +
(membrane_potential[7] ? $signed({decay[7], decay[7], decay}) : -$signed({decay[7], decay[7], decay}));
always @(posedge clk or posedge reset) begin
// Initialize spike_out at the beginning of the block
spike_out <= 1'b0;
if (reset) begin
// Reset all states immediately when reset is high, regardless of clock
membrane_potential <= 8'b0;
refractory_counter <= 8'b0;
end else begin
if (refractory_counter > 0) begin
// Decrement refractory counter if in refractory period
refractory_counter <= refractory_counter - 1;
end else begin
if (potential_update[9] && potential_update < -128) // Negative overflow (checks if negative and exceeds 8-bit lower bound)
membrane_potential <= 8'b1000_0000; // Set to -128
else if (potential_update > 127) // Positive overflow (checks if exceeds 8-bit upper bound)
membrane_potential <= 8'b0111_1111; // Set to 127
else // No overflow or underflow
membrane_potential <= potential_update[7:0];
if ($signed(membrane_potential) >= $signed(threshold)) begin
// Neuron fires
spike_out <= 1'b1;
membrane_potential <= $signed(membrane_potential) - $signed(threshold); // Subtracting reset
refractory_counter <= refractory_period; // Enter refractory period
end
// No need to set spike_out to 0 here as it's initialized at the top
end
end
end
endmodule
Assistant
Hello! It looks like you've shared a Verilog module for a Leaky Integrate-and-Fire (LIF) neuron model. This module is designed to simulate the behavior of a biological neuron, translating the electrical activity of the neuron into digital signals in a digital circuit. Let's break down the functionality and key aspects of this module:
Module Definition
Inputs:clk: Clock signal for set: Asynchronous reset signal; when active, it resets the neuron's state.input_current(I_ext): the external current input to the neuron.threshold(V_thresh): The threshold voltage at which the neuron fires.decay: Adjusts the decay in membrane potential depending on the potential's sign.refractory_period: Specifies the duration for which the neuron will not fire again after emitting a spike.
clk: Clock signal for synchronization.
reset: Asynchronous reset signal; when active, it resets the neuron's state.
input_current(I_ext): the external current input to the neuron.
threshold(V_thresh): The threshold voltage at which the neuron fires.
decay: Adjusts the decay in membrane potential depending on the potential's sign.
refractory_period: Specifies the duration for which the neuron will not fire again after emitting a spike.
Output:spike_out: Indicates whether the neuron has fired a spike.
spike_out: Indicates whether the neuron has fired a spike.
Inputs:
clk: Clock signal for synchronization.
reset: Asynchronous reset signal; when active, it resets the neuron's state.
input_current(I_ext): the external current input to the neuron.
threshold(V_thresh): The threshold voltage at which the neuron fires.
decay: Adjusts the decay in membrane potential depending on the potential's sign.
refractory_period: Specifies the duration for which the neuron will not fire again after emitting a spike.
clk: Clock signal for synchronization.
reset: Asynchronous reset signal; when active, it resets the neuron's state.
input_current(I_ext): the external current input to the neuron.
threshold(V_thresh): The threshold voltage at which the neuron fires.
decay: Adjusts the decay in membrane potential depending on the potential's sign.
refractory_period: Specifies the duration for which the neuron will not fire again after emitting a spike.
Output:
spike_out: Indicates whether the neuron has fired a spike.
spike_out: Indicates whether the neuron has fired a spike.
Key Variables
membrane_potential(V_m): Represents the current state of the neuron's membrane potential.
refractory_counter: Keeps track of the refractory period following a spike.
membrane_potential(V_m): Represents the current state of the neuron's membrane potential.
User
Can you write me a verilog test bench for the above module?
Assistant
Certainly! Below is an example of a Verilog testbench for theLeakyIntegrateFireNeuronmodule you provided. This testbench will apply a sequence of stimuli to the neuron and observe its behavior, especially how it handles the threshold, decay, and refractory period.
// Inputs
reg clk;
reg reset;
reg [7:0] input_current;
reg [7:0] threshold;
reg [7:0] decay;
reg [7:0] refractory_period;
// Outputs
wire spike_out;
// Instantiate the Unit Under Test (UUT)
LeakyIntegrateFireNeuron uut (
.clk(clk),
.reset(reset),
.input_current(input_current),
.threshold(threshold),
.decay(decay),
.refractory_period(refractory_period),
.spike_out(spike_out)
);
// Clock generation
initial begin
clk = 0;
forever #10 clk = !clk; // Clock period of 20 ns
end
// Stimulus application
initial begin
// Initialize inputs
reset = 1; // Assert reset initially
input_current = 0;
threshold = 50; // Set threshold to 50
decay = 5; // Set decay value
refractory_period = 5; // Set refractory period to 5 clock cycles
// Release reset
#25 reset = 0;
// Stimulus 1: Small input current, no spike
input_current = 10;
#40;
// Stimulus 2: Larger current to trigger spike
input_current = 60;
#20;
// Stimulus 3: Check refractory behavior, should not spike despite high current
input_current = 60;
#100;
// Stimulus 4: After refractory period, should be able to spike again
input_current = 60;
#100;
// Complete the test
#50 $finish;
end
// Optional: Monitoring changes
initial begin
$monitor("Time = %t, Input Current = %d, Membrane Potential = %d, <REDACTED> = %b", $time, input_current, uut.membrane_potential, spike_out);
end
User
can you add more cases?
Assistant
Sure, I can add more test cases to the Verilog testbench to cover a broader range of scenarios and ensure the module behaves as expected under various conditions. Here’s an extended version of the testbench with additional test cases:
// Inputs
reg clk;
reg reset;
reg [7:0] input_current;
reg [7:0] threshold;
reg [7:0] decay;
reg [7:0] refractory_period;
// Outputs
wire spike_out;
// Instantiate the Unit Under Test (UUT)
LeakyIntegrateFireNeuron uut (
.clk(clk),
.reset(reset),
.input_current(input_current),
.threshold(threshold),
.decay(decay),
.refractory_period(refractory_period),
.spike_out(spike_out)
);
// Clock generation
initial begin
clk = 0;
forever #10 clk = !clk; // Clock period of 20 ns
end
// Stimulus application
initial begin
// Initialize inputs
reset = 1; // Assert reset initially
input_current = 0;
threshold = 50; // Set threshold to 50
decay = 5; // Set decay value
refractory_period = 10; // Set refractory period to 10 clock cycles
// Release reset
#25 reset = 0;
// Test Case 1: Small input current, no spike expected
input_current = 10;
#40;
// Test Case 2: Sufficient current to trigger a spike
input_current = 60;
#20;
// Test Case 3: Check refractory behavior, no spike should occur despite high current
input_current = 60;
#200;
// Test Case 4: Neuron should fire again after refractory period
input_current = 60;
#100;
// Test Case 5: Check for decay effects on membrane potential
input_current = 30;
#200;
// Test Case 6: Trigger firing at the edge of threshold
input_current = threshold - uut.membrane_potential; // Adjust current to just reach threshold
#40;
// Test Case 7: Negative input current to test decay in negative direction
input_current = 0;
#40;
input_current = -10; // Apply negative current
#100;
// Test Case 8: Reset during operation
input_current = 50;
#30;
reset = 1; // Assert reset to clear state
#10;
reset = 0; // Release reset
#40;
// Test Case 9: Consistent low-level input to check gradual potential increase
input_current = 15;
#400;
// Test Case 10: Zero input with non-zero decay to see if potential naturally decays to zero
input_current = 0;
#300;
// Complete the test
#50 $finish;
end
// Optional: Monitoring changes
initial begin
$monitor("Time = %t, Input Current = %d, Membrane Potential = %d, <REDACTED> = %b", $time, input_current, uut.membrane_potential, spike_out);
end
User
thank you.
As shown in the following Verilog module, the LIF module has been modified by adding an enable input. Can you also change the test bench module accordingly?
module LeakyIntegrateFireNeuron(
input clk, // Clock signal
input reset, // Asynchronous reset, active high
input enable, // Enable input for updating the neuron
input [7:0] input_current, // Input current (I_ext)
input [7:0] threshold, // Firing threshold (V_thresh)
input [7:0] decay, // Decay value adjusted based on membrane potential sign
input [7:0] refractory_period, // Refractory period in number of clock cycles, now 8 bits
output reg spike_out // Output spike signal, renamed from 'fired'
);
code
reg [7:0] membrane_potential = 8'b0; // Membrane potential (V_m), initialized to 0
reg [7:0] refractory_counter = 8'b0; // Counter to handle the refractory period, initialized to 0
wire signed [9:0] potential_update; // Use a wire for immediate calculation, now 10 bits
// Correctly perform sign extension when computing potential_update
assign potential_update = $signed({membrane_potential[7], membrane_potential[7], membrane_potential}) +
$signed({input_current[7], input_current[7], input_current}) +
(membrane_potential[7] ? $signed({decay[7], decay[7], decay}) : -$signed({decay[7], decay[7], decay}));
always @(posedge clk or posedge reset) begin
// Initialize spike_out at the beginning of the block
spike_out <= 1'b0;
if (reset) begin
// Reset all states immediately when reset is high, regardless of clock
membrane_potential <= 8'b0;
refractory_counter <= 8'b0;
end else if (enable) begin // Only update if enabled
if (refractory_counter > 0) begin
// Decrement refractory counter if in refractory period
refractory_counter <= refractory_counter - 1;
end else begin
// Use the calculated potential_update to set the new membrane potential
if (potential_update[9] && potential_update < -128) // Negative overflow (checks if negative and exceeds 8-bit lower bound)
membrane_potential <= 8'b1000_0000; // Set to -128
else if (potential_update > 127) // Positive overflow (checks if exceeds 8-bit upper bound)
membrane_potential <= 8'b0111_1111; // Set to 127
else // No overflow or underflow
membrane_potential <= potential_update[7:0];
if ($signed(membrane_potential) >= $signed(threshold)) begin
// Neuron fires
spike_out <= 1'b1;
membrane_potential <= $signed(membrane_potential) - $signed(threshold); // Subtracting reset
refractory_counter <= refractory_period; // Enter refractory period
end
end
end
end // Correct closing 'end' for the always block
Assistant
Sure! Given the newenablesignal in the Leaky Integrate-and-Fire (LIF) neuron module, we need to modify the testbench to incorporate the control of this input. This signal will determine when the neuron is allowed to update its state.
Here's the revised version of the testbench incorporating theenableinput:
// Inputs
reg clk;
reg reset;
reg enable; // Enable signal for updating the neuron
reg [7:0] input_current;
reg [7:0] threshold;
reg [7:0] decay;
reg [7:0] refractory_period;
// Outputs
wire spike_out;
// Instantiate the Unit Under Test (UUT)
LeakyIntegrateFireNeuron uut (
.clk(clk),
.reset(reset),
.enable(enable),
.input_current(input_current),
.threshold(threshold),
.decay(decay),
.refractory_period(refractory_period),
.spike_out(spike_out)
);
// Clock generation
initial begin
clk = 0;
forever #10 clk = !clk; // Clock period of 20 ns
end
// Stimulus application
initial begin
// Initialize inputs
reset = 1;
enable = 0; // Initialize enable as low
input_current = 0;
threshold = 50;
decay = 5;
refractory_period = 10;
// Release reset and enable the neuron
#25;
reset = 0;
enable = 1;
// Test Case 1: No input current, neuron should not fire
#40;
// Test Case 2: Provide input current to trigger firing
input_current = 60;
#20;
// Test Case 3: Check refractory behavior with high input
input_current = 60;
#100;
// Disable the neuron and check that no updates occur
enable = 0;
input_current = 60;
#40;
// Re-enable and check response
enable = 1;
#20;
// Test various scenarios with enable toggling
input_current = 30;
#100;
enable = 0;
#40;
enable = 1;
input_current = 75; // High input to ensure firing when enabled
#60;
// Test neuron with reset asserted while enabled
reset = 1;
#30;
reset = 0;
#40;
// Continuous input with periodic enabling
input_current = 15;
#100;
enable = 0;
#40;
enable = 1;
#60;
// Finish test
#50 $finish;
end
// Optional: Monitoring changes
initial begin
$monitor("Time = %t, Input Current = %d, Membrane Potential = %d, <REDACTED> = %b", $time, input_current, uut.membrane_potential, spike_out);
end
User
can you a case with a low input current and a high threshold, giving the time the generate the spike?
Assistant
Certainly! To test a scenario with a low input current and a high threshold, you would want to see how long it takes for the neuron to accumulate enough potential to finally generate a spike. For this case, we can simulate a situation where the input current is consistently low, and set the threshold high enough to require several cycles for the neuron to reach it. This test will demonstrate the neuron's ability to integrate input over time and show how it handles slow buildup to a spike.
Let's add a specific test case to the testbench for this scenario:
// Inputs
reg clk;
reg reset;
reg enable;
reg [7:0] input_current;
reg [7:0] threshold;
reg [7:0] decay;
reg [7:0] refractory_period;
// Outputs
wire spike_out;
// Instantiate the Unit Under Test (UUT)
LeakyIntegrateFireNeuron uut (
.clk(clk),
.reset(reset),
.enable(enable),
.input_current(input_current),
.threshold(threshold),
.decay(decay),
.refractory_period(refractory_period),
.spike_out(spike_out)
);
// Clock generation
initial begin
clk = 0;
forever #10 clk = !clk; // Clock period of 20 ns
end
// Stimulus application
initial begin
// Initialize inputs
reset = 1; enable = 0;
input_current = 0; threshold = 200; // Set a high threshold
decay = 1; refractory_period = 10;
#25 reset = 0; enable = 1; // Release reset and enable
// Test Case: Low input current, high threshold
input_current = 5; // Low, consistent input
$display("Starting test with low input and high threshold at time %t", $time);
// Monitor when a spike occurs
fork
begin
// Wait for the spike to occur
wait (spike_out == 1);
$display("Spike occurred at time %t with low input current", $time);
$finish; // Optionally finish the simulation here or let it run longer
end
begin
// Let this run for a simulated maximum time if no spike occurs
#10000;
$display("No spike after 10000ns with low input current");
$finish;
end
join
end
// Optional: Monitoring changes
initial begin
$monitor("Time = %t, Input Current = %d, Membrane Potential = %d, <REDACTED> = %b", $time, input_current, uut.membrane_potential, spike_out);
end
User
remember that the signals are encoded as 2 complement 8 bit fixed point. Therefore, the maximum threshold can be 127.
Can you modify the threshold accordingly and includes also the previous cases?
Assistant
Absolutely, considering the signals are encoded as 8-bit two's complement fixed-point, the maximum possible threshold value is 127. I'll adjust the threshold in the test case and also ensure the previous test cases are included in the testbench.
Here's the updated version of the testbench with all cases included and the corrected threshold:
refractory_counter: Keeps track of the refractory period following a spike.
Calculations
potential_update: This wire calculates the new membrane potential by considering the current potential, the input current, and the decay. The calculation includes sign extension to manage overflow correctly.
potential_update: This wire calculates the new membrane potential by considering the current potential, the input current, and the decay. The calculation includes sign extension to manage overflow correctly.
Behavioral Logic
Initialization: At the start of each clock cycle, thespike_outis set to 0.
Reset Handling: If the reset signal is high, the membrane potential and refractory counter are reset to zero.
Refractory Period: If therefractory_counteris not zero, it decrements, indicating the neuron is still in the refractory period and cannot fire.
Membrane Potential Update:Handles overflow and underflow: Sets the potential to -128 or 127 if the updates exceed the bounds of an 8-bit signed number.Updates themembrane_potentialwith the new value calculated bypotential_update.
Handles overflow and underflow: Sets the potential to -128 or 127 if the updates exceed the bounds of an 8-bit signed number.
Updates themembrane_potentialwith the new value calculated bypotential_update.
Firing Check: If the updated membrane potential exceeds the threshold, the neuron fires (setsspike_outto 1), subtracts the threshold from the potential, and resets therefractory_counterto the specified refractory period.
Initialization: At the start of each clock cycle, thespike_outis set to 0.
Reset Handling: If the reset signal is high, the membrane potential and refractory counter are reset to zero.
Refractory Period: If therefractory_counteris not zero, it decrements, indicating the neuron is still in the refractory period and cannot fire.
Membrane Potential Update:
Handles overflow and underflow: Sets the potential to -128 or 127 if the updates exceed the bounds of an 8-bit signed number.
Updates themembrane_potentialwith the new value calculated bypotential_update.
Handles overflow and underflow: Sets the potential to -128 or 127 if the updates exceed the bounds of an 8-bit signed number.
Updates themembrane_potentialwith the new value calculated bypotential_update.
Firing Check: If the updated membrane potential exceeds the threshold, the neuron fires (setsspike_outto 1), subtracts the threshold from the potential, and resets therefractory_counterto the specified refractory period.
Key Points
The neuron can only update its membrane potential or fire when it's not in a refractory period.
The neuron correctly handles potential underflow and overflow, which is crucial for maintaining realistic simulation behavior.
The sign extensions and conditions for adjusting the potential based on the current potential sign (membrane_potential[7]) ensure that decay is applied correctly for both increasing and decreasing membrane potentials.
The neuron can only update its membrane potential or fire when it's not in a refractory period.
The neuron correctly handles potential underflow and overflow, which is crucial for maintaining realistic simulation behavior.
The sign extensions and conditions for adjusting the potential based on the current potential sign (membrane_potential[7]) ensure that decay is applied correctly for both increasing and decreasing membrane potentials.
Overall, this Verilog module effectively models a basic LIF neuron, demonstrating digital simulation of biological neuron behaviors in a system design context. If you have any specific questions or need further clarifications on any part of this module, feel free to ask!
endmodule
Key Elements of the :
Clock Generation: A simple clock generator that toggles the clock signal every 10 ns, giving a 20 ns clock period.
Stimulus Application: Sequences of different input currents are applied to observe how the neuron behaves under various conditions. This includes checking the neuron's response during the refractory period.
Reset: The reset is initially asserted to ensure that the neuron starts in a known state and then released after a short delay.
Monitoring: Uses$monitorto display useful simulation information in real-time, helping to debug and understand the neuron's behavior during the simulation.
Clock Generation: A simple clock generator that toggles the clock signal every 10 ns, giving a 20 ns clock period.
Stimulus Application: Sequences of different input currents are applied to observe how the neuron behaves under various conditions. This includes checking the neuron's response during the refractory period.
Reset: The reset is initially asserted to ensure that the neuron starts in a known state and then released after a short delay.
Monitoring: Uses$monitorto display useful simulation information in real-time, helping to debug and understand the neuron's behavior during the simulation.
This testbench will help you verify the basic functionality of the LIF neuron module, such as handling the refractory period, reacting to different levels of input currents, and managing the membrane potential based on given thresholds and decay values. Adjust the test cases and parameters as needed to fit more specific testing needs or to expand the coverage of different scenarios.
endmodule
Additional Test Cases Explained:
Test Case 5: Applies a moderate current to observe the neuron's potential build-up without crossing the firing threshold.
Test Case 6: Precisely reaches the threshold to test the spike triggering boundary.
Test Case 7: Tests the behavior with negative input current to ensure decay works correctly in reducing potential.
Test Case 8: Asserts and de-asserts the reset while
Test Case 5: Applies a moderate current to observe the neuron's potential build-up without crossing the firing threshold.
Test Case 6: Precisely reaches the threshold to test the spike triggering boundary.
Test Case 7: Tests the behavior with negative input current to ensure decay works correctly in reducing potential.
Test Case 8: Asserts and de-asserts the reset while
endmodule
endmodule
Changes in the :
Enable Control: Theenableinput is now controlled throughout the test to demonstrate the neuron's behavior when it's allowed to update its state and when it's not. This simulates scenarios where neuron updates might be gated by some external logic or conditions in a larger system.
Dynamic Enable Testing: Several cases have been added where theenablesignal is toggled between high and low states to confirm the neuron only updates its state when enabled.
Reset During Enabled State: Added a test where the reset is asserted while the neuron is enabled to ensure the reset functionality takes priority over theenablestate.
Enable Control: Theenableinput is now controlled throughout the test to demonstrate the neuron's behavior when it's allowed to update its state and when it's not. This simulates scenarios where neuron updates might be gated by some external logic or conditions in a larger system.
Dynamic Enable Testing: Several cases have been added where theenablesignal is toggled between high and low states to confirm the neuron only updates its state when enabled.
Reset During Enabled State: Added a test where the reset is asserted while the neuron is enabled to ensure the reset functionality takes priority over theenablestate.
This revised testbench should provide comprehensive verification of the neuron's functionality considering the addedenablesignal, covering both regular operations and edge cases influenced by enabling and disabling the module.
endmodule
Explanation of the Added Test Case:
Test Initialization: Sets the threshold very high at 200, which is not typical for an 8-bit signed value but illustrates the concept. Ensure the actual maximum does not exceed what the model can represent if it's indeed capped at 255 due to its 8-bit nature.
Low Input Current: An input current of5is used, which is quite low and will require many cycles to accumulate enough potential to exceed the threshold.
Monitoring and : This test uses afork...joinconstruct to monitor for a spike and includes a timeout to end the simulation if a spike doesn't occur within a set time (10000 ns in this case). The use of$displayprovides feedback on the simulation's progress and outcomes.
Test Initialization: Sets the threshold very high at 200, which is not typical for an 8-bit signed value but illustrates the concept. Ensure the actual maximum does not exceed what the model can represent if it's indeed capped at 255 due to its 8-bit nature.
Low Input Current: An input current of5is used, which is quite low and will require many cycles to accumulate enough potential to exceed the threshold.
Monitoring and : This test uses afork...joinconstruct to monitor for a spike and includes a timeout to end the simulation if a spike doesn't occur within a set time (10000 ns in this case). The use of$displayprovides feedback on the simulation's progress and outcomes.
This setup will help you analyze how effectively the neuron integrates small inputs over time and can be adjusted for different rates of input and threshold values to test other conditions or neuron configurations.
// Inputs
reg clk;
reg reset;
reg enable;
reg [7:0] input_current;
reg [7:0] threshold;
reg [7:0] decay;
reg [7:0] refractory_period;
// Outputs
wire spike_out;
// Instantiate the Unit Under Test (UUT)
LeakyIntegrateFireNeuron uut (
.clk(clk),
.reset(reset),
.enable(enable),
.input_current(input_current),
.threshold(threshold),
.decay(decay),
.refractory_period(refractory_period),
.spike_out(spike_out)
);
// Clock generation
initial begin
clk = 0;
forever #10 clk = !clk; // Clock period of 20 ns
end
// Stimulus application
initial begin
// Initialize inputs
reset = 1; enable = 0;
input_current = 0; threshold = 127; // Set threshold to <REDACTED> for 8-bit signed
decay = 1; refractory_period = 10;
#25 reset = 0; enable = 1; // Release reset and enable
// Test Case 1: Small input current, no spike expected
input_current = 10;
#40;
// Test Case 2: Sufficient current to trigger a spike
input_current = 60;
#20;
// Test Case 3: Check refractory behavior with high input
input_current = 60;
#100;
// Disable the neuron and check that no updates occur
enable = 0;
input_current = 60;
#40;
// Re-enable and check response
enable = 1;
#20;
// Test various scenarios with enable toggling
input_current = 30;
#100;
enable = 0;
#40;
enable = 1;
input_current = 75; // High input to ensure firing when enabled
#60;
// Test neuron with reset asserted while enabled
reset = 1;
#30;
reset = 0;
#40;
// Continuous input with periodic enabling
input_current = 15;
#100;
enable = 0;
#40;
enable = 1;
#60;
// Test Case: Low input current, high threshold
input_current = 5; // Low, consistent input
$display("Starting test with low input and high threshold at time %t", $time);
// Monitor when a spike occurs
fork
begin
// Wait for the spike to occur
wait (spike_out == 1);
$display("Spike occurred at time %t with low input current", $time);
$finish; // Optionally finish the simulation here or let it run longer
end
begin
// Let this run for a simulated maximum time if no spike occurs
#10000;
$display("No spike after 10000ns with low input current");
$finish;
end
join
end
// Optional: Monitoring changes
initial begin
$monitor("Time = %t, Input Current = %d, Membrane Potential = %d, <REDACTED> = %b", $time, input_current, uut.membrane_potential, spike_out);
end
endmodule
Key Modifications:
Threshold Value: Adjusted the threshold value to 127, reflecting the maximum value in an 8-bit signed fixed-point format.
Comprehensive Test Coverage: This testbench includes multiple test cases for different input currents and enabling conditions. It tests the neuron's response to both regular and edge-case inputs and also includes checks for the functionality under disabled conditions.
Special Case for Accumulation: Added a case for slow accumulation of potential to reach the high threshold with low input current. This particular case demonstrates how the neuron integrates input over time until it reaches the firing threshold.
Threshold Value: Adjusted the threshold value to 127, reflecting the maximum value in an 8-bit signed fixed-point format.
Comprehensive Test Coverage: This testbench includes multiple test cases for different input currents and enabling conditions. It tests the neuron's response to both regular and edge-case inputs and also includes checks for the functionality under disabled conditions.
Special Case for Accumulation: Added a case for slow accumulation of potential to reach the high threshold with low input current. This particular case demonstrates how the neuron integrates input over time until it reaches the firing threshold.
This modified testbench ensures that the Leaky Integrate-and-Fire neuron is comprehensively tested under various conditions, including extreme and typical scenarios. This will help confirm the robustness and correctness of the neuron model in a simulated environment.