- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi there,
I'm trying to increment a row of leds by one but pressing a pushbutton that is normally high until it is pressed. I have this code, but for some reason, the led's just light randomly. I'm using a DE2-70 board, 18 LEDs, 1 pushbutton to reset, and 1 to increment. module button_led(iKEY, oLEDR, iCLK_28); output [17:0]oLEDR; input [0:3]iKEY; input iCLK_28; reg [17:0]j; assign oLEDR = j; always @(posedge iCLK_28) begin if(!iKEY[0]) j <= 0; else if (!iKEY[1]) j <= j + 1; end endmodule Thanks!!Link copiado
4 Respostas
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Your code is exactly doing what you have written: increment the counter while the key is pressed. You apparently intended to increment it by one for each falling edge of the key signal.
The key inputs are said to have debouncing circuits in the DE2-70 manual. If this is correct, the below code (synchronous edge detection) should work.reg k1;
reg k2;
always @(posedge iCLK_28)
begin
k1 <= KEY;
k2 <= k1;
if(!iKEY)
j <= 0;
else if (!k1 && k2)
j <= j + 1;
end
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Thanks for the reply!
I'll try your code tomorrow when i get the chance. I realize that i was incrementing awkwardly like that, but i also tried: always @ (negedge iKEY[1]) j <= j+1; but that didn't give any sort of response..- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
hmm, the code still doesn't light any LEDs. any ideas?
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I'm sorry, i forgot to import the assignments -_-. it works perfectly thanks!

Responder
Opções do tópico
- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora