Skip to content

Commit

Permalink
morse (#64)
Browse files Browse the repository at this point in the history
* Create a

* Add files via upload

Upload inicial morse code

* Create a

* Add files via upload

Upload dos arquivos da pasta sint

* Delete peripherals/morse/a

* Delete peripherals/morse/sint/a

* Create a

* Add files via upload

Upload das imagens para o README

* Delete peripherals/morse/imagens/a

* Update README.md

ajuste de links

* Update README.md

ajuste de links_2

* Update MorseCodeBuzzer.vhd

ajuste de comentário
  • Loading branch information
suzuki1994 authored Dec 19, 2023
1 parent d392692 commit 938a559
Show file tree
Hide file tree
Showing 17 changed files with 2,129 additions and 0 deletions.
170 changes: 170 additions & 0 deletions peripherals/morse/MorseCodeBuzzer.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
--! Use standard library
library ieee;

use ieee.std_logic_1164.all;

use ieee.numeric_std.all;
use work.MorseCode_Package.all;


entity MorseCodeBuzzer is
Port (
clk : in std_logic; -- Clock input
rst : in std_logic; -- Reset input
entrada: in integer; --entrada do numero/letra/caracter especial
buzzer : out std_logic; -- Buzzer output
ledt : out std_logic;-- led acionado com o tempo T (ponto)
ledf : out std_logic;-- led acionado com o fim da palavra
led3t: out std_logic-- led acionado com o tempo 3T (traço)
);

end MorseCodeBuzzer;

architecture Behavioral of MorseCodeBuzzer is
constant T: integer :=225;--225 para a placa; para os testbench 10 muda a frequencia de operação
constant Tbase: integer :=5555;--5555 para a placa; para os testbench 1 muda a frequencia do tom
signal count_T,count_3T,count_7T, count_within_char, count_between_letters : integer:=0; -- contadores de cada tempo
signal count_T_TC, count_3T_TC,count_7T_TC, count_within_char_TC, count_between_letters_TC: std_logic:='0';-- sinal de contagem completa
signal counter : integer := 0;-- contador da palavra
signal temp: bit:='1';--qual o bit atual
signal count_pulse: integer range 0 to Tbase-1 := 0; -- Contador para a geração da freq do buzzer
signal tone: std_logic := '0'; -- Sinal de saida do buzzer modulado pela frequencia
signal morse_code : bit_vector (4 downto 0);-- vetor que é recebido pelo arquivo package (onde entra o número inteiro e sai o vetor de bits)
type MorseStates is (IDLE, TIME_T, TIME_3T, TIME_7T,NEXT_CARACTER, TIME_WITHIN_LETTER, TIME_BETWEEN_LETTERS);-- maquina de estados
signal STATE : MorseStates := IDLE;-- estado inicial

begin
process (clk, rst)
begin

if rst = '1' then -- não esquecer de resetar tudo
STATE <= IDLE;
counter <= 0;
temp<='0';
morse_code<="00000";
buzzer <= '1';
ledt<='0';
ledf<='0';
led3t<='0';
elsif rising_edge(clk) then -- no limiar de subida do clock

if count_pulse <= 0 then
-- Se o contador atingir 0, inverta o sinal do buzzer para gerar a frequencia
tone <= not tone;
count_pulse <= Tbase - 1; -- Reinicia o contador
else
count_pulse <= count_pulse - 1; -- Decrementa o contador
end if;
ledt<='0';
case STATE is
when IDLE =>
if entrada >= 0 and entrada <= 9 then --limitar o numero entre 0 a 9
morse_code <= Morse_codes(entrada);-- entra com a entrada na tabela e recebe o vetor de bit
temp<= morse_code(counter);-- seleciona o bit em relação ao contador (faz a varredura)
ledf<='0';-- desliga o led de quando acaba a palavra
if temp = '0' then -- caso seja ponto
count_T <=T; -- o valor de count passa a ser a constante definida anteriormente
STATE<= TIME_T;-- vai para o estado de T
elsif temp = '1' then --caso seja traco
count_3T <=3*T; -- o valor de count passa a ser a 3*constante definida anteriormente
STATE<= TIME_3T;-- vai para o estado de 3T
else
-- STATE<= IDLE;
null;
end if;
end if;
when TIME_T =>-- ponto
buzzer<=tone;-- saida recebe o tom
ledt<='1'; -- led do T acende
count_within_char_TC<='0';
if count_T=0 then
count_T_TC<='1'; -- flag de fim da contagem de T
else
count_T<=count_T-1;
end if;

if count_T_TC = '1' then-- caso tenha terminado T
count_within_char<=3*T; -- define o contador do intervalo entre bit
STATE<= TIME_WITHIN_LETTER; -- vai para o intervalo entre bit
end if;

when TIME_3T =>-- traco
buzzer<=tone;
led3t<='1';
count_within_char_TC<='0';
if count_3T=0 then
count_3T_TC<='1';
else
count_3T<=count_3T-1;
end if;
if count_3T_TC='1' then
count_within_char<=3*T;
STATE<=TIME_WITHIN_LETTER;
end if;

when TIME_7T => -- intervalo entre palavra
buzzer<=tone;
if count_7T=0 then
count_7T_TC<='1';
else
count_7T<=count_7T-1;
end if;

if count_7T_TC='1' then

STATE<=IDLE;
end if;
when NEXT_CARACTER =>-- proxima bit
counter<= counter+1; -- aumenta o contador da bit
temp<=morse_code(counter);-- seleciona o prox bit da bit
if counter = 4 then-- como foi feito apenas com numeros e o seu numero max é 5 (lembra do 0)
morse_code <= Morse_codes(entrada);
temp<= morse_code(counter);
counter<= 0;
count_between_letters<=3*T;
STATE<= TIME_BETWEEN_LETTERS;-- intervalo entre palavras/numeros/fim do caracter atual
ledf<='1';
else
-- recomeça o processo com o proximo bit
if temp = '0' then -- caso seja ponto
count_T <=T;
STATE<= TIME_T;
elsif temp = '1' then --caso seja traco
count_3T <=3*T;
STATE<= TIME_3T;
end if;
end if;

when TIME_WITHIN_LETTER =>-- "silencio" entre os bits
count_T_TC<='0'; -- reseta a flag do T
count_3T_TC<='0'; -- reseta a flag do 3T
buzzer<='1'; -- silencia a saida
ledt<='0';
led3t<='0';
if count_within_char=0 then
count_within_char_TC<='1';
else
count_within_char<=count_within_char-1;
end if;

if count_within_char_TC = '1' then
STATE<= NEXT_CARACTER;-- vai para o proximo bit
end if;

when TIME_BETWEEN_LETTERS =>-- intervalo entre palavras/numeros/fim do caracter atual
buzzer<='1';
if count_between_letters=0 then
count_between_letters_TC<='1';
else
count_between_letters<=count_between_letters-1;
end if;
if count_between_letters_TC='1' then
STATE<=IDLE;
end if;

end case;
end if;
end process;
end Behavioral;


42 changes: 42 additions & 0 deletions peripherals/morse/MorseCode_Package.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

package MorseCode_Package is
type MorseCodeTable is array(integer range 0 to 9) of bit_vector(0 to 4);

function Morse_codes(Morse_value : integer) return bit_vector;

constant MorseCodes : MorseCodeTable := (
-- Para uma futura implementação:
-- acrescentar as letra e caracteres especiais
-- utilizar de "." e "-" no lugar de "0" e "1"
-- 'A' => ".-", 'B' => "-...", 'C' => "-.-.",
-- 'D' => "-..", 'E' => ".", 'F' => "..-.",
-- 'G' => "--.", 'H' => "....", 'I' => "..",
-- 'J' => ".---", 'K' => "-.-", 'L' => ".-..",
-- 'M' => "--", 'N' => "-.", 'O' => "---",
-- 'P' => ".--.", 'Q' => "--.-", 'R' => ".-.",
-- 'S' => "...", 'T' => "-", 'U' => "..-",
-- 'V' => "...-", 'W' => ".--", 'X' => "-..-",
-- 'Y' => "-.--", 'Z' => "--..",
-- 0 => "-----", 1 => ".----", 2 => "..---",
-- 3 => "...--", 4 => " ....-", 5 => ".....",
-- 6 => "-....", 7 => "--...", 8 => "---..",
-- 9 => "----."
-- ponto e 0 e traço e 1
0 => "11111", 1 => "01111", 2 => "00111",
3 => "00011", 4 => "00001", 5 => "00000",
6 => "10000", 7 => "11000", 8 => "11100",
9 => "11110"
);

end package MorseCode_Package;

package body MorseCode_Package is
function Morse_Codes(Morse_value : integer) return bit_vector is
begin
return MorseCodes(Morse_value);
end function Morse_Codes;

end package body MorseCode_Package;
22 changes: 22 additions & 0 deletions peripherals/morse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# MorseCode Numbers

Esta implementação contempla o uso de um módulo buzzer (figura abaixo) como periférico. Que recebe um sinal de entrada e converte para um sinal sonoro itermitente que é representado por pontos e traços. Atualmente está implementado os números do código morse.


![# modulo buzzer ](./imagens/modulo%20buzzer.png)



O ponto tem o periodo de T e o traço 3T emitindo som, intervalo entre caracter tem 3T e entre palavras 7T. O período T pode variar de acordo com a experiência do operador de código morse. A seguir a tabela de código morse implementada:

![numeros morse](./imagens/Morse_code_numbers.png)

Este periférico possui 3 pinos, VCC de 3V3, GND e o pino de controle, no qual envia um sinal que emite som quando '0' e fica sem som quando '1'

Utilizou-se uma tabela para converter a entrada em pontos e traços (pontos são represnetados por '0' traços representados por '1') e uma maquina de estados para realizar os diferentes periodos de operação. A maquina de estados a seguir resume a operação deste programa


![maquina de estados ](./imagens/Maquina_de_estados.png)

# Simulação
A primeira simulação foi feita ainda antes do periférico ser implementado no projeto como um todo e pode ser visto nos arquivos [testbench](/peripherals/morse/testbench.vhd) e [tb.do](/peripherals/morse/tb.do)
Binary file added peripherals/morse/imagens/Maquina_de_estados.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added peripherals/morse/imagens/Morse_code_numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added peripherals/morse/imagens/modulo buzzer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions peripherals/morse/sint/PLL_Morse.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--Copyright (C) 2022 Intel Corporation. All rights reserved.
--Your use of Intel Corporation's design tools, logic functions
--and other software and tools, and any 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, at
--https://fpgasoftware.intel.com/eula.


component PLL_Morse
PORT
(
inclk0 : IN STD_LOGIC := '0';
c0 : OUT STD_LOGIC
);
end component;
9 changes: 9 additions & 0 deletions peripherals/morse/sint/PLL_Morse.ppf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE pinplan>
<pinplan intended_family="MAX 10" variation_name="PLL_Morse" megafunction_name="ALTPLL" specifies="all_ports">
<global>
<pin name="inclk0" direction="input" scope="external" source="clock" />
<pin name="c0" direction="output" scope="external" source="clock" />

</global>
</pinplan>
6 changes: 6 additions & 0 deletions peripherals/morse/sint/PLL_Morse.qip
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set_global_assignment -name IP_TOOL_NAME "ALTPLL"
set_global_assignment -name IP_TOOL_VERSION "21.1"
set_global_assignment -name IP_GENERATED_DEVICE_FAMILY "{MAX 10}"
set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "PLL_Morse.vhd"]
set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "PLL_Morse.cmp"]
set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "PLL_Morse.ppf"]
Loading

0 comments on commit 938a559

Please sign in to comment.