Picoblaze 2022
Picoblaze 2022
SERDAR DURAN
ITU Embedded System Design Laboratory
1 gstl.itu.edu.tr
Picoblaze Design Steps
I. Write your algorithm as an Assembly Code
II. Simulate your Assembly Code in Fidex IDE
III.Generate your instruction memory from Fidex IDE
IV. Combine your instruction memory and picoblaze design in Vivado
(implementation of the picoblaze in an FPGA)
V. Write a testbench file to make a simulation.
VI. Make your simulations in Xilinx Vivado
2 gstl.itu.edu.tr
Vivado and Fidex Environments
• Install one of the recent version of Xilinx Vivado:
https://www.xilinx.com/support/download.html
• Download the ‘‘PicoBlaze for UltraScale, 7-series, 6-series FPGAs’’ design files:
https://www.xilinx.com/products/intellectual-property/picoblaze.html#design
3 gstl.itu.edu.tr
Picoblaze Overview
4 gstl.itu.edu.tr
Picoblaze
• The PicoBlaze processor is a simple 8-bit microcontroller specifically designed and
optimized for Xilinx FPGA devices.
• Basic Features:
• 8-bit data width,
• 8-bit ALU with carry and zero flags,
• 16 8-bit general-purpose registers,
• 64-byte data memory (Scratchpad RAM, 64*8 bit),
• 8 input and 8 output pins,
• 8 bit port identifier, meaning 256 addressable input and output ports,
• 2 clock cycles per each instruction.
5 gstl.itu.edu.tr
6 gstl.itu.edu.tr
7 gstl.itu.edu.tr
Interfaces
• IN_PORT [7:0] : 8-bit data
• OUT_PORT [7:0] : 8-bit data
• PORT_ID [7:0] : port address for both
INPUT and OUTPUT pins
8 gstl.itu.edu.tr
Instruction Format
• Instruction Format:
• op sX,sY ; register-register format. sX = sX op sY
• op sX,KK ; register-constant format. sX = sX op KK
• op sX ; single-register format. sX = op sX
• op AAA ; single-address format (jump and call operations).
• Instruction Types:
• Arithmetic
• Logical
• Shift and Rotate
• Data Transfer
• Branch Instructions
9 gstl.itu.edu.tr
Instruction Set
• Arithmetic Instructions: ADD, ADDC, SUB, SUBC
• ADD sX, constant ; sX = sX + constant
• ADD sX, sY ; sX = sX + sY
10 gstl.itu.edu.tr
Instruction Set
• Comparison Instructions: COMP, COMPC, TEST, TESTC
• COMP sX, sY ; if regY > regX, then set CARRY, if regY = regX then set ZERO flag.
• COMP sX, const ; if regY > const, then set CARRY, if regY = regX then set ZERO flag.
• Shift and Rotate: SL0, SL1, SLA, SLX, SR0, SR1, SRA, SRX, RL, RR
• SL0 sX ; shift register sX left, zero fill
• SR1 sX ; shift register sX right, one fill
11 gstl.itu.edu.tr
Instruction Set
• Data Transfer Instructions: LOAD, FETCH, STORE, INPUT, OUTPUT
• LOAD sX, constant ; Load register sX with constant
• LOAD sX, sY ; Load register sX with sY
• WRMEM sX, scrpdAddr ; store regX into the memory at address scrpdAddr.
• WRMEM sX, ( sY ) ; store regX into the memory at address (sY).
• RDMEM sX, scrpdAddr ; fetch the value at address scrpdAddr into the sX.
• RDMEM sX, ( sY ) ; fetch the value at address (sY) into the sX.
12 gstl.itu.edu.tr
Fidex Part
13 gstl.itu.edu.tr
Default Specifications for Verilog
#ifDef proc::xPblze6
Picoblaze 6 Configs
; PICOBLAZE 6 CONFIGs
• Scratchpad RAM size
#set proc::xPblze6:: scrpdSize, 64 ; [64, 128, 256]
#set proc::xPblze6:: clkFreq, 100000000 ; in Hz
• Clock frequency
14 gstl.itu.edu.tr
Default Specifications for VHDL
#ifDef proc::xPblze6
; PICOBLAZE 6 CONFIGs
#set proc::xPblze6:: scrpdSize, 64 ; [64, 128, 256]
#set proc::xPblze6:: clkFreq, 100000000 ; in Hz
15 gstl.itu.edu.tr
Example - Fidex
Program Counter
LOAD s0, 0
LOAD s1, 1
Scratchpad RAM
16 gstl.itu.edu.tr
Instruction Set
Manual
help->content
17 gstl.itu.edu.tr
Generate the HDL output Reset Run all the
of instruction memory Simulation codes
18 gstl.itu.edu.tr
Coding Steps
1) Open or Create a new project
2) Make a configuration for your project
• Xilinx Picoblaze 6
• Scratchpad Size 64
• Interrupt vector address 1023
• Clock frequency 100 MHz
3) Write the default specifications (Verilog or VHDL)
4) Write your Assembly code
5) Run Assembler
6) Make a Simulation
7) Generate the HDL file if there is no problem with your code.
8) BRAM0.v or BRAM0.vhd will be your instruction memory file.
19 gstl.itu.edu.tr
Vivado Part
20 gstl.itu.edu.tr
Creating Project
• Create a new project in Vivado and use either Nexys4 DDR board or xc7a100tcsg324-1 chip. (they
are same)
• Please look at the online tutorial here!
21 gstl.itu.edu.tr
Creating Project
22 gstl.itu.edu.tr
Vivado Part
• Fidex IDE generates instruction memory according to your assembly code.
• Picoblaze projects are implemented by combining generated instruction memory and picoblaze
design file.
• You can write a top entity that combine BRAM0 (inst memory) and KCPSM6 (picoblaze) files.
BRAM0.vhd kcpsm6.vhd
top.vhd
23 gstl.itu.edu.tr
• Include the generated BRAM0.vhd, kcpsm6.vhd and top.vhd as Design Sources.
24 gstl.itu.edu.tr
25 gstl.itu.edu.tr
Vivado Part
• After adding Design Files you can see the hierarchy between these files.
• To see your design works as expected you need to write a testbench file and add
it as a Simulation Source File.
Picoblaze (kcpsm6.vhd)
26 gstl.itu.edu.tr
• Include the top_tb.vhd as a Simulation Source.
27 gstl.itu.edu.tr
28 gstl.itu.edu.tr
Vivado Part
• Hierarchy between these entities (files):
Picoblaze (kcpsm6.vhd)
29 gstl.itu.edu.tr
Vivado Part
• If the top_tb.vhd testbench is not seen as top entity (bald) ‘‘ right click->Set as Top’’ this
entity.
30 gstl.itu.edu.tr
• After adding the design files and top_tb.vhd simulation file you can make a simulation
for your design.
31 gstl.itu.edu.tr
• After running behavioral simulation you can see the waveform of the ports and signals of the
picoblaze.
32 gstl.itu.edu.tr
Advance the simulation(waveform)
for 1 us more Restart the Simulation
33 gstl.itu.edu.tr
• Values of registers, buses, ports, ram etc. can be found from the scope and objects section
• Drag these objects to the waveform and restart the simulation.
begin
uut: top
port map( clk => clk, in_port => in_port, port_id => port_id, out_port => out_port, write_strobe =>
write_strobe, read_strobe => read_strobe, interrupt => interrupt, interrupt_ack => interrupt_ack ); Port connections
process
begin
clk <= '0'; wait for 5ns;
clk <= '1'; wait for 5ns; Clock signal 10ns period
end process;
end Behavioral;
35 gstl.itu.edu.tr
`timescale 1ns / 1ps top_tb.v - Testbench File
module top_tb();
reg clk = 1'b0;
reg [7:0] in_port;
wire [7:0] port_id;
wire [7:0] out_port;
wire write_strobe;
wire read_strobe;
reg interrupt;
wire interrupt_ack;
Clock signal 10ns period
always #5 clk = ~clk;
top UUT(
.clk(clk),
.in_port(in_port),
.port_id(port_id),
.out_port(out_port), Port connections of the top file
.write_strobe(write_strobe),
.read_strobe(read_strobe),
.interrupt(interrupt),
.interrupt_ack(interrupt_ack)
);
endmodule
36 gstl.itu.edu.tr
Implementation of the Picoblaze in an FPGA
1) Create a new project in Vivado.
2) Take kcpsm6.vhd and BRAM0.vhd (generated from Fidex IDE) design files and
add them as design sources.
3) Take top.vhd file that provided for you or write a new one and add it as a
Design Source.
4) Take top_tb.vhd or top_tb.v file that provided for you or write a new one and
add it as a Simulation Source.
5) Run Behavioral Simulation and check the objects and waveform to see your
algorithm works properly.
37 gstl.itu.edu.tr
Vivado Block Design
38 gstl.itu.edu.tr
Vivado Block Design
• Any blocks (entities) can be included into a project alongside with the Picoblaze.
• You can add predefined IP Blocks in Vivado (like Block RAM).
• You can also add your own designed entities.
• An Example:
Com.
Block RAM #1 Picoblaze Interface #2 Picoblaze
(e.g. UART)
39 gstl.itu.edu.tr
Vivado Block Design
• Create a project and add BRAM0.vhd, kcpsm6.vhd and top.vhd files into this project as Design
Sources.
• Then click ‘‘Create Block Design’’ .
40 gstl.itu.edu.tr
• Drag top.vhd file into the Diagram window.
41 gstl.itu.edu.tr
42 gstl.itu.edu.tr
• To create the ports ‘’right click->make external’’
43 gstl.itu.edu.tr
• You can change the names of the ports.
44 gstl.itu.edu.tr
45 gstl.itu.edu.tr
Including a Block RAM
• Click IP Catalog
• Type Block Memory Generator
46 gstl.itu.edu.tr
• Add IP to Block Design
47 gstl.itu.edu.tr
• Double click to customize Block RAM
48 gstl.itu.edu.tr
• Change the default specifications:
49 gstl.itu.edu.tr
• We have 8-bit bus.
( Picoblaze is an 8-bit
microcontroller )
• 256 different locations
can be addressable.
(Port id is 8 bit)
50 gstl.itu.edu.tr
• After customizing Block RAM, make the following connections:
• port_id to addra
• out_port to dina
• in_port to douta
• Create ena and wea ports.
51 gstl.itu.edu.tr
• Right click on design_1 -> Create HDL Wrapper
52 gstl.itu.edu.tr
• A top entity called design_1_wrapper is generated by Vivado.
• design_1_wrapper combines the top (picoblaze + inst memory) and Block RAM.
53 gstl.itu.edu.tr
BRAM0.vhd kcpsm6.vhd
design_1_wrapper
Testbench
54 gstl.itu.edu.tr
• Write a testbench file and add it as a Simulation Source File.
`timescale 1ns / 1ps block_design_verilog_tb.v - Testbench File
module block_design_verilog_tb();
reg clk = 1'b0;
reg ena;
reg [0:0] wea;
reg interrupt;
wire interrupt_ack;
wire read_strobe;
wire write_strobe;
wire k_write_strobe;
Clock signal 10ns period
always #5 clk = ~clk;
design_1_wrapper UUT(
.clk(clk),
.ena(ena),
.wea(wea),
.interrupt(interrupt), Port connections of the
.interrupt_ack(interrupt_ack),
design_1_wrapper file
.read_strobe(read_strobe),
.write_strobe(write_strobe),
.k_write_strobe(k_write_strobe)
);
endmodule
55 gstl.itu.edu.tr
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; block_design_tb.vhd - Testbench File
entity block_design_tb is
end block_design_tb;
begin
uut: design_1_wrapper
port map( clk => clk, ena => ena, interrupt => interrupt, interrupt_ack => interrupt_ack,
k_write_strobe => k_write_strobe, read_strobe => read_strobe, wea => wea, write_strobe => write_strobe); Port connections
process
begin
clk <= '0'; wait for 5ns;
clk <= '1'; wait for 5ns; Clock signal 10ns period
end process;
end Behavioral;
56 gstl.itu.edu.tr
References
• Picoblaze user guide
57 gstl.itu.edu.tr