문제상황:
다음과 같은 Verilog 코드를 작성하고 컴파일을 실행했을 때, multiple drivers 에러가 발생했습니다. 이 모듈의 목적은 입력신호인 data_in을 받아서 data_out으로 출력하는 동작을 수행하는 것입니다.
module top_module (
input wire clk,
input wire rst,
input wire data_in,
output wire data_out
);
reg [7:0] data;
always @(posedge clk or posedge rst) begin
if (rst) begin
data <= 8'b0;
end else begin
data <= data_in;
end
end
assign data_out = data;
endmodule
에러로그 내용:
Error: multiple drivers for net "data_out"
해결방법:
에러가 수정된 코드와 수정된 부분에 대한 주석:
module top_module (
input wire clk,
input wire rst,
input wire data_in,
output reg data_out
);
reg [7:0] data;
always @(posedge clk or posedge rst) begin
if (rst) begin
data <= 8'b0;
end else begin
data <= data_in;
end
end
always @(posedge clk or posedge rst) begin
if (rst) begin
data_out <= 1'b0;
end else begin
data_out <= data;
end
end
endmodule
에러 발생 원인은 `data_out` 신호에 대해 다중 구동자(multiple drivers)가 존재하기 때문입니다. 기존 코드에서는 `data` 레지스터 값을 `assign` 문을 통해 `data_out`에 할당하고 있습니다. 그러나 `data_out`은 출력 포트로 선언되어 있기 때문에, 이러한 방식으로 값이 할당되면 내부 회로에서 충돌이 발생할 수 있습니다.
이 문제를 해결하기 위해 `data_out`을 `output reg`으로 변경하고, `assign` 문을 제거한 뒤, `always` 블록 내에서 `data_out`에 `data` 값을 할당하는 방식으로 코드를 수정했습니다. 이렇게 하면 `data_out`에 대한 구동자 충돌이 해결되어 에러가 발생하지 않습니다
참고링크:
https://stackoverflow.com/questions/13569351/connecting-verilog-arrays-multiple-drivers
[Connecting Verilog Arrays: Multiple Drivers
I am storing a sequence of values in a memory array. When it comes time to output this sequence to an LED display, I am running into an error with multiple drivers. Here are code snippets that I'm
stackoverflow.com](https://stackoverflow.com/questions/13569351/connecting-verilog-arrays-multiple-drivers)