`timescale 1ns / 1ps module enco(clk, enable,quadA, quadB, out,buffer_addr); input clk, quadA, quadB; input enable; input [10:0]buffer_addr; output [7:0] out; wire [7:0] vel_dir; //Registros para implementar retardos, con la idea de syncronizar las seales reg [2:0] quadA_delayed, quadB_delayed=0; always @(posedge clk) quadA_delayed <= {quadA_delayed[1:0], quadA}; always @(posedge clk) quadB_delayed <= {quadB_delayed[1:0], quadB}; //Valores internos para habilitar el conteo, y determinar la direccin del mismo wire count_enable = quadA_delayed[1] ^ quadA_delayed[2] ^ quadB_delayed[1] ^ quadB_delayed[2]; wire count_direction = quadA_delayed[1] ^ quadB_delayed[2]; //Registro para almacenar el contador reg [7:0] count=0; //Pendiente cambiar este, no sabemos que dato saldr al final always @(posedge clk) begin if(count_enable) begin if(count_direction) count<=count+1; else count<=count-1; end end //Falta definir como vamos a comunicar esta info, es ms facil como posicin /*reg [1:0] pos_reg0=0; //Registro temporal 1 reg [1:0] pos_reg1=0; //Registro temporal reg dir=0; //Direccin, 1=adelante? 0=atras? always @(posedge clk) begin pos_reg0<={quadB, quadA}; pos_reg1<=pos_reg0; if(pos_reg1==pos_reg0) dir<=dir; else if(pos_reg0==1) begin if(pos_reg1