MiniCPU簡易OS
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[MiniCPUとI2Cバスの接続]]
* 概要 [#zaba5b6a]
- OSはプログラムを動かすプログラムであり、プログラムと人...
- このOSは、miniCPUの起動と停止, miniCPUの実行速度の変更,...
-- fpga で、miniCPU と周辺機器の接続を変更したり、miniCPU...
-- 一般的なOSはプログラムの入れ替えを行うことができますが...
プログラムの入れ替えは、ISE上でram.v を書き換えて生成され...
- [[MiniCPUとI2Cバスの接続]]を拡張して実現します。[[MiniC...
-
動作モードを変更することにより、([[MiniCPUとI2Cバスの接続...
* 動作モード別機能 [#vc8cd336]
- 動作モードの変更は、5つのボタンの、右(東)を使って変更...
** I2Cバスの手動操作(動作モード0) [#w24316c6]
- [[I2Cデバイスを手で動かしてみる]]と同様のことを可能にし...
** miniCPUの独立実行(手動クロック供給)(動作モード1) [#t2...
- miniCPUのクロックを手で供給するときは、中央のボタンを押...
- miniCPUの run 信号は, 上(北)のボタンを押して供給します。
** miniCPUでI2Cバスを操作(手動クロック供給)(動作モード2) ...
- miniCPUでI2Cの slave device を動かしているとき、miniCPU...
- out[2]-out[5]を基板のJCコネクタの3-6に接続しています。
** miniCPU自動クロック供給のときのクロック分周値設定(動作...
- Nexys4ボードのクロックは 100MHz です。ボードのクロック...
** miniCPUの独立実行(自動クロック供給)(動作モード4) [#q9a...
- クロック分周によって分周されたクロックをminiCPUに供給し...
- I2Cとは切り離します。
** miniCPUでI2Cバスを操作(自動クロック供給)(動作モード5) ...
- クロック分周によって分周されたクロックをminiCPUに供給し...
- cpuStartStopSequence 回路により, 中央ボタン(BCx)を押す...
- miniCPUでI2Cの slave device を動かしているとき、miniCPU...
- out[2]-out[5]を基板のJCコネクタの3-6に接続しています。
* 回路の概要 [#oe8fa2dd]
- miniCPU を構成する部品は、[[MiniCPU]]のものをそのまま使...
- 「[[I2Cデバイスを手で動かしてみる]]」の回路を拡張して、...
- sw[15:0]と up button, left button, center button, right...
- sclx が1のときは、sclはZ(high impedance), sclxが0のとき...
- sdax が1のときは、sdaはZ(high impedance), sclxが0のとき...
- 動作モードを表すレジスタ, operationMode を使います。ope...
-- 動作モードをカラーLED 1で表示します。
-- 動作モード 0 のときは、miniCPUのクロック(cpuCLK)や run...
-- 動作モード 1 のときは、BCxを miniCPUのクロックに接続し...
-- 動作モード 2 のときは, BCxを miniCPUのクロックに接続し...
- 動作モードの表 &br;
|operationMode |機能|Color LED 1|cpuClk|cpuRun|cpuIn|sSeg...
|0|I2Cバスの手動操作| {0,0,0} |BCx | 0 | 0| {16{0}, data,...
|1|miniCPUの独立実行(手動クロック供給)|{0,0,1}|BCx|BNx|sw...
|2|miniCPUでI2Cバスを操作(手動クロック供給)|{0,1,0}|BCx|B...
|3|miniCPU自動クロック供給のときのクロック分周値設定 |{0,...
|4|miniCPUの独立実行(自動クロック供給)|{1,0,0}|dclk|ssRun...
|5|miniCPUでI2Cバスを操作(自動クロック供給)|{1,0,1}|dclk|...
- down button をリセット信号とします。
- sda を led[8] に接続します。scl が 0->1 に変化するたび...
- 1つのポートで入出力を行う為、scl, sda は verilog の in...
** Verilog [#y617cf4a]
- top.v
module top(sSegAnode, sSegCathode, sw, ledOut, colorLed_...
bu, bd, bl, br, bc, scl, sda, jc,
bclck
);
output [7:0] sSegAnode;
output [7:0] sSegCathode;
output [15:0] ledOut; // led[8] ... i...
// i...
// led[0] corresponding to sw[0]
// led[1] corresponding to sw[1]
// led[2] corresponsing to center button,...
output [2:0] colorLed_1;
output [2:0] colorLed_2; // color LED
output [3:0] jc;
input [15:0] sw; // sw[15:8] ... fo...
// sw[0] ... if...
// sw[1] ... if 1 sda is receiving(1), ...
// sw[2] ... sending sda.
input bu, bd, bl, br, bc, bclck; // bd correspondi...
// bc correspondi...
// if posedge bl is detected, sw is shown...
inout scl, sda;
reg sclx, sdax;
reg [3:0] jcx;
assign scl=(~sclx)?1'b0:1'bz;
assign sda=(~sdax)?1'b0:1'bz;
assign jc=jcx;
wire BNx, BWx, BEx, BCx;
// reset: BSx
// BWx, BEx ... change operationMode
//
wire [15:0] swx;
wire reset;
// reg sclRw, sdaRw; // write=1, read=0;
wire cpuClk;
wire cpuRun;
reg [7:0] data;
reg [2:0] operationMode;
// operationMode: 0 ... manual operation of peripherals
// 1 ... CPU independent
// 2 ... CPU, I2C connected
reg [15:0] ledWire,cpuIn;
wire [2:0] cpuCs;
wire [11:0] pcout,abus;
wire [15:0] irout,qtop,dbus,out;
reg [31:0] sSegArray;
reg [15:0] led;
wire start;
wire haltIn;
wire halt;
wire [15:0] sSegBufL;
wire [15:0] sSegBufH;
reg [4:0] divide;
wire dclk;
initial begin
divide={01101};
end
assign ledOut=led;
reg [2:0] colorLed_1x;
wire [2:0] colorLed_2x;
//
assign colorLed_1=colorLed_1x;
assign colorLed_2=colorLed_2x;
assign reset=~bd;
always @(posedge sclx, negedge reset) begin
if(!reset) begin
data<=0;
end
else
data<={data[6:0],sda};
end
// for operation mode
always @(posedge BEx or negedge reset ) begin
if(!reset) begin
operationMode<=3'b000;
end
else
case (operationMode)
3'b000: operationMode<=3'b001;
3'b001: operationMode<=3'b010;
3'b010: operationMode<=3'b011;
3'b011: operationMode<=3'b100;
3'b100: operationMode<=3'b101;
3'b101: operationMode<=3'b110;
3'b110: operationMode<=3'b000;
default
operationMode<=3'b000;
endcase
end
/*
always @(posedge BWx or negedge reset ) begin
if(!reset) begin
operationMode<=0;
end
else
case (operationMode)
3'b000: operationMode<=3'b110;
3'b001: operationMode<=3'b000;
3'b010: operationMode<=3'b001;
3'b011: operationMode<=3'b010;
3'b100: operationMode<=3'b011;
3'b101: operationMode<=3'b100;
3'b110: operationMode<=3'b101;
default
operationMode<=3'b000;
endcase
end
*/
/* */
// assign setDivide=(operationMode==3'b011)?BCx:1'b0;
always @(posedge BCx ) begin
if(operationMode==3'b011) begin
divide<=swx[15:11];
end
end
assign colorLed_2x={dclk,scl,sda};
assign start=(operationMode==3'b100|operationMode==3'b...
assign cpuClk=(operationMode==3'b100|operationMode==3'...
assign cpuRun=(operationMode==3'b100|operationMode==3'...
assign haltIn=(operationMode==3'b100|operationMode==3'...
assign sSegBufL=BWx?irout:out;
assign sSegBufH=BWx?{{0},cpuCs,abus}:pcout;
// always @(operationMode or swx[0] or BCx or data or B...
// always @(posedge BEx or posedge BWx or negedge reset...
always @(operationMode) begin
case(operationMode)
3'b000: begin // direc...
colorLed_1x=3'b000;
cpuIn=0;
sSegArray={{16{0}},data,swx[7:0]};
led[15:8]=data;
led[7:0]=swx[7:0];
sclx=BCx;
sdax=swx[0];
jcx=swx[5:2];
end
3'b001: begin // mini CPU, with manual clock only ... ...
colorLed_1x=3'b001; // blue
cpuIn=swx;
sSegArray={sSegBufH,sSegBufL};
led=out;
sclx=1'b1;
sdax=1'b1;
jcx={0,0,0,0};
end
3'b010: begin // mini CPU, with manual clock, with i2c...
colorLed_1x=3'b010; //green
cpuIn={swx[15:8],data};
sSegArray={sSegBufH, sSegBufL};
led[15:8]=data;
led[7:0]=out[7:0];
sclx=out[1];
sdax=out[0];
jcx=out[5:2];
end
3'b011: begin // set clock divider for mini CPU with a...
colorLed_1x=3'b011; // cyan .. aqua
cpuIn=0;
sSegArray={divide,{13{0}},data,swx[7:0]};
led[15:8]=divide;
led[7:0]=swx[7:0];
sclx=1;
sdax=1;
jcx={0,0,0,0};
end
3'b100: begin // mini CPU, only, with automatic clock,
colorLed_1x=3'b100; // red
cpuIn=swx;
sSegArray={sSegBufH, sSegBufL};
led=out;
sclx=1'b1;
sdax=1'b1;
jcx={0,0,0,0};
end
3'b101: begin // mini CPU, with automatic clock, with ...
colorLed_1x=3'b101; // purple
cpuIn={swx[15:8],data};
sSegArray={sSegBufH, sSegBufL};
led[15:8]=data;
led[7:0]=out[7:0];
sclx=out[1];
sdax=out[0];
jcx=out[5:2];
end
default begin
colorLed_1x=3'b000;
cpuIn=swx;
sSegArray={{0{16}},data,swx[7:0]};
led[15:8]=data;
led[7:0]=swx[7:0];
sclx=BCx;
sdax=swx[0];
jcx=swx[5:2];
end
endcase
end
chattering #(20) chattering0(.clk(bclck), .reset(reset...
/* for test bench
assign BNx=bu;
assign BWx=bl;
assign BEx=br;
assign BCx=bc;
assign swx=sw;
*/
sSegArray sSegArray0(.clk(bclck), .reset(reset), .load...
minicpu minicpu0(.clk(cpuClk), .reset(reset), .run(cpu...
.irout(irout), .qtop(qtop), .abus(abus), .dbus...
clockDivider clockDivider0(.clk(bclck),.reset(reset), ...
cpuStartStopSequence cpuStartStopSequence0(.clk(dclk),...
endmodule
- top.xdc (nexys4の基板上の温度計を使う場合で vivado を使...
-- [[top-xdc-for-minicpu-os-i2c-jc]]
- top.ucf (nexys4の基板上の温度計を使う場合で ISEを使う場...
-- [[top-ucf-for-minicpu-os-i2c-jc]]
- chattering.v
module chattering(clk, reset, in, out
);
parameter N=1;
input clk, reset;
input [N-1:0]in;
output [N-1:0]out;
reg [N-1:0]out;
reg [21:0] count;
always @(posedge clk or negedge reset)
if(!reset) count <=0;
else count <= count +1;
always @(posedge clk)
if(count==0) out <= in;
endmodule
- sSegArray.v
module sSegArray(
clk,reset,load,d,
anode, cathode
);
parameter N=32;
input clk,reset,load;
input [N-1:0] d;
output [7:0] anode;
output [7:0] cathode;
reg [7:0] anode;
reg [7:0] cathode;
reg [31:0] q;
wire [2:0] selectedSeg;
wire [7:0] wOneSeg;
reg segClk;
counter #(8) waitOneSeg(.clk(clk), .reset(reset), .load(...
//assign segClk= (wOneSeg==0)? ~segClk: segClk;
always @(posedge clk, negedge reset) begin
if(!reset) segClk<=0;
else
if (wOneSeg==0) segClk<=~segClk;
end
counter #(3) selector(.clk(segClk),.reset(reset),.load(1...
//counter #(3) selector(.clk(clk), .reset(reset), .load(...
always @(posedge clk, negedge reset)
begin
if(!reset) anode=8'hFE; // note! anode is connected...
else // in order to active one 7s...
case (selectedSeg)
3'b000: anode=8'hFE;
3'b001: anode=8'hFD;
3'b010: anode=8'hFB;
3'b011: anode=8'hF7;
3'b100: anode=8'hEF;
3'b101: anode=8'hDF;
3'b110: anode=8'hBF;
3'b111: anode=8'h7F;
endcase
end
reg [3:0] selectedVal;
always @(posedge clk, negedge reset)
begin
if(!reset) cathode=8'h03; // note! w...
else // and it...
case (selectedVal) // ...
4'b0000: cathode=8'h03; //8'hfc; 0 --...
4'b0001: cathode=8'h9f; //8'h60; 1 / ...
4'b0010: cathode=8'h25; //8'hda; 2 /c...
4'b0011: cathode=8'h0d; //8'hf2; 3 / ...
4'b0100: cathode=8'h99; //8'h66; 4 -----
4'b0101: cathode=8'h49; //8'hb6; 5 / c...
4'b0110: cathode=8'h41; //8'hbe; 6 /ce ...
4'b0111: cathode=8'h1f; //8'he0; 7 / ...
4'b1000: cathode=8'h01; //8'hfe; 8 ---...
4'b1001: cathode=8'h09; //8'hf6; 9 cd
4'b1010: cathode=8'h11; //8'hee; A
4'b1011: cathode=8'hc1; //8'h3e; B
4'b1100: cathode=8'h63; //8'h9c; C
4'b1101: cathode=8'h85; //8'h7c; D
4'b1110: cathode=8'h61; //8'h9e; E
4'b1111: cathode=8'h71; //8'h8e; F
endcase
end
always @(posedge clk, negedge reset)
begin
if(!reset) selectedVal=q[3:0];
else
case (selectedSeg)
3'b000: selectedVal=q[3:0];
3'b001: selectedVal=q[7:4];
3'b010: selectedVal=q[11:8];
3'b011: selectedVal=q[15:12];
3'b100: selectedVal=q[19:16];
3'b101: selectedVal=q[23:20];
3'b110: selectedVal=q[27:24];
3'b111: selectedVal=q[31:28];
endcase
end
always @(posedge clk, negedge reset)
begin
if(!reset) q=0;
else
if(load) q=d;
end
endmodule
- clockDivider.v
module clockDivider(clk, reset, div, dclk);
input clk, reset;
input [4:0] div;
output dclk;
reg dclk;
reg [31:0] q;
always @(posedge clk or negedge reset) begin
if(!reset)
q <=0;
else q<=q+1;
end
always @(posedge clk) begin
dclk<=q[div];
end
endmodule
- cpuStartStopSequence.v
module cpuStartStopSequence(clk, reset, start, run, halt
);
input clk, reset, start;
reg [3:0] cs;
output run;
reg run;
output halt;
reg halt;
always @(posedge clk or negedge reset)
if(!reset) begin
cs<= 4'b0000;
run<=1'b0;
halt<=1'b0;
end
else
case(cs)
4'b0000: if(start) begin
cs <= 4'b0001;
end
4'b0001: if(!start) begin
cs <= 4'b0010;
run <= 1;
end
4'b0010: cs <= 4'b0011;
4'b0011: begin
cs <= 4'b0100;
run <=0;
end
4'b0100: if(start ) begin
cs <= 4'b0101;
end
4'b0101: begin
cs <= 4'b0110;
halt <=1'b1;
end
4'b0110: cs <= 4'b0111;
4'b0111: cs <= 4'b1000;
4'b1000: cs <= 4'b1001;
4'b1001: begin
cs <= 4'b0000;
halt <=1'b0;
end
default: cs <= 3'bxxx;
endcase
endmodule
- defs.v, minicpu.v, state.v, stack.v, alu.v, counter.v ...
- 最初の ram.v の例として、[[I2C温度計その3]]を使って見...
----
#counter
終了行:
[[MiniCPUとI2Cバスの接続]]
* 概要 [#zaba5b6a]
- OSはプログラムを動かすプログラムであり、プログラムと人...
- このOSは、miniCPUの起動と停止, miniCPUの実行速度の変更,...
-- fpga で、miniCPU と周辺機器の接続を変更したり、miniCPU...
-- 一般的なOSはプログラムの入れ替えを行うことができますが...
プログラムの入れ替えは、ISE上でram.v を書き換えて生成され...
- [[MiniCPUとI2Cバスの接続]]を拡張して実現します。[[MiniC...
-
動作モードを変更することにより、([[MiniCPUとI2Cバスの接続...
* 動作モード別機能 [#vc8cd336]
- 動作モードの変更は、5つのボタンの、右(東)を使って変更...
** I2Cバスの手動操作(動作モード0) [#w24316c6]
- [[I2Cデバイスを手で動かしてみる]]と同様のことを可能にし...
** miniCPUの独立実行(手動クロック供給)(動作モード1) [#t2...
- miniCPUのクロックを手で供給するときは、中央のボタンを押...
- miniCPUの run 信号は, 上(北)のボタンを押して供給します。
** miniCPUでI2Cバスを操作(手動クロック供給)(動作モード2) ...
- miniCPUでI2Cの slave device を動かしているとき、miniCPU...
- out[2]-out[5]を基板のJCコネクタの3-6に接続しています。
** miniCPU自動クロック供給のときのクロック分周値設定(動作...
- Nexys4ボードのクロックは 100MHz です。ボードのクロック...
** miniCPUの独立実行(自動クロック供給)(動作モード4) [#q9a...
- クロック分周によって分周されたクロックをminiCPUに供給し...
- I2Cとは切り離します。
** miniCPUでI2Cバスを操作(自動クロック供給)(動作モード5) ...
- クロック分周によって分周されたクロックをminiCPUに供給し...
- cpuStartStopSequence 回路により, 中央ボタン(BCx)を押す...
- miniCPUでI2Cの slave device を動かしているとき、miniCPU...
- out[2]-out[5]を基板のJCコネクタの3-6に接続しています。
* 回路の概要 [#oe8fa2dd]
- miniCPU を構成する部品は、[[MiniCPU]]のものをそのまま使...
- 「[[I2Cデバイスを手で動かしてみる]]」の回路を拡張して、...
- sw[15:0]と up button, left button, center button, right...
- sclx が1のときは、sclはZ(high impedance), sclxが0のとき...
- sdax が1のときは、sdaはZ(high impedance), sclxが0のとき...
- 動作モードを表すレジスタ, operationMode を使います。ope...
-- 動作モードをカラーLED 1で表示します。
-- 動作モード 0 のときは、miniCPUのクロック(cpuCLK)や run...
-- 動作モード 1 のときは、BCxを miniCPUのクロックに接続し...
-- 動作モード 2 のときは, BCxを miniCPUのクロックに接続し...
- 動作モードの表 &br;
|operationMode |機能|Color LED 1|cpuClk|cpuRun|cpuIn|sSeg...
|0|I2Cバスの手動操作| {0,0,0} |BCx | 0 | 0| {16{0}, data,...
|1|miniCPUの独立実行(手動クロック供給)|{0,0,1}|BCx|BNx|sw...
|2|miniCPUでI2Cバスを操作(手動クロック供給)|{0,1,0}|BCx|B...
|3|miniCPU自動クロック供給のときのクロック分周値設定 |{0,...
|4|miniCPUの独立実行(自動クロック供給)|{1,0,0}|dclk|ssRun...
|5|miniCPUでI2Cバスを操作(自動クロック供給)|{1,0,1}|dclk|...
- down button をリセット信号とします。
- sda を led[8] に接続します。scl が 0->1 に変化するたび...
- 1つのポートで入出力を行う為、scl, sda は verilog の in...
** Verilog [#y617cf4a]
- top.v
module top(sSegAnode, sSegCathode, sw, ledOut, colorLed_...
bu, bd, bl, br, bc, scl, sda, jc,
bclck
);
output [7:0] sSegAnode;
output [7:0] sSegCathode;
output [15:0] ledOut; // led[8] ... i...
// i...
// led[0] corresponding to sw[0]
// led[1] corresponding to sw[1]
// led[2] corresponsing to center button,...
output [2:0] colorLed_1;
output [2:0] colorLed_2; // color LED
output [3:0] jc;
input [15:0] sw; // sw[15:8] ... fo...
// sw[0] ... if...
// sw[1] ... if 1 sda is receiving(1), ...
// sw[2] ... sending sda.
input bu, bd, bl, br, bc, bclck; // bd correspondi...
// bc correspondi...
// if posedge bl is detected, sw is shown...
inout scl, sda;
reg sclx, sdax;
reg [3:0] jcx;
assign scl=(~sclx)?1'b0:1'bz;
assign sda=(~sdax)?1'b0:1'bz;
assign jc=jcx;
wire BNx, BWx, BEx, BCx;
// reset: BSx
// BWx, BEx ... change operationMode
//
wire [15:0] swx;
wire reset;
// reg sclRw, sdaRw; // write=1, read=0;
wire cpuClk;
wire cpuRun;
reg [7:0] data;
reg [2:0] operationMode;
// operationMode: 0 ... manual operation of peripherals
// 1 ... CPU independent
// 2 ... CPU, I2C connected
reg [15:0] ledWire,cpuIn;
wire [2:0] cpuCs;
wire [11:0] pcout,abus;
wire [15:0] irout,qtop,dbus,out;
reg [31:0] sSegArray;
reg [15:0] led;
wire start;
wire haltIn;
wire halt;
wire [15:0] sSegBufL;
wire [15:0] sSegBufH;
reg [4:0] divide;
wire dclk;
initial begin
divide={01101};
end
assign ledOut=led;
reg [2:0] colorLed_1x;
wire [2:0] colorLed_2x;
//
assign colorLed_1=colorLed_1x;
assign colorLed_2=colorLed_2x;
assign reset=~bd;
always @(posedge sclx, negedge reset) begin
if(!reset) begin
data<=0;
end
else
data<={data[6:0],sda};
end
// for operation mode
always @(posedge BEx or negedge reset ) begin
if(!reset) begin
operationMode<=3'b000;
end
else
case (operationMode)
3'b000: operationMode<=3'b001;
3'b001: operationMode<=3'b010;
3'b010: operationMode<=3'b011;
3'b011: operationMode<=3'b100;
3'b100: operationMode<=3'b101;
3'b101: operationMode<=3'b110;
3'b110: operationMode<=3'b000;
default
operationMode<=3'b000;
endcase
end
/*
always @(posedge BWx or negedge reset ) begin
if(!reset) begin
operationMode<=0;
end
else
case (operationMode)
3'b000: operationMode<=3'b110;
3'b001: operationMode<=3'b000;
3'b010: operationMode<=3'b001;
3'b011: operationMode<=3'b010;
3'b100: operationMode<=3'b011;
3'b101: operationMode<=3'b100;
3'b110: operationMode<=3'b101;
default
operationMode<=3'b000;
endcase
end
*/
/* */
// assign setDivide=(operationMode==3'b011)?BCx:1'b0;
always @(posedge BCx ) begin
if(operationMode==3'b011) begin
divide<=swx[15:11];
end
end
assign colorLed_2x={dclk,scl,sda};
assign start=(operationMode==3'b100|operationMode==3'b...
assign cpuClk=(operationMode==3'b100|operationMode==3'...
assign cpuRun=(operationMode==3'b100|operationMode==3'...
assign haltIn=(operationMode==3'b100|operationMode==3'...
assign sSegBufL=BWx?irout:out;
assign sSegBufH=BWx?{{0},cpuCs,abus}:pcout;
// always @(operationMode or swx[0] or BCx or data or B...
// always @(posedge BEx or posedge BWx or negedge reset...
always @(operationMode) begin
case(operationMode)
3'b000: begin // direc...
colorLed_1x=3'b000;
cpuIn=0;
sSegArray={{16{0}},data,swx[7:0]};
led[15:8]=data;
led[7:0]=swx[7:0];
sclx=BCx;
sdax=swx[0];
jcx=swx[5:2];
end
3'b001: begin // mini CPU, with manual clock only ... ...
colorLed_1x=3'b001; // blue
cpuIn=swx;
sSegArray={sSegBufH,sSegBufL};
led=out;
sclx=1'b1;
sdax=1'b1;
jcx={0,0,0,0};
end
3'b010: begin // mini CPU, with manual clock, with i2c...
colorLed_1x=3'b010; //green
cpuIn={swx[15:8],data};
sSegArray={sSegBufH, sSegBufL};
led[15:8]=data;
led[7:0]=out[7:0];
sclx=out[1];
sdax=out[0];
jcx=out[5:2];
end
3'b011: begin // set clock divider for mini CPU with a...
colorLed_1x=3'b011; // cyan .. aqua
cpuIn=0;
sSegArray={divide,{13{0}},data,swx[7:0]};
led[15:8]=divide;
led[7:0]=swx[7:0];
sclx=1;
sdax=1;
jcx={0,0,0,0};
end
3'b100: begin // mini CPU, only, with automatic clock,
colorLed_1x=3'b100; // red
cpuIn=swx;
sSegArray={sSegBufH, sSegBufL};
led=out;
sclx=1'b1;
sdax=1'b1;
jcx={0,0,0,0};
end
3'b101: begin // mini CPU, with automatic clock, with ...
colorLed_1x=3'b101; // purple
cpuIn={swx[15:8],data};
sSegArray={sSegBufH, sSegBufL};
led[15:8]=data;
led[7:0]=out[7:0];
sclx=out[1];
sdax=out[0];
jcx=out[5:2];
end
default begin
colorLed_1x=3'b000;
cpuIn=swx;
sSegArray={{0{16}},data,swx[7:0]};
led[15:8]=data;
led[7:0]=swx[7:0];
sclx=BCx;
sdax=swx[0];
jcx=swx[5:2];
end
endcase
end
chattering #(20) chattering0(.clk(bclck), .reset(reset...
/* for test bench
assign BNx=bu;
assign BWx=bl;
assign BEx=br;
assign BCx=bc;
assign swx=sw;
*/
sSegArray sSegArray0(.clk(bclck), .reset(reset), .load...
minicpu minicpu0(.clk(cpuClk), .reset(reset), .run(cpu...
.irout(irout), .qtop(qtop), .abus(abus), .dbus...
clockDivider clockDivider0(.clk(bclck),.reset(reset), ...
cpuStartStopSequence cpuStartStopSequence0(.clk(dclk),...
endmodule
- top.xdc (nexys4の基板上の温度計を使う場合で vivado を使...
-- [[top-xdc-for-minicpu-os-i2c-jc]]
- top.ucf (nexys4の基板上の温度計を使う場合で ISEを使う場...
-- [[top-ucf-for-minicpu-os-i2c-jc]]
- chattering.v
module chattering(clk, reset, in, out
);
parameter N=1;
input clk, reset;
input [N-1:0]in;
output [N-1:0]out;
reg [N-1:0]out;
reg [21:0] count;
always @(posedge clk or negedge reset)
if(!reset) count <=0;
else count <= count +1;
always @(posedge clk)
if(count==0) out <= in;
endmodule
- sSegArray.v
module sSegArray(
clk,reset,load,d,
anode, cathode
);
parameter N=32;
input clk,reset,load;
input [N-1:0] d;
output [7:0] anode;
output [7:0] cathode;
reg [7:0] anode;
reg [7:0] cathode;
reg [31:0] q;
wire [2:0] selectedSeg;
wire [7:0] wOneSeg;
reg segClk;
counter #(8) waitOneSeg(.clk(clk), .reset(reset), .load(...
//assign segClk= (wOneSeg==0)? ~segClk: segClk;
always @(posedge clk, negedge reset) begin
if(!reset) segClk<=0;
else
if (wOneSeg==0) segClk<=~segClk;
end
counter #(3) selector(.clk(segClk),.reset(reset),.load(1...
//counter #(3) selector(.clk(clk), .reset(reset), .load(...
always @(posedge clk, negedge reset)
begin
if(!reset) anode=8'hFE; // note! anode is connected...
else // in order to active one 7s...
case (selectedSeg)
3'b000: anode=8'hFE;
3'b001: anode=8'hFD;
3'b010: anode=8'hFB;
3'b011: anode=8'hF7;
3'b100: anode=8'hEF;
3'b101: anode=8'hDF;
3'b110: anode=8'hBF;
3'b111: anode=8'h7F;
endcase
end
reg [3:0] selectedVal;
always @(posedge clk, negedge reset)
begin
if(!reset) cathode=8'h03; // note! w...
else // and it...
case (selectedVal) // ...
4'b0000: cathode=8'h03; //8'hfc; 0 --...
4'b0001: cathode=8'h9f; //8'h60; 1 / ...
4'b0010: cathode=8'h25; //8'hda; 2 /c...
4'b0011: cathode=8'h0d; //8'hf2; 3 / ...
4'b0100: cathode=8'h99; //8'h66; 4 -----
4'b0101: cathode=8'h49; //8'hb6; 5 / c...
4'b0110: cathode=8'h41; //8'hbe; 6 /ce ...
4'b0111: cathode=8'h1f; //8'he0; 7 / ...
4'b1000: cathode=8'h01; //8'hfe; 8 ---...
4'b1001: cathode=8'h09; //8'hf6; 9 cd
4'b1010: cathode=8'h11; //8'hee; A
4'b1011: cathode=8'hc1; //8'h3e; B
4'b1100: cathode=8'h63; //8'h9c; C
4'b1101: cathode=8'h85; //8'h7c; D
4'b1110: cathode=8'h61; //8'h9e; E
4'b1111: cathode=8'h71; //8'h8e; F
endcase
end
always @(posedge clk, negedge reset)
begin
if(!reset) selectedVal=q[3:0];
else
case (selectedSeg)
3'b000: selectedVal=q[3:0];
3'b001: selectedVal=q[7:4];
3'b010: selectedVal=q[11:8];
3'b011: selectedVal=q[15:12];
3'b100: selectedVal=q[19:16];
3'b101: selectedVal=q[23:20];
3'b110: selectedVal=q[27:24];
3'b111: selectedVal=q[31:28];
endcase
end
always @(posedge clk, negedge reset)
begin
if(!reset) q=0;
else
if(load) q=d;
end
endmodule
- clockDivider.v
module clockDivider(clk, reset, div, dclk);
input clk, reset;
input [4:0] div;
output dclk;
reg dclk;
reg [31:0] q;
always @(posedge clk or negedge reset) begin
if(!reset)
q <=0;
else q<=q+1;
end
always @(posedge clk) begin
dclk<=q[div];
end
endmodule
- cpuStartStopSequence.v
module cpuStartStopSequence(clk, reset, start, run, halt
);
input clk, reset, start;
reg [3:0] cs;
output run;
reg run;
output halt;
reg halt;
always @(posedge clk or negedge reset)
if(!reset) begin
cs<= 4'b0000;
run<=1'b0;
halt<=1'b0;
end
else
case(cs)
4'b0000: if(start) begin
cs <= 4'b0001;
end
4'b0001: if(!start) begin
cs <= 4'b0010;
run <= 1;
end
4'b0010: cs <= 4'b0011;
4'b0011: begin
cs <= 4'b0100;
run <=0;
end
4'b0100: if(start ) begin
cs <= 4'b0101;
end
4'b0101: begin
cs <= 4'b0110;
halt <=1'b1;
end
4'b0110: cs <= 4'b0111;
4'b0111: cs <= 4'b1000;
4'b1000: cs <= 4'b1001;
4'b1001: begin
cs <= 4'b0000;
halt <=1'b0;
end
default: cs <= 3'bxxx;
endcase
endmodule
- defs.v, minicpu.v, state.v, stack.v, alu.v, counter.v ...
- 最初の ram.v の例として、[[I2C温度計その3]]を使って見...
----
#counter
ページ名: