Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .qsys_edit/filters.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<filters version="19.1" />
12 changes: 12 additions & 0 deletions .qsys_edit/preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<preferences>
<debug showDebugMenu="0" />
<systemtable filter="All Interfaces">
<columns>
<connections preferredWidth="47" />
<irq preferredWidth="34" />
</columns>
</systemtable>
<library expandedCategories="Project,Library" />
<window width="1100" height="800" x="0" y="0" />
</preferences>
12 changes: 7 additions & 5 deletions PWMGenerator.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ ENTITY PWM_GEN IS
END PWM_GEN;

ARCHITECTURE a OF PWM_GEN IS
SIGNAL COUNT : STD_LOGIC_VECTOR(4 DOWNTO 0);
SIGNAL COMPARE : STD_LOGIC_VECTOR(4 DOWNTO 0);
SIGNAL COUNT : STD_LOGIC_VECTOR(6 DOWNTO 0);
SIGNAL COMPARE : STD_LOGIC_VECTOR(6 DOWNTO 0);

BEGIN

IO_Handler: PROCESS (RESETN, CS)

BEGIN
-- Create a register to store the data sent from SCOMP
IF (RESETN = '0') THEN
COMPARE <= "00000";
COMPARE <= "0000000";
ELSIF rising_edge(CS) THEN
-- When written to, latch IO_DATA into the compare register.
COMPARE <= IO_DATA(4 DOWNTO 0);
COMPARE <= IO_DATA(6 DOWNTO 0);
END IF;

END PROCESS;
Expand All @@ -55,7 +56,7 @@ ARCHITECTURE a OF PWM_GEN IS
END IF;

-- todo: on overflow, set the output high
IF (COUNT = "11111") THEN
IF (COUNT = "1111111") THEN
PWM_OUT <= '1';
END IF;

Expand All @@ -64,5 +65,6 @@ ARCHITECTURE a OF PWM_GEN IS

END IF;
END PROCESS;


END a;
33 changes: 15 additions & 18 deletions PositionControl.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,31 @@

ORG 0
Start:
LOAD VelControlOn
JPOS Velocity
LOAD PosControlOn
JPOS Position

Velocity:
; IN Switches
LOAD VelControl
OUT PWM

IN Quad
OUT Hex0

JUMP Velocity

Position:
IN Switches
; LOAD PosControlSpeed
OUT PWM


IN Quad
CALL Abs
OUT Hex0
SUB PosControl
JZERO End

; IN Switches
LOAD PosControlSpeed
OUT PWM

JUMP Position

End:
LOAD Zero
OUT PWM

; IN Quad
; CALL Abs
; OUT Hex1

JUMP End

Abs:
Expand All @@ -48,6 +42,7 @@ Abs_r:
; IO address constants
Switches: EQU &H000
Hex0: EQU &H004
Hex1: EQU &H005
PWM: EQU &H021
Quad: EQU &H0F1

Expand All @@ -57,6 +52,8 @@ NegOne: DW -1

VelControlOn: DW 0
PosControlOn: DW 1
PosControlSpeed: DW &B10000

VelControl: DW &B01111
PosControlSpeed: DW &B11001
PosControl: DW 540
PosControl: DW 1080
; DirControl: DW
47 changes: 47 additions & 0 deletions PositionControl.mif
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- Altera Memory Initialization File (MIF)

DEPTH = 2048;
WIDTH = 16;

ADDRESS_RADIX = HEX;
DATA_RADIX = HEX;

CONTENT
BEGIN
[000..7FF] : 0000; -- Default to NOP

000 : 081D; -- LOAD VelControlOn
001 : 3804; -- JPOS Velocity
002 : 081E; -- LOAD PosControlOn
003 : 3809; -- JPOS Position
004 : 0820; -- LOAD VelControl
005 : 9821; -- OUT PWM
006 : 90F1; -- IN Quad
007 : 9804; -- OUT Hex0
008 : 2804; -- JUMP Velocity
009 : 90F1; -- IN Quad
00A : 8017; -- CALL Abs
00B : 9804; -- OUT Hex0
00C : 2021; -- SUB PosControl
00D : 4011; -- JZERO End
00E : 081F; -- LOAD PosControlSpeed
00F : 9821; -- OUT PWM
010 : 2809; -- JUMP Position
011 : 081B; -- LOAD Zero
012 : 9821; -- OUT PWM
013 : 90F1; -- IN Quad
014 : 8017; -- CALL Abs
015 : 9805; -- OUT Hex1
016 : 2811; -- JUMP End
017 : 381A; -- JPOS Abs_r ; If already positive, return
018 : 581C; -- XOR NegOne ; Flip all bits
019 : 6801; -- ADDI 1 ; Add one
01A : 8800; -- RETURN
01B : 0000; -- Zero: DW 0
01C : FFFF; -- NegOne: DW -1
01D : 0000; -- VelControlOn: DW 0
01E : 0001; -- PosControlOn: DW 1
01F : 0010; -- PosControlSpeed: DW &B10000
020 : 000F; -- VelControl: DW &B01111
021 : 0438; -- PosControl: DW 1080
END;
1 change: 1 addition & 0 deletions SCOMP.qsf
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,5 @@ set_location_assignment PIN_AB8 -to STBY
set_location_assignment PIN_Y10 -to ENCODER_H1
set_location_assignment PIN_AB9 -to ENCODER_H2
set_global_assignment -name VHDL_FILE output_files/PositionControl.vhd
set_global_assignment -name VHDL_FILE VelocityControl.vhd
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
Binary file modified SCOMP.qws
Binary file not shown.
Loading