Xilinx Home
PicoBlaze
Register  ·  Sign In  ·  Help
Jump to Page:   1
  Reply   Reply  

More basic than "hello world", this bare bones intro project blinks a single LED.
Options    Options  
greglondon
Visitor
Posts: 20
Registered: 11-05-2009


greglondon

Message 1 of 3

Viewed 156 times


Here is a bare bones project using the picoblaze. It toggles an LED. It uses a clock in, a reset in (which is optional), and an LED output. Just about every evalutation board has at least a clock and one LED, many have an external pushbutton that can be used as reset.

 

This is a good project for getting the kinks out of your environment, making sure everything is configured properly, confirm that your running the assembler correctly, and confirm that all your hardware is working. It's bare bones enough that you don't need any fancy test equipment, and just about any eval board should be able to run this configuration without adding external hardware or jumpers or whatever. And the LED blinks slowly enough that you don't need an oscilliscope to see the waveform. 

 

The assembly code is a simple counter to toggle the LED at a slow enough rate that you can see it with the naked eye. With a 16 Mhz clock, the LED will turn ON about two times a second. if you have a faster clock, you may want to increase the initial value of S2 from 0F to FF.

 

If you have a user-controlled input signal, you can use that as "reset". In this design, reset (active high) will put the picoblaze in reset, but the LED will hold whatever value it last held. If it looks like your LED is always on, it may simply be toggling too fast for your eyes to see it. One way to check is to assert reset a number of times manually. While you push the reset button, the LED should stick to it's last value, on or off. It should be like a coin toss, about half and half. If you hit reset a bunch of times but the LED always stays on, then something isn't working. If you hit reset a bunch of times and the LED is a coin toss between on and off, then increase your S2 initial value or decrease your clock frequency.

 

If you don't have a reset signal that you can control, just tie the signal to zero. 

 

 

 

module picoblaze_toggle(    input FPGA_RESET,    input CLK_16MHZ,    output LED1    );        wire clock = CLK_16MHZ;        // reset is active high.        // if no reset signal input        // then tie reset to zero here.        wire reset = FPGA_RESET;         wire [7:0]         port_id;        wire                         write_strobe;        wire                         read_strobe;        wire [7:0]         out_port;        wire [7:0]         in_port=0;        wire                         interrupt=0;        wire                         interrupt_ack;         embedded_kcpsm3 EMBEDDED(                .port_id(port_id),                .write_strobe(write_strobe),                .read_strobe(read_strobe),                .out_port(out_port),                .in_port(in_port),                .interrupt(interrupt),                .interrupt_ack(interrupt_ack),                .reset(reset),                .clk(clock)        );        // only one bit written to by picoblaze, the LED.        // therefore don't need to decode port_id.        // if write_strobe asserts, grab out_port[0] and        // hold it in userbit.        reg userbit = 0;        always @(posedge clock) begin                if(write_strobe) begin                        userbit <= out_port[0];                end        end                assign LED1 = userbit;

endmodule

   

This is the assembly for the toggle project. All the code does is count a really long time and then invert the LED. The total count is controlled by the initial values of s0, s1, s2. with a 16 mhz clock, this code ends up toggling the LED on 2 times a second. Increase S2 initial value from 0F to FF to slow the LED down even further.

  start:             LOAD s9, 00                    drive_wave: OUTPUT s9, 02           ; write s9 register to userbit                     LOAD S2, 0F               ; S2 initial valueloop2:          LOAD S1, FF               ; S1 initial valueloop1:          LOAD s0, FF               ; S0 initial valueloop0:          SUB s0, 01                              JUMP NZ, loop0                    SUB s1, 01                    JUMP NZ, loop1                    SUB s2, 01                    JUMP NZ, loop2                   ;                    XOR s9, FF                    ;toggle register

                    JUMP drive_wave           

1
Kudos!
Solved!
Go to the Solution
Go to Solution
11-06-2009 08:13 PM
  Reply   Reply  

Re: More basic than "hello world", this bare bones intro project blinks a single LED.
Options    Options  
greglondon
Visitor
Posts: 20
Registered: 11-05-2009


greglondon

Message 2 of 3

Viewed 155 times


See if I can get the carriage returns right this time:

 

Here's the verilog:

 

module picoblaze_toggle(

    input FPGA_RESET,

    input CLK_16MHZ,

    output LED1

    );

        wire clock = CLK_16MHZ;

        // reset is active high.

        // if no reset signal input

        // then tie reset to zero here.

        wire reset = FPGA_RESET;

 

        wire [7:0]         port_id;

        wire                         write_strobe;

        wire                         read_strobe;

        wire [7:0]         out_port;

        wire [7:0]         in_port=0;

        wire                         interrupt=0;

        wire                         interrupt_ack;

 

        embedded_kcpsm3 EMBEDDED(

                .port_id(port_id),

                .write_strobe(write_strobe),

                .read_strobe(read_strobe),

                .out_port(out_port),

                .in_port(in_port),

                .interrupt(interrupt),

                .interrupt_ack(interrupt_ack),

                .reset(reset),

                .clk(clock)

        );

        // only one bit written to by picoblaze, the LED.

        // therefore don't need to decode port_id.

        // if write_strobe asserts, grab out_port[0] and

        // hold it in userbit.

        reg userbit = 0;

        always @(posedge clock) begin

                if(write_strobe) begin

                        userbit <= out_port[0];

                end

        end

       

        assign LED1 = userbit;

endmodule

  

Here's teh assembly code:

 

start:             LOAD s9, 00                   

drive_wave: OUTPUT s9, 02           ; write s9 register to userbit

 

                    LOAD S2, 0F               ; S2 initial value

loop2:          LOAD S1, FF               ; S1 initial value

loop1:          LOAD s0, FF               ; S0 initial value

loop0:          SUB s0, 01         

                    JUMP NZ, loop0

                    SUB s1, 01

                    JUMP NZ, loop1

                    SUB s2, 01

                    JUMP NZ, loop2

                   ;

                    XOR s9, FF                    ;toggle register

                    JUMP drive_wave             

 

Kudos!
Accepted Solution
Accepted Solution
11-06-2009 08:16 PM
  Reply   Reply  

Re: More basic than "hello world", this bare bones intro project blinks a single LED.
Options    Options  
Xilinx Employee kcmman
Xilinx Employee
Posts: 138
Registered: 09-05-2007


kcmman

Message 3 of 3

Viewed 101 times


Thank you for this; I am a great believer that there is no such thing as an example that is too simple.

 

Regards,

 

 


 

Ken Chapman
Senior Staff Engineer, Applications Specialist, Xilinx UK

Kudos!
11-10-2009 01:16 AM
Jump to Page:   1