-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Readme.md * Add files via upload * Update Readme.md * Create de10_lite.vhd * Add files via upload * Delete peripherals/encoder/sintese.zip
- Loading branch information
Showing
8 changed files
with
866 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Encoder Frequency Measurement | ||
|
||
Este projeto VHDL implementa uma contagem de pulsos de um encoder e calcula a frequência desses pulsos com base em um período de tempo configurável. O código permite selecionar diferentes períodos de medição e calcula a frequência em Hz (pulsos por segundo). | ||
|
||
## Exemplo prático | ||
|
||
Abaixo temos o exemplo de um sinal de 53 kHZ sendo injetado na placa, para que seja feita a medição de sua frequencia através do periférico implementado. | ||
|
||
 | ||
 | ||
|
||
O valor medido é apresentado no display em formato hexadecimal, ou seja, CF08, que convertido a decimal, nos dá exatamente 53k, igual a frequencia do sinal injetado. | ||
|
||
## Entidade `encoder` | ||
|
||
A entidade `encoder` recebe os seguintes sinais de entrada e saída: | ||
|
||
### Entradas: | ||
- `clk`: Sinal de clock do sistema (50 MHz assumido). | ||
- `aclr_n`: Sinal de reset ativo em baixo. | ||
- `select_time`: Vetor de 3 bits para seleção do período de medição. | ||
- "000" -> 1 ms | ||
- "001" -> 10 ms | ||
- "010" -> 100 ms | ||
- "011" -> 1000 ms | ||
- `encoder_pulse`: Sinal de pulso do encoder. | ||
|
||
### Saídas: | ||
- `frequency`: Frequência dos pulsos do encoder em Hz, é possivel medir frequencias de até 4 Mhz com esta aplicação, devido a limitação do tamanho do registrador utilizado em pulse counter. | ||
|
||
## Arquitetura `rtl` | ||
|
||
A arquitetura `rtl` define o seguinte comportamento: | ||
|
||
1. **Seleção do Período de Medição:** | ||
- O `select_time` define o tempo de medição. O tempo é armazenado no sinal `time_period` e um multiplicador é ajustado para converter a contagem de pulsos em frequência (Hz). | ||
- Períodos disponíveis: 1 ms, 10 ms, 100 ms, e 1000 ms. | ||
|
||
2. **Contagem de Pulsos:** | ||
- Um contador (`time_counter`) é incrementado a cada ciclo de clock até atingir o valor do `time_period`. | ||
- Quando o contador de tempo atinge o período definido, a frequência é calculada multiplicando a contagem de pulsos (`pulse_count`) pelo multiplicador apropriado para gerar a frequência em Hz. | ||
|
||
3. **Reinicialização e Contagem:** | ||
- A cada intervalo de tempo definido, o contador de pulsos é resetado, e um novo cálculo de frequência é feito. | ||
- O sinal de controle `flag` garante que o contador de pulsos seja resetado corretamente no final de cada período de medição. | ||
|
||
## Como Utilizar | ||
|
||
- Atribua um valor de entrada ao vetor `select_time` para definir o período de medição desejado. | ||
- Aplique o sinal do encoder no `encoder_pulse`. | ||
- A frequência calculada será disponibilizada na saída `frequency` em pulsos por segundo. | ||
|
||
## Sinais Importantes | ||
|
||
- `pulse_count`: Contador de pulsos do encoder. | ||
- `time_period`: Período de contagem selecionado. | ||
- `time_counter`: Contador de tempo baseado no clock. | ||
- `multiplicador`: Fator para converter a contagem de pulsos na frequência adequada. | ||
|
||
Este código é útil para sistemas que necessitam medir a frequência de pulsos de um encoder, como em aplicações de controle de motores ou medição de velocidade de rotação. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
entity encoder is | ||
port ( | ||
clk : in std_logic; | ||
aclr_n : in std_logic; | ||
select_time : in std_logic_vector(2 downto 0); | ||
encoder_pulse : in std_logic; | ||
frequency : out unsigned(31 downto 0) | ||
); | ||
end entity encoder; | ||
|
||
architecture rtl of encoder is | ||
signal pulse_count : unsigned(21 downto 0) := (others => '0'); | ||
signal time_period : unsigned(31 downto 0); | ||
signal multiplicador: unsigned(9 downto 0):= (others => '0'); | ||
signal time_counter : unsigned(31 downto 0) := (others => '0'); | ||
signal flag : std_logic := '0'; -- Sinal para reiniciar pulse_count | ||
|
||
begin | ||
|
||
|
||
process(select_time) | ||
begin | ||
case select_time is | ||
when "000" => time_period <= to_unsigned(50000, 32);-- 1ms (assumindo clock de 50 MHz) | ||
multiplicador <= to_unsigned(1000, 10); | ||
when "001" => time_period <= to_unsigned(500000, 32); -- 10ms | ||
multiplicador <= to_unsigned(100, 10); | ||
when "010" => time_period <= to_unsigned(5000000, 32); -- 100ms | ||
multiplicador <= to_unsigned(10, 10); | ||
when "011" => time_period <= to_unsigned(50000000, 32); -- 1000ms | ||
multiplicador <= to_unsigned(1, 10); | ||
when others => time_period <= to_unsigned(50000, 32); -- Default para 1ms | ||
multiplicador <= to_unsigned(1000, 10); | ||
end case; | ||
end process; | ||
|
||
-- Contagem dos pulsos do clock | ||
process(aclr_n, clk) | ||
begin | ||
if aclr_n = '0' then | ||
time_counter <= (others => '0'); | ||
frequency <= (others => '0'); | ||
elsif flag = '1' then | ||
flag <= '0'; | ||
elsif rising_edge(clk) then | ||
if time_counter < time_period then | ||
time_counter <= time_counter + 1; | ||
else | ||
time_counter <= (others => '0'); | ||
frequency <= pulse_count*multiplicador; -- Frequência em pulsos por período (Hz) | ||
flag <= '1'; -- Garante que o flag seja resetado no início | ||
end if; | ||
end if; | ||
end process; | ||
|
||
-- Contagem dos pulsos do encoder | ||
process(aclr_n, encoder_pulse,flag) | ||
variable q_var : unsigned(21 downto 0) := (others => '0'); | ||
begin | ||
if aclr_n = '0' then | ||
q_var := (others => '0'); | ||
elsif flag = '1' then | ||
q_var := (others => '0'); | ||
elsif rising_edge(encoder_pulse) then | ||
q_var := q_var + 1; | ||
end if; | ||
pulse_count <= q_var; | ||
end process; | ||
|
||
end architecture rtl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
------------------------------------------------------------------- | ||
-- name : seven_segment_cntrl.vhd | ||
-- author : Stanislau de Lira Kaszubowski | ||
-- data : 02/04/2024 | ||
-- copyright : Instituto Federal de Santa Catarina | ||
-- description : Traduz uma entrada de 4 bits para o acionamento de um display de 7 segmentos. | ||
------------------------------------------------------------------- | ||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
entity seven_segment_cntrl is | ||
port ( | ||
input: in unsigned (4-1 downto 0); | ||
segs : out std_logic_vector (7 downto 0) | ||
); | ||
end entity seven_segment_cntrl; | ||
|
||
architecture rtl of seven_segment_cntrl is | ||
begin | ||
|
||
process (input) | ||
begin | ||
case input is | ||
when "0000" => | ||
segs <= "11000000"; --0 | ||
when "0001" => | ||
segs <= "11111001"; --1 | ||
when "0010" => | ||
segs <= "10100100"; --2 | ||
when "0011" => | ||
segs <= "10110000"; --3 | ||
when "0100" => | ||
segs <= "10011001"; --4 | ||
when "0101" => | ||
segs <= "10010010"; --5 | ||
when "0110" => | ||
segs <= "10000010"; --6 | ||
when "0111" => | ||
segs <= "11111000"; --7 | ||
when "1000" => | ||
segs <= "10000000"; --8 | ||
when "1001" => | ||
segs <= "10010000"; --9 | ||
when "1010" => | ||
segs <= "10001000"; -- A | ||
when "1011" => | ||
segs <= "10000011"; -- b | ||
when "1100" => | ||
segs <= "11000110"; -- C | ||
when "1101" => | ||
segs <= "10100001"; -- d | ||
when "1110" => | ||
segs <= "10000110"; -- E | ||
when "1111" => | ||
segs <= "10001110"; -- F | ||
when others => | ||
segs <= "00000000"; -- Default (off) | ||
end case; | ||
end process; | ||
|
||
end architecture rtl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -------------------------------------------------------------------------- # | ||
# | ||
# Copyright (C) 2018 Intel Corporation. All rights reserved. | ||
# Your use of Intel Corporation's design tools, logic functions | ||
# and other software and tools, and its AMPP partner logic | ||
# functions, and any output files from any of the foregoing | ||
# (including device programming or simulation files), and any | ||
# associated documentation or information are expressly subject | ||
# to the terms and conditions of the Intel Program License | ||
# Subscription Agreement, the Intel Quartus Prime License Agreement, | ||
# the Intel FPGA IP License Agreement, or other applicable license | ||
# agreement, including, without limitation, that your use is for | ||
# the sole purpose of programming logic devices manufactured by | ||
# Intel and sold by Intel or its authorized distributors. Please | ||
# refer to the applicable agreement for further details. | ||
# | ||
# -------------------------------------------------------------------------- # | ||
# | ||
# Quartus Prime | ||
# Version 18.1.0 Build 625 09/12/2018 SJ Standard Edition | ||
# Date created = 09:41:06 April 06, 2020 | ||
# | ||
# -------------------------------------------------------------------------- # | ||
|
||
QUARTUS_VERSION = "18.1" | ||
DATE = "09:41:06 April 06, 2020" | ||
|
||
# Revisions | ||
|
||
PROJECT_REVISION = "de10_lite" |
Oops, something went wrong.