Tarjeta de Desarrollo Spartan-3ramos.elo.utfsm.cl/~elo212/docs/elo212-clase5-0110.pdfPermite...
Transcript of Tarjeta de Desarrollo Spartan-3ramos.elo.utfsm.cl/~elo212/docs/elo212-clase5-0110.pdfPermite...
LAB 5Tarjeta de Desarrollo Spartan-3
Laboratorio de Sistemas DigitalesELO212Primer Semestre de 2010
Objetivos Generales
Controlar dispositivos mediante una FPGA.Conocer la interfaz PS/2 para conexión de un teclado.Aprender el menejo de:
pulsadores, interruptores, leds, display de 7 segmentos.
Interfaz PS/2
Permite conectar periféricos teclado y mouse.Protocolo de comunicación serial bidireccional.Para teclados se garantiza el conjunto 2 de los scan codes.Responden a todos los comandos enviados, sin embargo no actúan en todos ellos.
Socket y Pinout
Pin 1: DataPin 2: ReservadoPin 3: GroundPin 4: Vcc (+5V)Pin 5: ClockPin 6: Reservado
Comunicación Bidireccional
Estado IDLE: Data y Clock en alto
Estado INHIBIT:Data en alto y Clock en bajo
Estado REQUEST TO SEND: Data en bajo y Clock en alto
PS/2 Frame (1)
1 bit de partida: siempre es 0.8 bits de datos: LSB a MSB.1 bit de paridad (impar)1 bit de parada: siempre es 1.1 bit de ack: sólo para comunicación host →teclado/mouse.
PS/2 Frame (2)
Scan Code (1)
Hay varios tipos de scan codes, el más popular (por omisión) es el número 2.Cada tecla tiene asociado un scan codecompuesto por:
make code, que se emite al presionar una teclabreake code, que se emite al soltar la tecla
Scan Code (2): Ejemplos
49F0,4343I48F0,3333H47F0,3434G46F0,2B2BF45F0,2424E44F0,2323D43F0,2121C42F0,3232B41F0,1C1CAASCIIBreakMakeKey
PS/2 Driver Verilog (1)
10 0
ShiftRegSig1
10 1
ShiftRegSig2
kd
kc
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 x x x x x x x x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 x x x x x x x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 0 x x x x x x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 0 0 x x x x x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 0 0 0 x x x x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 0 0 0 0 0 x x x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 1 0 0 0 0 0 x x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 1 1 0 0 0 0 0 x x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 1 1 1 0 0 0 0 0 x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc x x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 1 1 1 1 0 0 0 0 x10 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc 0 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 1 1 1 1 1 0 0 0 010 0
ShiftRegSig1
x x x x x x x x x10 1
ShiftRegSig2
kd
kc 0 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 1 1 1 1 1 1 0 0 010 0
ShiftRegSig1
0 x x x x x x x x10 1
ShiftRegSig2
kd
kc 0 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 1 1 1 1 1 1 0 010 0
ShiftRegSig1
0 0 x x x x x x x10 1
ShiftRegSig2
kd
kc 0 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 0 1 1 1 1 1 1 010 0
ShiftRegSig1
0 0 0 x x x x x x10 1
ShiftRegSig2
kd
kc 0 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 0 0 0 1 1 1 1 1 010 0
ShiftRegSig1
0 0 0 0 x x x x x10 1
ShiftRegSig2
kd
kc 1 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 1 0 0 0 1 1 1 1 110 0
ShiftRegSig1
0 0 0 0 0 x x x x10 1
ShiftRegSig2
kd
kc 1 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 1 1 0 0 0 1 1 1 110 0
ShiftRegSig1
1 0 0 0 0 0 x x x10 1
ShiftRegSig2
kd
kc 1 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 1 1 1 0 0 0 1 1 110 0
ShiftRegSig1
1 1 0 0 0 0 0 x x10 1
ShiftRegSig2
kd
kc 1 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 1 1 1 0 0 0 1 110 0
ShiftRegSig1
1 1 1 0 0 0 0 0 x10 1
ShiftRegSig2
kd
kc 1 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 0 1 1 1 0 0 0 110 0
ShiftRegSig1
1 1 1 1 0 0 0 0 010 1
ShiftRegSig2
kd
kc 1 x
kbs
0 xxxxxxxxvalue
PS/2 Driver Verilog (1)
0 0 0 0 1 1 1 0 0 110 0
ShiftRegSig1
1 1 1 1 1 0 0 0 010 1
ShiftRegSig2
kd
kc 0 0
kbs
1 xxxxxxxxvalue
PS/2 Driver Verilog (1)
1 0 0 0 0 1 1 1 0 010 0
ShiftRegSig1
1 1 1 1 1 1 0 0 010 1
ShiftRegSig2
kd
kc 0 0
kbs
0 1Cvalue
PS/2 Driver Verilog (2a)
module kbd(rst, clk, kd, kc, kbs, value);input rst, clk, kd, kc; // reset, clock, k-data, k-clockoutput reg kbs; // keyboard stroke (negedge)output reg [7:0] value; // scan code
// ------------------------------------------------------------------// -- Signal Declarations// ------------------------------------------------------------------
reg kdi, kci;reg dff1, dff2;reg [10:0] ShiftRegSig1; reg [10:1] ShiftRegSig2;reg kbs_tmp;
PS/2 Driver Verilog (2b)
// ------------------------------------------------------------------// -- Module Implementation// ------------------------------------------------------------------
// --Flip Flops used to condition signals coming from PS2--always @ (posedge clk or posedge rst)begin
if (rst == 1) begindff1 <= 0; dff2 <= 0; kdi <= 0; kci <= 0;
end else begindff1 <= kd; kdi <= dff1; dff2 <= kc; kci <= dff2;
endend
PS/2 Driver Verilog (2c)
// --Shift Registers used to clock in scan codes from PS2--always @(negedge kci or posedge rst)begin
if (rst == 1) beginShiftRegSig1 <= 11'b00000000000;ShiftRegSig2 <= 10'b0000000000;
end else beginShiftRegSig1[10:0] <= {kdi, ShiftRegSig1[10:1]};ShiftRegSig2[10:1] <= {ShiftRegSig1[0], ShiftRegSig2[10:2]};
endend
PS/2 Driver Verilog (2d)
// --Wait for scan codealways @(posedge rst or posedge kci)begin
if (rst == 1) beginvalue <= 8'b00000000; kbs_tmp <= 0;
end else if (ShiftRegSig2[9:2] == 8'b11110000) beginvalue <= value; kbs_tmp <= 1;
end else if (ShiftRegSig2[8:1] == 8'b11110000) beginvalue <= ShiftRegSig1[8:1]; kbs_tmp <= 0;
endend
always @(negedge clk) kbs <= kbs_tmp;
endmodule
Ejemplo Uso Driver PS/2
module kbdUse(rst, clk, kd, kc, led);input rst, clk, kd, kc;output reg [7:0] led;
wire [7:0] value; kbd kbd0(rst, clk, kd, kc, kbs, value);
always @ (negedge rst or negedge kbs) if (rst == 0) led <= 0; else led <= led + 1;
endmodule
Display 7 segmentos
4 dígitos (7 segmentos).No dispone de conversores BCD / 7 segmentos.Ánodo común.12 salidas para controlar el display.Se debe multiplexar en el tiempo para poder ver números de más de 1 dígito.
Configuración del Display
Conexiones
Driver Verilog BCD/7Seg.
module ssdec(val, pt, type, ssg); input [3:0] val; // binary valueinput pt, type; // point, display type (0: anode, 1: cathode)output [7:0] ssg; // segments
assign ssg = ((type == 1) ? 8'h0 : 8'hff) ^ ((val == 0) ? {pt, 7'b0111111} :(val == 1) ? {pt, 7'b0000110} :(val == 2) ? {pt, 7'b1011011} :(val == 3) ? {pt, 7'b1001111} :// ……(val == 11) ? {pt, 7'b1111100} :(val == 12) ? {pt, 7'b1011000} :(val == 13) ? {pt, 7'b1011110} :(val == 14) ? {pt, 7'b1111001} : {pt, 7'b1110001});
endmodule
Driver Verilog Display 7Seg. (1)
module display(clk, num, type, pts, sseg, an);input clk, type; input [3:0] pts; input [15:0] num;output [7:0] sseg; output reg [3:0] an;
// fill in ….
endmodule
Contador BCD
module bcdcounter(rst, clk, value);input rst, clk; // reset, clockoutput reg [15:0] value; // 4 bcd digits
always @(negedge clk or posedge rst) beginif (rst == 1)
value <= 0; else begin
if (value[3:0] == 9) beginvalue[3:0] <= 0; if (value[7:4] == 9) begin
value[7:4] <= 0; if (value[11:8] == 9) begin
value[11:8] <= 0; if (value[15:12] == 9) value[15:12] <= 0; else value[15:12] <= value[15:12] + 1;
end else value[11:8] <= value[11:8] + 1; end else value[7:4] <= value[7:4] + 1;
end else value <= value + 1; end
endendmodule
Uso de Pulsadores, Interruptores y ledsmodule (btn, swt, led);input [0:3] btn; input [0:7] swt; output [0:7] led;
assign led[0:3] = btn; assign led[4:7] = swt[0:3];
endmodule
Trabajo Previo (1)
Diseño de un módulo para visualizar una cuenta en el display
Completar diseño del módulo display.Usar display para mostrar tiempo MM.SS.Hacer simulación funcional y temporal.
Módulo para uso de leds, interruptores y pulsadores.
Leds reflejan el estado del interruptor.Pulsador 0: enciende todos los leds.Pulsador 1: apaga todos los leds.Pulsador 2: invierte estado de los leds. Hacer simulación funcional.
Trabajo Previo (2)
Diseño de un módulo que permita:Visualizar scan codes de teclado en display 7 segmentos, dígitos menos significativos.Visualizar el valor de teclas numéricas en los dígitos más significativos, o “FF” si no es número.
En el Laboratorio
Revisión actividades previas.Sintetizar y demostrar el funcionamiento del módulo reloj en formato MM.SS.Sintetizar el módulo para uso de pulsadores, interruptores y leds.Demostrar el funcionamiento del módulo que despliega scan codes del teclado PS/2.Diseño de una máquina digital.
Máquina Digital (1)
Cuenta el número de teclas presionadas.4
Contador descendente binario de Y Hz.3
Contador ascendente binario de X Hz.2
Contador BCD descendente Y Hz.1
Contador BCD ascendente X Hz.0
Contenido del display y ledsOp.
Máquina Digital (2)
Comportamiento dinámico para leds y puntos.9
Leds pestañean X Hz, se mantienen las cuentas.8
Display off, se mantienen las cuentas.7
2MSD ⇒ op. 0, 2LSD ⇒ op. 1.6
Número de repeticiones de una tecla.5
Contenido del display y ledsOp.
Máquina Digital (2)
Tiempo transcurrido en MM.SS.12
Tiempo [ms] entre 2 eventos PS/2, máx 9999.11
2LSD ⇒ último pulsador (0 - 3); mantiene cuentas.10
Contenido del display y ledsOp.
Máquina Digital (3)
Blinking leds at Y Hz. 3
Display rotate left (eg. 1): 1234 ⇒ 23412
Display rotate right (eg. 1): 1234 ⇒ 41231
Resetea todas las cuentas.0
Descripción operaciónPulsador