touch가 될때마다 시리얼 통신으로 254를 전송하고 싶어. 그러나 지금은 처음 눌렀을때 3개의 254가 전송되고 그 뒤부터는 touch를 해도 전송되지…
- User
touch가 될때마다 시리얼 통신으로 254를 전송하고 싶어. 그러나 지금은 처음 눌렀을때 3개의 254가 전송되고 그 뒤부터는 touch를 해도 전송되지 않아. module motor_top( input clk, input i_Rx_Serial, input m_verification, input touch, output GPIO_1, output GPIO_2, output reg [6:0] led_direct, output reg [6:0] led_duty, output reg [6:0] led_time_10, output reg [6:0] led_time_1, output o_Tx_Serial ); reg un_touch; always @(posedge clk) un_touch <= ~touch;
reg [9:0] w_data; uart_rx #(.CLKS_PER_BIT(434)) rx ( .i_Clock(clk), .i_Rx_Serial(i_Rx_Serial), .o_Rx_DV(i_run), .o_Rx_Byte(w_data) );
wire [7:0] dumy_data = 254; pass_fsm core(
.clk(clk), .ii_run(i_run),
.o_tx_DV(data_valid) );reg ok; always @(*) begin if(un_touch==1 && data_valid==1) begin ok<=1; end else begin ok<=0; end end
uart_tx #(.CLKS_PER_BIT(434)) tx ( .i_Clock(clk), .i_Tx_DV(ok), .i_Tx_Byte(dumy_data), // s_TX_DATA_BITS 일때 출력으로 나갈거 .o_Tx_Serial(o_Tx_Serial) );
reg [3:0] direction; reg [3:0] dutynumber; reg [3:0] timenumber; reg [3:0] timenumber_10; reg [3:0] timenumber_1;
always @(posedge clk) begin
if(i_run==1 && w_data<8) dutynumber <= w_data; else if(i_run==1 && w_data==8) direction <= 0; else if(i_run==1 && w_data==9) direction <= 1; else if(i_run==1 && w_data==10) timenumber <=0;
else if(i_run==1 && w_data==11) timenumber <=5; else if(i_run==1 && w_data==12) timenumber <=10; else if(i_run==1 && w_data==13) timenumber <=15;end
reg [5:0]time_s; always @(clk) begin timenumber_10 <= time_s/10; timenumber_1 <= time_s%10; end
led_dec for_accel( .led1_in(direction), .led1_out(led_direct) ); led_dec for_direc( .led1_in(dutynumber), .led1_out(led_duty) );
led_dec for_time10( .led1_in(timenumber_10), .led1_out(led_time_10) );
led_dec for_time1( .led1_in(timenumber_1), .led1_out(led_time_1) );
accelerator ins_accelerator( .clk(clk), .verification(m_verification), .direction_change(direction), .touch_sensor(un_touch), .duty_number(dutynumber), .time_number(timenumber), .outvalue1(GPIO_1), .outvalue2(GPIO_2), .s(time_s) );
endmodule
module uart_tx #(parameter CLKS_PER_BIT = 0) ( input i_Clock, input i_Tx_DV, input [7:0] i_Tx_Byte, /////처리된 입력 //output o_Tx_Active, output reg o_Tx_Serial //output o_Tx_Done );
localparam s_IDLE = 3'b000; localparam s_TX_START_BIT = 3'b001; localparam s_TX_DATA_BITS = 3'b010; localparam s_TX_STOP_BIT = 3'b011; localparam s_CLEANUP = 3'b100;
reg [2:0] r_SM_Main = 0; reg [15:0] r_Clock_Count = 0; reg [2:0] r_Bit_Index = 0; reg [7:0] r_Tx_Data = 0; // reg r_Tx_Done = 0; //reg r_Tx_Active = 0;
always @(posedge i_Clock) begin
code - Assistant
- User
한국어로 다시 설명해줘
- Assistant
여러분의 Verilog 코드에서 'touch' 이벤트가 발생했을 때 UART를 통해 숫자 254를 전송하는 데 있어 몇 가지 개념적이고 논리적인 문제점이 보입니다. 'touch' 입력 신호의 상승 에지를 감지하고, 이를 기반으로 UART 전송을 시작하는 기능이 필요합니다. 또한 'touch' 신호가 노이즈를 포함하는 경우, 실제 터치와 상관 없이 여러 번의 전송을 초래할 수 있으므로 디바운싱(Debouncing) 메커니즘도 중요합니다.
제안된 코드 변경에는 다음과 같은 부분들이 포함됩니다:
1. 에지 감지 및 디바운싱 모듈
아래는 터치 신호의 상승 에지를 감지하고 간단한 디바운싱을 수행하는 Verilog 모듈의 예입니다. 디바운싱은 입력 신호의 짧은 변동을 무시하여 안정적인 상태 변화만을 캡쳐하도록 돕습니다.
verilog