mirror of
https://github.com/Klagarge/Cursor.git
synced 2025-08-10 00:03:09 +00:00
Initial commit
This commit is contained in:
148
Cursor_test/hdl/cursor_tester_test.vhd
Normal file
148
Cursor_test/hdl/cursor_tester_test.vhd
Normal file
@@ -0,0 +1,148 @@
|
||||
ARCHITECTURE test OF cursor_tester IS
|
||||
|
||||
constant clockFrequency: real := 66.0E6;
|
||||
constant clockPeriod: time := 1.0/clockFrequency * 1 sec;
|
||||
signal sClock: std_uLogic := '1';
|
||||
|
||||
signal testMode_int: std_uLogic;
|
||||
|
||||
constant buttonsPulseWidth : time := 100 us;
|
||||
|
||||
constant pulsesPerTurn: integer := 2000;
|
||||
constant pwmReadBitNb: positive :=8;
|
||||
constant pwmLowpassAddBitNb: positive :=8;
|
||||
constant voltageToSpeedBitNb: positive := 8;
|
||||
signal side1Acc: unsigned(pwmReadBitNb+pwmLowpassAddBitNb-1 downto 0) := (others => '0');
|
||||
signal side2Acc: unsigned(pwmReadBitNb+pwmLowpassAddBitNb-1 downto 0) := (others => '0');
|
||||
signal side1M: unsigned(pwmReadBitNb-1 downto 0);
|
||||
signal side2M: unsigned(pwmReadBitNb-1 downto 0);
|
||||
signal position: signed(pwmReadBitNb+voltageToSpeedBitNb-1 downto 0) := (others => '0');
|
||||
signal stepCount: unsigned(1 downto 0);
|
||||
|
||||
BEGIN
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- clock and reset
|
||||
--
|
||||
reset <= '1', '0' after 2*clockPeriod;
|
||||
|
||||
sClock <= not sClock after clockPeriod/2;
|
||||
clock <= transport sClock after clockPeriod*9/10;
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- test sequence
|
||||
--
|
||||
process
|
||||
begin
|
||||
|
||||
testMode_int <= '1';
|
||||
|
||||
restart <= '0';
|
||||
go1 <= '0';
|
||||
go2 <= '0';
|
||||
button4 <= '0';
|
||||
|
||||
sensor1 <= '0';
|
||||
sensor2 <= '0';
|
||||
|
||||
wait for 0.1 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- restart
|
||||
restart <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 0.25 ms;
|
||||
sensor1 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 0.25 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- advance to first stop point
|
||||
go1 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 2 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- advance to second stop point
|
||||
go2 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 2 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- go back to first stop point
|
||||
go1 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 2 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- back to start with sensor reset
|
||||
restart <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 0.5 ms;
|
||||
sensor1 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 0.5 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- advance to second stop point
|
||||
go2 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 3 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- back to start with counter stop
|
||||
restart <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 2 ms;
|
||||
sensor1 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 1 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- quit test mode
|
||||
testMode_int <= '0';
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- advance to first stop point
|
||||
go1 <= '1', '0' after buttonsPulseWidth;
|
||||
wait for 2 ms;
|
||||
|
||||
wait;
|
||||
end process;
|
||||
|
||||
testMode <= testMode_int;
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- PWM lowpass
|
||||
--
|
||||
process(sClock)
|
||||
begin
|
||||
if rising_edge(sClock) then
|
||||
if side1 = '1' then
|
||||
side1Acc <= side1Acc + 2**pwmReadBitNb-1 - shift_right(side1Acc, pwmLowpassAddBitNb);
|
||||
else
|
||||
side1Acc <= side1Acc - shift_right(side1Acc, pwmLowpassAddBitNb);
|
||||
end if;
|
||||
if side2 = '1' then
|
||||
side2Acc <= side2Acc + 2**pwmReadBitNb-1 - shift_right(side2Acc, pwmLowpassAddBitNb);
|
||||
else
|
||||
side2Acc <= side2Acc - shift_right(side2Acc, pwmLowpassAddBitNb);
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
side1M <= resize(shift_right(side1Acc, pwmLowpassAddBitNb), side1M'length);
|
||||
side2M <= resize(shift_right(side2Acc, pwmLowpassAddBitNb), side2M'length);
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- motor feedback
|
||||
--
|
||||
count: process (sClock)
|
||||
begin
|
||||
if motorOn = '1' then
|
||||
if testMode_int = '0' then
|
||||
position <= position + to_integer(side1M) - to_integer(side2M);
|
||||
else
|
||||
position <= position + (to_integer(side1M) - to_integer(side2M)) * 5;
|
||||
end if;
|
||||
end if;
|
||||
end process count;
|
||||
|
||||
stepCount <= resize(shift_right(unsigned(position), position'length-stepCount'length), stepCount'length);
|
||||
|
||||
encoderA <= stepCount(1);
|
||||
encoderB <= not stepCount(1) xor stepCount(0);
|
||||
encoderI <= '1' when stepCount = pulsesPerTurn-1 else '0';
|
||||
|
||||
END ARCHITECTURE test;
|
22
Cursor_test/hdl/divider_tester_test.vhd
Normal file
22
Cursor_test/hdl/divider_tester_test.vhd
Normal file
@@ -0,0 +1,22 @@
|
||||
ARCHITECTURE test OF divider_tester IS
|
||||
|
||||
constant clockFrequency: real := 66.0E6;
|
||||
constant clockPeriod: time := 1.0/clockFrequency * 1 sec;
|
||||
signal sClock: std_uLogic := '1';
|
||||
|
||||
BEGIN
|
||||
|
||||
reset <= '1', '0' after clockPeriod/4;
|
||||
|
||||
sClock <= not sClock after clockPeriod/2;
|
||||
clock <= sClock after clockPeriod/10;
|
||||
|
||||
testMode <= '1', '0' after 10000*clockPeriod;
|
||||
|
||||
-- start <= '0',
|
||||
-- '1' after 210 us,
|
||||
-- '0' after 210 us + clockPeriod,
|
||||
-- '1' after 2.1 ms,
|
||||
-- '0' after 2.1 ms + clockPeriod;
|
||||
|
||||
END ARCHITECTURE test;
|
@@ -0,0 +1,8 @@
|
||||
--
|
||||
-- Auto generated dummy architecture for leaf level instance.
|
||||
--
|
||||
ARCHITECTURE generatedInstance OF positionCounter_tester IS
|
||||
BEGIN
|
||||
|
||||
|
||||
END generatedInstance;
|
1
Cursor_test/hds/.hdlsidedata/_cursor_tb_entity.vhg._fpf
Normal file
1
Cursor_test/hds/.hdlsidedata/_cursor_tb_entity.vhg._fpf
Normal file
@@ -0,0 +1 @@
|
||||
DIALECT atom VHDL_ANY
|
1
Cursor_test/hds/.hdlsidedata/_cursor_tb_struct.vhg._fpf
Normal file
1
Cursor_test/hds/.hdlsidedata/_cursor_tb_struct.vhg._fpf
Normal file
@@ -0,0 +1 @@
|
||||
DIALECT atom VHDL_ANY
|
@@ -0,0 +1 @@
|
||||
DIALECT atom VHDL_ANY
|
@@ -0,0 +1,4 @@
|
||||
INCLUDE list {
|
||||
DEFAULT atom 1
|
||||
}
|
||||
DIALECT atom VHDL_2008
|
@@ -0,0 +1,4 @@
|
||||
INCLUDE list {
|
||||
DEFAULT atom 1
|
||||
}
|
||||
DIALECT atom VHDL_2008
|
@@ -0,0 +1 @@
|
||||
DIALECT atom VHDL_2008
|
2
Cursor_test/hds/_cursor_tb._epf
Normal file
2
Cursor_test/hds/_cursor_tb._epf
Normal file
@@ -0,0 +1,2 @@
|
||||
DEFAULT_ARCHITECTURE atom struct
|
||||
DEFAULT_FILE atom cursor_tb/struct.bd
|
2
Cursor_test/hds/_divider_tb._epf
Normal file
2
Cursor_test/hds/_divider_tb._epf
Normal file
@@ -0,0 +1,2 @@
|
||||
DEFAULT_ARCHITECTURE atom struct
|
||||
DEFAULT_FILE atom divider_tb/struct.bd
|
2
Cursor_test/hds/_positioncounter_tb._epf
Normal file
2
Cursor_test/hds/_positioncounter_tb._epf
Normal file
@@ -0,0 +1,2 @@
|
||||
DEFAULT_ARCHITECTURE atom struct
|
||||
DEFAULT_FILE atom position@counter_tb/struct.bd
|
4174
Cursor_test/hds/cursor_tb/struct.bd
Normal file
4174
Cursor_test/hds/cursor_tb/struct.bd
Normal file
File diff suppressed because it is too large
Load Diff
1230
Cursor_test/hds/cursor_tb/symbol.sb
Normal file
1230
Cursor_test/hds/cursor_tb/symbol.sb
Normal file
File diff suppressed because it is too large
Load Diff
2253
Cursor_test/hds/cursor_tester/interface
Normal file
2253
Cursor_test/hds/cursor_tester/interface
Normal file
File diff suppressed because it is too large
Load Diff
118
Cursor_test/hds/cursor_tester/test.vhd
Normal file
118
Cursor_test/hds/cursor_tester/test.vhd
Normal file
@@ -0,0 +1,118 @@
|
||||
ARCHITECTURE test OF cursor_tester IS
|
||||
|
||||
constant clockPeriod: time := 50 ns;
|
||||
signal sClock: std_uLogic := '1';
|
||||
|
||||
constant pulsesPerTurn: integer := 200;
|
||||
constant stepPeriodNb: positive := 8;
|
||||
signal stepEn: std_uLogic := '0';
|
||||
signal direction: std_uLogic;
|
||||
signal turning: std_uLogic;
|
||||
signal stepCount: unsigned(10 downto 0) := (others => '0');
|
||||
|
||||
BEGIN
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- clock and reset
|
||||
--
|
||||
reset <= '1', '0' after clockPeriod/4;
|
||||
|
||||
sClock <= not sClock after clockPeriod/2;
|
||||
clock <= sClock after clockPeriod/10;
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- test sequence
|
||||
--
|
||||
process
|
||||
begin
|
||||
|
||||
testMode <= '1';
|
||||
|
||||
restart <= '0';
|
||||
go1 <= '0';
|
||||
go2 <= '0';
|
||||
setPoint <= '0';
|
||||
|
||||
sensor1 <= '0';
|
||||
sensor2 <= '0';
|
||||
|
||||
wait for 1 us;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- advance to first stop point
|
||||
go1 <= '1', '0' after 1 us;
|
||||
wait for 4 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- advance to second stop point
|
||||
go2 <= '1', '0' after 1 us;
|
||||
wait for 4 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- back to start with sensor reset
|
||||
restart <= '1', '0' after 1 us;
|
||||
wait for 0.5 ms;
|
||||
sensor1 <= '1', '0' after 1 us;
|
||||
wait for 0.5 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- advance to second stop point
|
||||
go2 <= '1', '0' after 1 us;
|
||||
wait for 7 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- go back to first stop point
|
||||
go1 <= '1', '0' after 1 us;
|
||||
wait for 4 ms;
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- back to start with counter stop
|
||||
restart <= '1', '0' after 1 us;
|
||||
wait for 4 ms;
|
||||
sensor1 <= '1', '0' after 1 us;
|
||||
wait for 1 ms;
|
||||
|
||||
wait;
|
||||
end process;
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- motor feedback
|
||||
--
|
||||
turning <= motorOn;
|
||||
|
||||
findDirection: process(side1, side2)
|
||||
begin
|
||||
if (side1 = '1') and (side2 = '0') then
|
||||
direction <= '1';
|
||||
elsif (side1 = '0') and (side2 = '1') then
|
||||
direction <= '0';
|
||||
end if;
|
||||
end process findDirection;
|
||||
|
||||
stepEn <= not stepEn after (stepPeriodNb/4)*clockPeriod;
|
||||
|
||||
count: process (stepEn)
|
||||
begin
|
||||
if turning = '1' then
|
||||
if direction = '1' then
|
||||
if stepCount < pulsesPerTurn-1 then
|
||||
stepCount <= stepCount + 1;
|
||||
else
|
||||
stepCount <= to_unsigned(0, stepCount'length);
|
||||
end if;
|
||||
else
|
||||
if stepCount > 0 then
|
||||
stepCount <= stepCount - 1;
|
||||
else
|
||||
stepCount <= to_unsigned(pulsesPerTurn-1, stepCount'length);
|
||||
end if;
|
||||
end if;
|
||||
end if;
|
||||
end process count;
|
||||
|
||||
encoderA <= stepCount(1);
|
||||
encoderB <= not stepCount(1) xor stepCount(0);
|
||||
encoderI <= '1' when stepCount = pulsesPerTurn-1 else '0';
|
||||
|
||||
END test;
|
2770
Cursor_test/hds/divider_tb/struct.bd
Normal file
2770
Cursor_test/hds/divider_tb/struct.bd
Normal file
File diff suppressed because it is too large
Load Diff
1230
Cursor_test/hds/divider_tb/symbol.sb
Normal file
1230
Cursor_test/hds/divider_tb/symbol.sb
Normal file
File diff suppressed because it is too large
Load Diff
1584
Cursor_test/hds/divider_tester/interface
Normal file
1584
Cursor_test/hds/divider_tester/interface
Normal file
File diff suppressed because it is too large
Load Diff
21
Cursor_test/hds/divider_tester/test.vhd
Normal file
21
Cursor_test/hds/divider_tester/test.vhd
Normal file
@@ -0,0 +1,21 @@
|
||||
ARCHITECTURE test OF divider_tester IS
|
||||
|
||||
constant clockPeriod: time := 50 ns;
|
||||
signal sClock: std_uLogic := '1';
|
||||
|
||||
BEGIN
|
||||
|
||||
reset <= '1', '0' after clockPeriod/4;
|
||||
|
||||
sClock <= not sClock after clockPeriod/2;
|
||||
clock <= sClock after clockPeriod/10;
|
||||
|
||||
testMode <= '1', '0' after 10000*clockPeriod;
|
||||
|
||||
start <= '0',
|
||||
'1' after 210 us,
|
||||
'0' after 210 us + clockPeriod,
|
||||
'1' after 2.1 ms,
|
||||
'0' after 2.1 ms + clockPeriod;
|
||||
|
||||
END test;
|
3009
Cursor_test/hds/position@counter_tb/struct.bd
Normal file
3009
Cursor_test/hds/position@counter_tb/struct.bd
Normal file
File diff suppressed because it is too large
Load Diff
1230
Cursor_test/hds/position@counter_tb/symbol.sb
Normal file
1230
Cursor_test/hds/position@counter_tb/symbol.sb
Normal file
File diff suppressed because it is too large
Load Diff
1737
Cursor_test/hds/position@counter_tester/interface
Normal file
1737
Cursor_test/hds/position@counter_tester/interface
Normal file
File diff suppressed because it is too large
Load Diff
57
Cursor_test/hds/position@counter_tester/test.vhd
Normal file
57
Cursor_test/hds/position@counter_tester/test.vhd
Normal file
@@ -0,0 +1,57 @@
|
||||
ARCHITECTURE test OF positionCounter_tester IS
|
||||
|
||||
constant clockPeriod: time := 50 ns;
|
||||
signal sClock: std_uLogic := '1';
|
||||
|
||||
constant pulsesPerTurn: integer := 200;
|
||||
constant stepPeriodNb: positive := 16;
|
||||
signal stepEn: std_uLogic := '0';
|
||||
signal direction: std_uLogic;
|
||||
signal stepCount: unsigned(10 downto 0) := (others => '0');
|
||||
|
||||
BEGIN
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- clock and reset
|
||||
--
|
||||
reset <= '1', '0' after clockPeriod/4;
|
||||
|
||||
sClock <= not sClock after clockPeriod/2;
|
||||
clock <= sClock after clockPeriod/10;
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- encoder signals
|
||||
--
|
||||
direction <= '1', '0' after 2000*clockPeriod;
|
||||
|
||||
stepEn <= not stepEn after (stepPeriodNb/4)*clockPeriod;
|
||||
|
||||
count: process (stepEn)
|
||||
begin
|
||||
if direction = '1' then
|
||||
if stepCount < pulsesPerTurn-1 then
|
||||
stepCount <= stepCount + 1;
|
||||
else
|
||||
stepCount <= to_unsigned(0, stepCount'length);
|
||||
end if;
|
||||
else
|
||||
if stepCount > 0 then
|
||||
stepCount <= stepCount - 1;
|
||||
else
|
||||
stepCount <= to_unsigned(pulsesPerTurn-1, stepCount'length);
|
||||
end if;
|
||||
end if;
|
||||
end process count;
|
||||
|
||||
encoderA <= stepCount(1);
|
||||
encoderB <= stepCount(1) xor stepCount(0);
|
||||
encoderI <= '1' when stepCount = pulsesPerTurn-1 else '0';
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- control signals
|
||||
--
|
||||
clear <= '0',
|
||||
'1' after 100*clockPeriod,
|
||||
'0' after 101*clockPeriod;
|
||||
|
||||
END test;
|
2752
Cursor_test/hds/pulse@width@modulator_tb/struct.bd
Normal file
2752
Cursor_test/hds/pulse@width@modulator_tb/struct.bd
Normal file
File diff suppressed because it is too large
Load Diff
1226
Cursor_test/hds/pulse@width@modulator_tb/symbol.sb
Normal file
1226
Cursor_test/hds/pulse@width@modulator_tb/symbol.sb
Normal file
File diff suppressed because it is too large
Load Diff
1575
Cursor_test/hds/pulse@width@modulator_tester/interface
Normal file
1575
Cursor_test/hds/pulse@width@modulator_tester/interface
Normal file
File diff suppressed because it is too large
Load Diff
29
Cursor_test/hds/pulse@width@modulator_tester/test.vhd
Normal file
29
Cursor_test/hds/pulse@width@modulator_tester/test.vhd
Normal file
@@ -0,0 +1,29 @@
|
||||
ARCHITECTURE test OF pulseWidthModulator_tester IS
|
||||
|
||||
constant clockPeriod: time := 50 ns;
|
||||
signal sClock: std_uLogic := '1';
|
||||
|
||||
constant enPeriodNb: positive := 3;
|
||||
signal sEn: std_uLogic := '0';
|
||||
|
||||
BEGIN
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- clock and reset
|
||||
--
|
||||
reset <= '1', '0' after clockPeriod/4;
|
||||
|
||||
sClock <= not sClock after clockPeriod/2;
|
||||
clock <= sClock after clockPeriod/10;
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- control signals
|
||||
--
|
||||
amplitude <= to_unsigned( 64, amplitude'length),
|
||||
to_unsigned(128, amplitude'length) after 10*256*enPeriodNb*clockPeriod,
|
||||
to_unsigned(192, amplitude'length) after 20*256*enPeriodNb*clockPeriod;
|
||||
|
||||
sEn <= '1' after (enPeriodNb-1)*clockPeriod when sEn = '0' else '0' after clockPeriod;
|
||||
en <= sEn;
|
||||
|
||||
END test;
|
Reference in New Issue
Block a user