Skip to content

Instantly share code, notes, and snippets.

@cibomahto
Created November 30, 2018 06:33
Show Gist options
  • Save cibomahto/3f5a279609b4675a3a68f3f89cdcf288 to your computer and use it in GitHub Desktop.
Save cibomahto/3f5a279609b4675a3a68f3f89cdcf288 to your computer and use it in GitHub Desktop.
"Trammell Mode" RGB blink pattern for UPDuino v2.0
module chip (
output LED_R,
output LED_G,
output LED_B
);
wire clk, led_r, led_g, led_b;
SB_HFOSC u_hfosc (
.CLKHFPU(1'b1),
.CLKHFEN(1'b1),
.CLKHF(clk)
);
blink my_blink (
.clk(clk),
.rst(0),
.led_r(led_r),
.led_g(led_g),
.led_b(led_b)
);
assign LED_R = led_r;
assign LED_G = led_b;
assign LED_B = led_g;
endmodule
~
'''
module lut(count_out, angle);
input [2:0] count_out;
output [11:0] angle;
reg [11:0] angle;
always @(count_out)
case (count_out)
3'b000: angle=12'b001000000000; //0 45 45
3'b001: angle=12'b000100101110; //1 26.54 26.57
3'b010: angle=12'b000010100000; //2 14.06 14.036
3'b011: angle=12'b000001010001; //3 7.12 7.13
3'b100: angle=12'b000000101001; //4 3.604 3.576
3'b101: angle=12'b000000010100; //5 1.76 1.79
3'b110: angle=12'b000000001010; //6 0.88 0.9
3'b111: angle=12'b000000000101; //7 0.44 0.45
default: angle=12'b001000000000; //default 0
endcase
endmodule
'''
header = '''
module correction_lut(value, corrected);
input [7:0] value;
output [7:0] corrected;
reg [7:0] corrected;
always @(value)
case (value)
'''
footer = '''
endcase
endmodule
'''
out = open('correction_lut.v','w')
out.write(header)
for val in range(0,256):
out.write("%i: corrected=%i;\n" % (val,int(255*pow(val/255.0,1.8))))
out.write(footer)
chip.bin: chip.v blink.v upduino_v2.pcf
yosys -q -p "synth_ice40 -blif chip.blif" chip.v blink.v correction_lut.v
arachne-pnr -d 5k -P sg48 -p upduino_v2.pcf chip.blif -o chip.txt
icepack chip.txt chip.bin
.PHONY: flash
flash:
iceprog chip.bin
.PHONY: clean
clean:
$(RM) -f chip.blif chip.txt chip.ex chip.bin
t_io LED_R 41
set_io LED_G 40
set_io LED_B 39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment