Skip to content

Commit deaab94

Browse files
authored
Merge pull request #146 from davidgiven/sixbit
Switch to a simplified encoding with a six-bit timer.
2 parents e6da85b + 1509e1f commit deaab94

31 files changed

+599
-993
lines changed

FluxEngine.cydsn/CortexM3/ARM_GCC_541/Release/FluxEngine.hex

Lines changed: 314 additions & 314 deletions
Large diffs are not rendered by default.

FluxEngine.cydsn/FluxEngine.cyprj

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@
3939
<build_action v="HEADER;;;;" />
4040
<PropertyDeltas />
4141
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
42-
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
43-
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="crunch.c" persistent="..\lib\common\crunch.c">
44-
<Hidden v="False" />
45-
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
46-
<build_action v="SOURCE_C;;;;" />
47-
<PropertyDeltas />
48-
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
49-
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
50-
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="crunch.h" persistent="..\lib\common\crunch.h">
51-
<Hidden v="False" />
52-
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
53-
<build_action v="HEADER;;;;" />
54-
<PropertyDeltas />
55-
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
5642
</dependencies>
5743
</CyGuid_0820c2e7-528d-4137-9a08-97257b946089>
5844
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>

FluxEngine.cydsn/Sampler/Sampler.v

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,90 +19,78 @@ module Sampler (
1919

2020
//`#start body` -- edit after this line, do not edit this line
2121

22-
localparam STATE_RESET = 0;
23-
localparam STATE_WAITING = 1;
24-
localparam STATE_OPCODE = 2;
22+
localparam STATE_WAITING = 0;
23+
localparam STATE_OPCODE = 1;
2524

26-
reg [1:0] state;
27-
reg [6:0] counter;
25+
reg [0:0] state;
26+
reg [5:0] counter;
2827

2928
reg oldsampleclock;
30-
wire sampleclocked;
31-
assign sampleclocked = !oldsampleclock && sampleclock;
32-
3329
reg oldindex;
34-
wire indexed;
35-
assign indexed = !oldindex && index;
36-
37-
wire rdataed;
3830
reg oldrdata;
39-
assign rdataed = !oldrdata && rdata;
31+
32+
reg sampleclocked;
33+
reg indexed;
34+
reg rdataed;
4035

4136
assign req = (state == STATE_OPCODE);
4237

4338
always @(posedge clock)
4439
begin
4540
if (reset)
4641
begin
47-
state <= STATE_RESET;
42+
state <= STATE_WAITING;
4843
opcode <= 0;
44+
sampleclocked <= 0;
45+
indexed <= 0;
46+
rdataed <= 0;
4947
oldsampleclock <= 0;
5048
oldindex <= 0;
5149
oldrdata <= 0;
5250
counter <= 0;
5351
end
5452
else
53+
begin
54+
/* Remember positive egdes for sampleclock, index and rdata. */
55+
56+
if (sampleclock && !oldsampleclock)
57+
sampleclocked <= 1;
58+
oldsampleclock <= sampleclock;
59+
60+
if (index && !oldindex)
61+
indexed <= 1;
62+
oldindex <= index;
63+
64+
if (rdata && !oldrdata)
65+
rdataed <= 1;
66+
oldrdata <= rdata;
67+
5568
case (state)
56-
STATE_RESET:
57-
state <= STATE_WAITING;
58-
5969
STATE_WAITING:
6070
begin
61-
/* If something has happened, emit any necessary interval byte. */
62-
if ((rdataed || indexed) && (counter != 0))
71+
if (sampleclocked)
6372
begin
64-
opcode <= {0, counter};
65-
state <= STATE_OPCODE;
66-
end
67-
else if (indexed)
68-
begin
69-
oldindex <= 1;
70-
opcode <= 8'h81;
71-
state <= STATE_OPCODE;
72-
end
73-
else if (rdataed)
74-
begin
75-
oldrdata <= 1;
76-
opcode <= 8'h80;
77-
state <= STATE_OPCODE;
78-
end
79-
else if (sampleclocked)
80-
begin
81-
oldsampleclock <= 1;
82-
if (counter == 7'h7f)
73+
if (rdataed || indexed || (counter == 6'h3f))
8374
begin
84-
opcode <= {0, counter};
75+
opcode <= {rdataed, indexed, counter};
76+
rdataed <= 0;
77+
indexed <= 0;
78+
counter <= 0;
8579
state <= STATE_OPCODE;
8680
end
87-
counter <= counter + 1;
81+
else
82+
counter <= counter + 1;
83+
84+
sampleclocked <= 0;
8885
end
89-
90-
/* Reset state once we've done the thing. */
91-
92-
if (oldrdata && !rdata)
93-
oldrdata <= 0;
94-
if (oldindex && !index)
95-
oldindex <= 0;
96-
if (oldsampleclock && !sampleclock)
97-
oldsampleclock <= 0;
9886
end
9987

100-
STATE_OPCODE: /* opcode or interval byte sent here */
88+
STATE_OPCODE: /* opcode sent here */
10189
begin
10290
state <= STATE_WAITING;
103-
counter <= 0;
10491
end
10592
endcase
93+
end
10694
end
10795

10896
//`#end` -- edit above this line, do not edit this line

FluxEngine.cydsn/Sequencer/Sequencer.v

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@ module Sequencer (
1919
//`#start body` -- edit after this line, do not edit this line
2020

2121
localparam STATE_LOAD = 0;
22-
localparam STATE_WAITING = 1;
23-
localparam STATE_PULSING = 2;
24-
localparam STATE_INDEXING = 3;
22+
localparam STATE_WRITING = 1;
2523

26-
localparam OPCODE_PULSE = 8'h80;
27-
localparam OPCODE_INDEX = 8'h81;
28-
29-
reg [1:0] state;
30-
reg [6:0] countdown;
24+
reg state;
25+
reg [5:0] countdown;
26+
reg pulsepending;
3127

3228
assign req = (!reset && (state == STATE_LOAD));
33-
assign wdata = (state == STATE_PULSING);
34-
assign debug_state = state;
29+
assign wdata = (!reset && (state == STATE_WRITING) && (countdown == 0) && pulsepending);
30+
assign debug_state = 0;
3531

3632
reg olddataclock;
3733
wire dataclocked;
@@ -52,49 +48,39 @@ begin
5248
begin
5349
state <= STATE_LOAD;
5450
countdown <= 0;
51+
pulsepending <= 0;
52+
oldsampleclock <= 0;
5553
end
5654
else
5755
begin
5856
if (!oldsampleclock && sampleclock)
5957
sampleclocked <= 1;
6058
oldsampleclock <= sampleclock;
61-
59+
6260
case (state)
6361
STATE_LOAD:
64-
/* Wait for a posedge on dataclocked, indicating an opcode has
62+
begin
63+
/* A posedge on dataclocked indicates that another opcode has
6564
* arrived. */
6665
if (dataclocked)
67-
case (opcode)
68-
OPCODE_PULSE:
69-
state <= STATE_PULSING;
70-
71-
OPCODE_INDEX:
72-
state <= STATE_INDEXING;
73-
74-
default:
75-
begin
76-
countdown <= opcode[6:0];
77-
state <= STATE_WAITING;
78-
end
79-
endcase
66+
begin
67+
pulsepending <= opcode[7];
68+
countdown <= opcode[5:0];
69+
state <= STATE_WRITING;
70+
end
71+
end
8072

81-
STATE_WAITING:
73+
STATE_WRITING:
74+
begin
8275
if (sampleclocked)
8376
begin
84-
sampleclocked <= 0;
85-
countdown <= countdown - 1;
86-
/* Nasty fudge factor here to account for one to two
87-
* sample ticks lost per pulse. */
88-
if (countdown <= 2)
77+
if (countdown == 0)
8978
state <= STATE_LOAD;
79+
else
80+
countdown <= countdown - 1;
81+
sampleclocked <= 0;
9082
end
91-
92-
STATE_PULSING:
93-
state <= STATE_LOAD;
94-
95-
STATE_INDEXING:
96-
if (indexed)
97-
state <= STATE_LOAD;
83+
end
9884
endcase
9985
end
10086
end

0 commit comments

Comments
 (0)