Skip to content

Commit

Permalink
atualizando software stepmotor
Browse files Browse the repository at this point in the history
  • Loading branch information
juliopacheco12 committed Jun 23, 2023
1 parent aa651d9 commit 4c47a6f
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 276 deletions.
5 changes: 3 additions & 2 deletions memory/iram_quartus.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ BEGIN
clock_enable_input_a => "BYPASS",
clock_enable_output_a => "BYPASS",
intended_device_family => "MAX 10",
-- init_file => "./software/quartus_blink.hex",
init_file => "./software/irq/quartus_irq_example.hex",
init_file => "../../software/step_motor/quartus_main_step_motor.hex",
--init_file => "../../software/quartus_blink.hex",
--init_file => "./software/irq/quartus_irq_example.hex",
lpm_hint => "ENABLE_RUNTIME_MOD=YES,INSTANCE_NAME=1",
lpm_type => "altsyncram",
numwords_a => 1024,
Expand Down
2 changes: 1 addition & 1 deletion peripherals/gpio/sint/de10_lite/de10_lite.qsf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set_global_assignment -name DEVICE 10M50DAF484C7G
set_global_assignment -name TOP_LEVEL_ENTITY de0_lite
set_global_assignment -name ORIGINAL_QUARTUS_VERSION 15.0.0
set_global_assignment -name PROJECT_CREATION_TIME_DATE "18:49:34 JUNE 20, 2019"
set_global_assignment -name LAST_QUARTUS_VERSION "20.1.1 Lite Edition"
set_global_assignment -name LAST_QUARTUS_VERSION "21.1.1 Standard Edition"
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
Expand Down
15 changes: 11 additions & 4 deletions peripherals/step_motor/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Step motor controller

Implementação de um periférico controlador de motor de passo compatível com o circuito integrado ULN2003.
Implementação de um periférico controlador de motor de passo 28BYJ-48 compatível com o circuito integrado ULN2003.

## ToDo

* Testes e sintetização em hardware
* Encontrar clock mais adequado para o funcionamento do motor de passo
* Testes e sintetização em hardware - FEITO
* Encontrar clock mais adequado para o funcionamento do motor de passo - FEITO

## Software

Foi implementado um software capaz de colocar o motor em estado de reset, parar o motor, variar sua velocidade, inverter sua rotação e o tamanho do passo. Para mais detalhes sobre a utilização de cada função, consultar o arquivo [step_motor.h](../../software/step_motor/step_motor.h)
Foi implementado um software capaz de colocar o motor em estado de reset, parar o motor, variar sua velocidade, inverter sua rotação e o tamanho do passo. Para mais detalhes sobre a utilização de cada função, consultar o arquivo [step_motor.h](../../software/step_motor/step_motor.h) e [step_motor.c](../../software/step_motor/step_motor.c). Para mais detalhes do teste realizado em hardware, consultar o arquivo [main_step_motor.c](../../software/step_motor/main_step_motor.c).

## Hardware
Foi criado o componente [stepmotor.vhd](../../peripherals/step_motor/stepmotor.vhd). Para testar em simulação, é necessário usar os arquivos [testbench.vhd](../../peripherals/step_motor/testbench.vhd) e [testbench.do](../../peripherals/step_motor/testbench.do).

## Descrição dos pinos

Expand All @@ -30,6 +33,10 @@ Foi implementado um software capaz de colocar o motor em estado de reset, parar

`speed`: Define a velocidade do motor em um intervalo de 0 até 7

## Sintetização

Ao sintetizar a saída com valores da maquina de estados foi conectada aos LEDR(3 downto 0) para ve os estados atuais, bem como aos pinos ARDUINO_IO(3 downto 0) para conectar ao circuito integrado ULN2003. O GND do CI foi colocado na placa, mas é necessario conectar o VDD do CI à uma fonte, evitando a possível queima da placa.

## Funcionamento do periférico

![Figura [1] - Simulação completa](./_images/im0.png)
Expand Down
11 changes: 10 additions & 1 deletion peripherals/step_motor/stepmotor.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ begin
end if;
end process;

-- Divisor de clock duplo para conseguir implementar em
-- hardware o tempo necessario para motor de passo girar
rotate : process(clk, reset)
-- Variavel extra para dividir counter do divisor de clock
variable div:unsigned(4 downto 0);
begin
if reset = '1' then
cntr <= (others => '0');
div := (others => '0');
elsif rising_edge(clk) then
cntr <= cntr + 1;
div := div + 1;
-- Incrementa counter ao estourar valor de div
if div = x"0000" then
cntr <= cntr + 1;
end if;
end if;
end process rotate;
rot <= cntr(7 - to_integer(speed));
Expand Down
10 changes: 5 additions & 5 deletions peripherals/step_motor/tb_stepmotor.do
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
vlib workstart

#compila projeto: todos os aquivo. Ordem é importante
#compila projeto: todos os aquivo. Ordem importante
vcom stepmotor.vhd tb_stepmotor.vhd

#Simula (work é o diretorio, testbench é o nome da entity)
vsim -t ns work.tb_stepmotor
#Simula (work o diretorio, testbench o nome da entity)
vsim -voptargs="+acc" -t ns work.tb_stepmotor

#Mosta forma de onda
view wave

#Adiciona ondas específicas
#Adiciona ondas espec�ficas
# -radix: binary, hex, dec
# -label: nome da forma de onda
add wave -radix binary -label clk /clk
Expand All @@ -22,7 +22,7 @@ add wave -radix unsigned -label speed /speed
add wave -radix binary -label output /outputs
add wave -label state /motor0/state

#Simula até 500ms
#Simula at� 500ms
run 500ms

wave zoomfull
2 changes: 1 addition & 1 deletion peripherals/step_motor/testbench.do
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ vcom ../../core/txt_util.vhdl
vcom ../../core/trace_debug.vhd
vcom testbench.vhd

vsim -t ns work.coretestbench
vsim -voptargs="+acc" -t ns work.coretestbench

view wave
add wave -radix binary /clk
Expand Down
8 changes: 8 additions & 0 deletions peripherals/step_motor/testbench.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ architecture RTL of coretestbench is
-- StepMotor signals
signal ddata_r_stepmot : std_logic_vector(31 downto 0);
signal outs : std_logic_vector(3 downto 0);
signal ddata_r_dif_fil : std_logic_vector(31 downto 0);
signal ddata_r_lcd : std_logic_vector(31 downto 0);
signal ddata_r_nn_accelerator : std_logic_vector(31 downto 0);
signal ddata_r_fir_fil : std_logic_vector(31 downto 0);

begin

Expand Down Expand Up @@ -203,6 +207,10 @@ begin
ddata_r_adc => ddata_r_adc,
ddata_r_i2c => ddata_r_i2c,
ddata_r_timer => ddata_r_timer,
ddata_r_dif_fil => ddata_r_dif_fil,
ddata_r_lcd => ddata_r_lcd,
ddata_r_nn_accelerator => ddata_r_nn_accelerator,
ddata_r_fir_fil => ddata_r_fir_fil,
ddata_r_stepmot => ddata_r_stepmot,
ddata_r_periph => ddata_r_periph
);
Expand Down
2 changes: 1 addition & 1 deletion software/_core/sections.ld
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SECTIONS {
} > ram AT > rom

.bss : {
_bss_start = .;
__bss_start = .;
*(.bss .bss.*)
. = ALIGN(4);
_bss_end = .;
Expand Down
2 changes: 1 addition & 1 deletion software/_core/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ _pvstart:
# lb s4, 2(a5)
# lb s5, 3(a5)

jal init_data_section
/* jal init_data_section */

/* push zeros on the stack for argc and argv */
/* (stack is aligned to 16 bytes in riscv calling convention) */
Expand Down
6 changes: 1 addition & 5 deletions software/step_motor/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
ifndef RISCV_TOOLS_PREFIX
#RISCV_TOOLS_PREFIX=riscv-none-embed-
# Para usar no LSC
RISCV_TOOLS_PREFIX = /home/rayanst/.local/xPacks/@xpack-dev-tools/riscv-none-embed-gcc/10.1.0-1.1.1/.content/bin/riscv-none-embed-
endif
RISCV_TOOLS_PREFIX = /var/data/aluno/gcc/bin/riscv-none-elf-

QUARTUS_DIR=/home/rayanst/intelFPGA_lite/20.1/quartus/bin/
CXX = $(RISCV_TOOLS_PREFIX)g++ -march=rv32im
Expand Down
45 changes: 26 additions & 19 deletions software/step_motor/main_step_motor.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
#include <stdint.h>
#include "step_motor.h"

// Arquivo principal para criar funcionalidade do periférico step_motor
// Teste seguindo passos:
// Iniciar motor com velocidade x, rotação em sentido anti-horário e full step (A-B-C-D-A)
// Alterar step para half step (A-AB-B-BC-C-CD-D-DA-A)
// Alterar sentido da rotação para sentido horário
// Para motor
// Refazer em looping

int main() {
reset_motor(1);
while(1) {
reset_motor(0);
change_speed(5);
change_step(1);
stop_motor(0);
reverse_rotation(0);
delay_(2);

change_step(0);
delay_(1);

stop_motor(1);
delay_(3);
reverse_rotation(1);
delay_(1);

change_speed(0);
delay_(1);
reset_motor(1); // Resetar motor

reset_motor(0); // Baixar nivel do reset para iniciar teste
change_speed(2); // Iniciar velocidade em 2 (pode ser outro valor de 0 a 7, pois componente recebe 3 bits)
change_step(1); // Iniciar passo em fullstep (A-B-C-D-A)
stop_motor(0); // Iniciar motor
reverse_rotation(0); // Iniciar motor com rotação no sentido anti-horário
delay_(500000); // Delay de tempo suficiente para visualizar em hardware situação atual

change_step(0); // Alterar passo para half step (A-AB-B-BC-C-CD-D-DA-A)
delay_(500000); // Delay de tempo suficiente para visualizar em hardware situação atual

reverse_rotation(1); // Alterar sentido da rotação para sentido horário
delay_(500000); // Delay de tempo suficiente para visualizar em hardware situação atual

stop_motor(1); // Parar motor
delay_(500000); // Delay de tempo suficiente para visualizar em hardware situação atual
}
return 0;
}
}
Loading

0 comments on commit 4c47a6f

Please sign in to comment.