Skip to content

Commit

Permalink
Minor stepmotor fixes and initial testbench
Browse files Browse the repository at this point in the history
  • Loading branch information
rayanmst committed Sep 12, 2021
1 parent cdb1e6e commit 022f19b
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 30 deletions.
64 changes: 34 additions & 30 deletions peripherals/step_motor/stepmotor.vhd
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-------------------------------------------------------------------
-- Name : stepmotor.vhd
-- Author : Rayan Martins Steinbach
-- Description : Step motor controller
-- Name : stepmotor.vhd --
-- Author : Rayan Martins Steinbach --
-- Description : Step motor controller --
-------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library ieee; -- Biblioteca padrão
use ieee.std_logic_1164.all; -- Elementos lógicos
use ieee.numeric_std.all; -- Conversões entre tipos

entity stepmotor is
port(
Expand All @@ -24,15 +24,16 @@ end entity stepmotor;
architecture rtl of stepmotor is
TYPE state_t is (A, AB, B, BC, C, CD, D, DA);
signal state : state_t;
signal rot, cntr : std_logic;
signal rot: std_logic;
signal outs : std_logic_vector(3 downto 0);
signal cntr : unsigned(7 downto 0);
begin
in1 <= outs(0);
in2 <= outs(1);
in3 <= outs(2);
in4 <= outs(3);
rot <= cntr(to_integer(speed));


rotate: process(clk, rst)
begin
if rst = '1' then
Expand All @@ -43,14 +44,15 @@ begin
cntr <= cntr + 1;
end if;
end process rotate;
rot <= cntr(to_integer(speed));

mealy : process(rot, rst)
begin
if rst = '1' then
state <= A;
end if;
if rising_edge(clk_s) then
if en = '1' then
if rising_edge(rot) then
if ena = '1' then
if stop = '0' then
case state is
when A =>
Expand Down Expand Up @@ -125,23 +127,25 @@ begin

moore : process(clk)
begin
case state is
when A =>
outs <= "1000";
when AB =>
outs <= "1100";
when B =>
outs <= "0100";
when BC =>
outs <= "0110";
when C =>
outs <= "0010";
when CD =>
outs <= "0011";
when D =>
outs <= "0001";
when DA =>
outs <= "1001";
end case;
end process mealy;
if rising_edge(clk) then
case state is
when A =>
outs <= "1000";
when AB =>
outs <= "1100";
when B =>
outs <= "0100";
when BC =>
outs <= "0110";
when C =>
outs <= "0010";
when CD =>
outs <= "0011";
when D =>
outs <= "0001";
when DA =>
outs <= "1001";
end case;
end if;
end process moore;
end architecture;
28 changes: 28 additions & 0 deletions peripherals/step_motor/tb_stepmotor.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
vlib workstart

#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

#Mosta forma de onda
view wave

#Adiciona ondas específicas
# -radix: binary, hex, dec
# -label: nome da forma de onda
add wave -radix binary -label clk /clk
add wave -radix binary -label reverse /reverse
add wave -radix binary -label reset /rst
add wave -radix binary -label stop /stop
add wave -radix binary -label enable /ena
add wave -radix binary -label half_full /half_full
add wave -radix unsigned -label speed /speed
add wave -radix binary -label output /outputs
add wave -label state /motor0/state

#Simula até 500ms
run 500ms

wave zoomfull
93 changes: 93 additions & 0 deletions peripherals/step_motor/tb_stepmotor.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
--! Bibliotecas !--
library ieee; --! Biblioteca padrão
use ieee.std_logic_1164.all; --! Elementos lógicos
use ieee.numeric_std.all; --! Conversões entre tipos

entity tb_stepmotor is
end entity tb_stepmotor;


architecture RTL of tb_stepmotor is
signal clk, reverse, rst, stop,ena : std_logic;
signal half_full : std_logic;
signal in1: std_logic;
signal in2: std_logic;
signal in3: std_logic;
signal in4: std_logic;
signal speed : unsigned(2 downto 0);
signal outputs: std_logic_vector(3 downto 0); -- @suppress "signal outputs is never read"
begin
outputs(0) <= in1; outputs(1) <= in2;
outputs(2) <= in3; outputs(3) <= in4;

motor0: entity work.stepmotor
port map(
clk => clk,
reverse => reverse,
rst => rst,
stop => stop,
ena => ena,
half_full => half_full,
in1 => in1,
in2 => in2,
in3 => in3,
in4 => in4,
speed => speed
);

clk0: process is
begin
clk <= '0';
wait for 1 ms;
clk <= '1';
wait for 1 ms;
end process clk0;

en0: process is
begin
ena <= '0';
wait for 6 ms;
ena <= '1';
wait;
end process en0;

speed0: process is
begin
rst <='0';
stop <='0';
speed <= to_unsigned(0, speed'length);
wait for 140 ms;
stop <= '1';
wait for 10 ms;
stop <= '0';
rst <= '1';
wait for 2 ms;
rst <= '0';
for i in 0 to 7 loop
speed <= to_unsigned(i, speed'length);
wait for 20 ms;
end loop;
wait;
end process speed0;

hf0: process is
begin
half_full <= '0';
wait for 140 ms;
half_full <= '1';
wait for 140 ms;
half_full <= '0';
wait;
end process hf0;

rev0: process is
begin
reverse <= '0';
wait for 70 ms;
reverse <= '1';
wait for 140 ms;
reverse <= '0';
wait;
end process rev0;

end architecture RTL;
Binary file added peripherals/step_motor/vsim.wlf
Binary file not shown.
94 changes: 94 additions & 0 deletions peripherals/step_motor/work/_info
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
m255
K4
z2
!s11e MIXED_VERSIONS
13
!s112 1.1
!i10d 8192
!i10e 25
!i10f 100
cModel Technology
Z0 dC:/Users/rayan/Documents/GitHub/riscv-multicycle/peripherals/step_motor
Estepmotor
Z1 w1631411376
Z2 DPx4 ieee 11 numeric_std 0 22 aU^R8eGcicLcUFIaBQSL>3
Z3 DPx3 std 6 textio 0 22 zE1`LPoLg^DX3Oz^4Fj1K3
Z4 DPx4 ieee 14 std_logic_1164 0 22 cVAk:aDinOX8^VGI1ekP<3
!i122 6
R0
Z5 8stepmotor.vhd
Z6 Fstepmotor.vhd
l0
L10 1
VRGa4cnclWom;dB=?6`1_[2
!s100 FEW6>`>5==XejOdSi0F:e3
Z7 OV;C;2021.1;73
32
Z8 !s110 1631411930
!i10b 1
Z9 !s108 1631411930.000000
Z10 !s90 -reportprogress|300|stepmotor.vhd|tb_stepmotor.vhd|
Z11 !s107 tb_stepmotor.vhd|stepmotor.vhd|
!i113 1
Z12 tExplicit 1 CvgOpt 0
Artl
R2
R3
R4
Z13 DEx4 work 9 stepmotor 0 22 RGa4cnclWom;dB=?6`1_[2
!i122 6
l30
Z14 L24 127
Z15 VBl?O0?m]IWiU;Qai@;FXf2
Z16 !s100 >Ak`S;8YIlFC]QOIH_1WS2
R7
32
R8
!i10b 1
R9
R10
R11
!i113 1
R12
Etb_stepmotor
Z17 w1631411894
R2
R3
R4
!i122 6
R0
Z18 8tb_stepmotor.vhd
Z19 Ftb_stepmotor.vhd
l0
L6 1
VKFJBX=L65oZ:V>6naD>?m3
!s100 PgVCU]oKP[5AgP=`B0g6T0
R7
32
R8
!i10b 1
R9
R10
R11
!i113 1
R12
Artl
R13
R2
R3
R4
Z20 DEx4 work 12 tb_stepmotor 0 22 KFJBX=L65oZ:V>6naD>?m3
!i122 6
l19
L10 84
VbDU5X>4bPnn2oH6:SI>m[1
!s100 l9FUkimFLh^z2]fP[QNb]2
R7
32
R8
!i10b 1
R9
R10
R11
!i113 1
R12
Binary file added peripherals/step_motor/work/_lib.qdb
Binary file not shown.
Binary file added peripherals/step_motor/work/_lib1_0.qdb
Binary file not shown.
Binary file added peripherals/step_motor/work/_lib1_0.qpg
Binary file not shown.
Binary file added peripherals/step_motor/work/_lib1_0.qtl
Binary file not shown.
4 changes: 4 additions & 0 deletions peripherals/step_motor/work/_vmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
m255
K4
z0
cModel Technology
10 changes: 10 additions & 0 deletions peripherals/step_motor/workstart/_info
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
m255
K4
z2
13
!s112 1.1
!i10d 8192
!i10e 25
!i10f 100
cModel Technology
dC:/Users/rayan/Documents/GitHub/riscv-multicycle/peripherals/step_motor

0 comments on commit 022f19b

Please sign in to comment.