Friday Free Board Quiz – prize is A20-CAN: What programming language can you use to automate tasks within Kicad?

A20-CAN

A20-CAN is Open Source Hardware CAN driver board, which you can connect to A20-OLinuXino-MICRO, A20-OLinuXino-LIME and A20-OLinuXino-LIME2.

You have chance to win this board!

To participate in the Quiz is enough to re-tweet the Twitter Quiz announcement message.

To double your chances  answer the quiz question.

You have time to re-tweet and/or answer until Monday 25th of July.

In Monday we will post the correct answer and ask random.org to generate random number in range then announce the winner and ship the board by post/airmail.

Good Luck!

FPGA tutorial – VGA video Generation with FPGA and Verilog – add video memory to the project and object animation

1

The previous blog about video generation is here.
For the weekend I posted Verilog Programming challenge to change the shape of the square to circle but unfortunately we didn’t got single solution:)

I guess you guys also learn yet and this was hard challenge to solve:)

In this post I will show you that this is not so hard.

Let's see again the source from the older post, here is where square is generated:
 
   if(c_col > l_sq_pos_x && c_col < r_sq_pos_x && c_row > u_sq_pos_y && c_row < d_sq_pos_y) begin 
      //generate blue square
      vga_r_r <= 0;
      vga_g_r <= 0;
      vga_b_r <= 7;
   end

 

What this codes does? If the video coordinates are within square we assign some color to VGA output.

This is the part we should modify to draw circle but how?

We will use for this purpose video memory and in this memory we will draw circle then when the video beam is in this area it will draw the content of the video memory.

Let’s define the memory:

   reg [19:0] sq_figure [0:19];

 

This defines 20 registers which are 20 bit wide, so we define 20×20 bit video memory which we will use to draw image on the VGA screen.

We also need two counters which to count XY beam position within the square area where we will draw:

wire [4:0] sq_fig_x;
wire [4:0] sq_fig_y;

assign sq_fig_x = c_col - l_sq_pos_x; // our figure's x axis when in square boundary
assign sq_fig_y = c_row - u_sq_pos_y; // our figure's y axis when in square boundary

This video memory registers must be load with the ball image, we will do this during the reset state where we initialize other registers too:

if(reset == 1) begin //while RESET is high init counters
  sq_figure[0][19:0] <= 20'b00000000000000000000;
  sq_figure[1][19:0] <= 20'b00000001111100000000;
  sq_figure[2][19:0] <= 20'b00000111111111000000;
  sq_figure[3][19:0] <= 20'b00011111111111110000;
  sq_figure[4][19:0] <= 20'b00111111111111111000;
  sq_figure[5][19:0] <= 20'b00111111111111111000;
  sq_figure[6][19:0] <= 20'b01111111111111111100;
  sq_figure[7][19:0] <= 20'b01111111111111111100;
  sq_figure[8][19:0] <= 20'b11111111111111111110;
  sq_figure[9][19:0] <= 20'b11111111111111111110;
  sq_figure[10][19:0] <= 20'b11111111111111111110;
  sq_figure[11][19:0] <= 20'b11111111111111111110;
  sq_figure[12][19:0] <= 20'b11111111111111111110;
  sq_figure[13][19:0] <= 20'b01111111111111111100;
  sq_figure[14][19:0] <= 20'b01111111111111111100;
  sq_figure[15][19:0] <= 20'b00111111111111111000;
  sq_figure[16][19:0] <= 20'b00111111111111111000;
  sq_figure[17][19:0] <= 20'b00011111111111110000;
  sq_figure[18][19:0] <= 20'b00000111111111000000;
  sq_figure[19][19:0] <= 20'b00000001111100000000;
 
  c_hor <= 0;
  c_ver <= 0;
  vga_hs_r <= 1;
  vga_vs_r <= 0;
  c_row <= 0;
  c_col <= 0;
end

 

Now we have loaded our video memory with the image of the ball and we should add code which draw it:

if(c_col > l_sq_pos_x && c_col < r_sq_pos_x && c_row > u_sq_pos_y && c_row < d_sq_pos_y) begin 
     //generate picture from the video memory
   if(sq_figure[sq_fig_y][sq_fig_x] == 1) begin
      vga_r_r <= 7;
      vga_g_r <= 0;
      vga_b_r <= 7;
   end
   else begin
     vga_r_r <= 0;
     vga_g_r <= 0;
     vga_b_r <= 0;
end

 

What we do here? If the video memory is 1 we draw pink dot otherwise black on the screen. Is it really so simple? Let’s compile and see what happens!

Wow it works! You see the picture above.

Let’s copy this code it to example_4.v for further reference.

Now when we have video memory we can change it content and make animations by change dynamically the image inside the video memory.

To do this we have to load the registers with different ‘picture’.

Before we do this first let’s fix something annoying with the keyboard handling which bothers me. When I press up key ball start to move up and I can’t change the direction until it hits the wall.

This is because we commented the code for key release, so the arrow flags are clear press key flag is to hit the wall.

Let’s make this modification:

if(c_row == 1 && c_col == 1) begin //once per video frame
  if(u_arr) begin
    if (sq_pos_y > square_size) begin
       sq_pos_y <= sq_pos_y - 1;
    end
    else begin
       u_arr <= 0;
       d_arr <= 1;
    end
  end;

if(d_arr) begin
  if (sq_pos_y < (v_pixels - 1 - square_size)) begin
    sq_pos_y <= sq_pos_y + 1;
  end
  else begin
    d_arr <= 0;
    u_arr <= 1;
  end
end;

if(l_arr) begin
  if (sq_pos_x > square_size) begin
    sq_pos_x <= sq_pos_x - 1;
  end
  else begin
    l_arr <= 0;
    r_arr <= 1;
  end
end;

if(r_arr) begin
  if (sq_pos_x < (h_pixels - 1 - square_size)) begin
     sq_pos_x <= sq_pos_x + 1;
   end
   else begin
      r_arr <= 0;
      l_arr <= 1;
   end
 end;

end

 

Great! Now I can change up down left right direction on the fly while ball is moving, but the ball after a while start moving only diagonally because up down do not change left right direction:)
Let’s save current example to example_5.v for further reference and try to modify one more time the code.

Let’s make if ball is moving up but also in any of X direction pressing second time up to make it move stright up and same for other keys.

First we will need to add de-bounce time as once we press the key each frame this means 25 per second key will be scanned .

We will add de-bounce timer:

reg [19:0] arr_timer; // delay between key check

 

We define 20 bit counter, which will be clocked at 25Mhz and will overflow after 0.041(6) seconds, we will check keys only when this counter oveflow:

arr_timer <= arr_timer + 1;
 
if(arr_timer == 0) begin
  if(ps2_data_reg_prev == 8'he0) begin //0xE0 means key pressed
    if(ps2_data_reg == 8'h75) begin 
      if(u_arr == 1) begin
        u_arr <= 1; //0x75 up key 
        d_arr <= 0;
        l_arr <= 0;
        r_arr <= 0;
      end
      else begin
        u_arr <= 1; //0x75 up key 
        d_arr <= 0;
      end
    ps2_data_reg <= 0;
   end
   if(ps2_data_reg == 8'h6b) begin 
     if(l_arr == 1) begin
       l_arr <= 1; //0x6B left key
       r_arr <= 0;
       u_arr <= 0;
       d_arr <= 0;
     end
     else begin
       l_arr <= 1; //0x6B left key
       r_arr <= 0;
     end
    ps2_data_reg <= 0;
   end
   if(ps2_data_reg == 8'h72) begin
     if(d_arr == 1) begin
       d_arr <= 1; //0x72 down key
       u_arr <= 0;
       l_arr <= 0;
       r_arr <= 0;
     end
     else begin
       d_arr <= 1; //0x72 down key
       u_arr <= 0;
     end
    ps2_data_reg <= 0;
   end
   if(ps2_data_reg == 8'h74) begin
     if(r_arr == 1) begin
       r_arr <= 1; //0x74 right key
       l_arr <= 0;
       u_arr <= 0;
       d_arr <= 0;
     end
     else begin
       r_arr <= 1; //0x74 right key
       l_arr <= 0;
     end
    ps2_data_reg <= 0;
   end
 end 
end

When u_arr is 0 and it is set 1 we just clear d_arr, but if u_arr already has been 1 and we set u_arr again we clear l_arr and r_arr too.

This way if ball moves diagonally up and we press the up key again it will go straight up, same for the other directions too.

Now everything is perfect! Let save it as example_6.v

One last mod: Let’s use arr_timer to dynamically change the video memory, we add this code

if(arr_timer == 0) begin
   sq_figure[8][19:0] <= sq_figure[8][19:0] ^ 20'b00000001111000000000;
   sq_figure[9][19:0] <= sq_figure[9][19:0] ^ 20'b00000001111000000000;
   sq_figure[10][19:0] <= sq_figure[10][19:0] ^ 20'b00000001111000000000;
   sq_figure[11][19:0] <= sq_figure[11][19:0] ^ 20'b00000001111000000000;

What we do here, each time arr_timer overflow (25 000 000 / 2^20) i.e. each 0.0416 seconds we xor few lines of the video memory and thus make square hole inside the ball.

We compile and see that the ball animation works but too fast. Let’s change the arr_timer to 21 bit and slow town the blinking.

The new code is saved as example_7.v

2

What we learn so far? How to define memory in Verilog and how to display this memory content at given coordinates.

All changes are now uploaded at GitHub.

What Next?

In the next Tutorial we will use iCE40HX1K-EVB SRAM memory as video memory to generate video with resolution 640×480 pixels 512 colors.

Then we will teach you how to use the 100Mhz  iCE40-ADC and iCE40-DAC.

Using  iCE40HX1K-EVB as 100Msps Logic Analizer for signals with voltage levels from  1.65V to 5.5V using iCE40-DIO and connected to Sigrok Pulseview and how you can sniff CAN, USB, RFID, I2C, I2S, JTAG, MIDI, MODBUS, SPDIF, SPI, and all other 66 decoding protocols which Sigrok supports.

All TuxCon 2016 Day 1 talks videos are uploaded on Youtube

tuxcon2016

 

All TuxCon 2016 talks from Day 1 are now online, some of them are in English, some in Bulgarian language.

RFID 13.56 Mifare Classic 1K tags with NXP MF1S50yyX/V1 chipset in stock

tags

MOD-RFID1356MIFARE RFID reader / writter based on NFC PN532 chip was recently introduced but we had no tags for it.

Now we stock 5 different tags:

Using iCE40HX1K-EVB under Windows

FPGA

Windows is still most popular desktop platform and many people use it. So far all our blogs were how to use iCE40HX1K-EVB with Linux and IceStorm Free and Open Source tools.

What are the options for Windows users? I can think of three options at glance:

  • Virtual machine: you can install VirtualBox or VMware Player then to install Linux OS on the Virtual Machine like Ubuntu or better Xubuntu which requires less resources and do not uses Unity 3D effects ;
  • Cygwin is another option and offers Linux like tools in Windows environment. You will be able to compile IceStorm from sources;
  • Wubi allows you to install Linux as Windows program, not dealing with disk partitioning and such, you install Linux, then if you want to remove just go to Control Panel and remove it as installed program;

Perhaps there are other ways to use Linux software under Windows, but these three are probably most popular.

Of course Windows users have one more options and this is the original Lattice FPGA software called iCEcube2. Here we will go through installation process of these tools too and how to use them with iCE40HX1K-EVB.

Intalling the iCEcube2 IDE and generating bit file.

First you have to go to Lattice Semiconductor web site and to register. You will have to fill lot of personal and work info and apply for registration then waiting your account to be created and you will get e-mail which you have to use to activate it. The account registration may take from few hours up to 1 day.

Once your account is activated you can go to Products -> Software Tools -> iCEcube2 and to download it.

To install it you will need to apply for Free License including information for the MAC address on your computer where the software will run! You can see the difference between IceStom and iCEcube2 in the first you have no restrictions whatsoever, the only free thing in the latter is that it’s cost-free you have no other freedom. Lattice may shut you down from using it at any time. Why is this? Edmund explained it well in his lecture at TuxCon 2016. Lattice didn’t made these tools, they buy from 3rd party, this is why they should have way to count their users to may pay licensee fees to the software vendor (you will see restriction iCEcube2 to be licensed by Cadence employees probably to not abuse Lattice with many licensees which Lattice pays for). Lattice make money only from selling chips, and generates loss from users who use small amount of chips like startups, small developers, people who learn FPGAs, as they use the tools but do not buy many chips which to justify the development tools price they pay to the vendor. So the tools they provide are named to be “free” but they are only cost-free, sponsored by Lattice.

When download it you should select Windows version:

1

Click on the Download button and select save the .zip file.

2

While your zip file is downloading go back to the iCEcube2 page and request you cost-free license.

3

Enter your MAC address and click on Generate License. If you enter a wrong MAC address iCEcube2 will not be able to start. You can request a new license with the correct MAC address.

To learn what your MAC address is run ‘cmd’ and type ipconfig /all .

4

Go to your email and you should see a new email, with the license file attached (license.dat). Save it to a convenient location.

After the iCEcube2 .zip file has finished downloading simply unzip it and run the .exe inside. During the installation you must provide the path to the license file:

6

Then the installation is fairly a straight-forward process and you can run the iCEcube2 IDE.

Double click on New Project on the left panel and fill the form and click Next.

You can download some examples for the iCE40HX1K-EVB from GitHub. The example should have at least two files: one is the Verilog (or VHDL) code and the other is the .pcf pin constraint file.7jpg

Click on Next and Finish, we will add the design and constraint files later manually.

8

First add the Verilog file: right-click on Design Files and select the .v file and add it to the project using the >> button or just double-clicking on it and click OK.

9

Then click on Constraint Files and add the .sdc file:

14

And then right-click on Constraint Files under P&R flow for the .pcf file:

11

Finally click on Tool->Run All:

12

The synthesis process should start and at the end will look like this:

13

From all the 3MB files that are generated only the .bin file is what we will use to upload to the FPGA.

You can compare the process with IceStorm where you only have to have two files and simple issue one command  ‘make’ compared to the claimed to be easier to use windows interface to  create the simple blink LED project.

Programming the iCE40-HX1K-EVB board with winiceprogduino

There are two types of programming: one is programming the iCE40HX1K-EVB on-board flash memory, which the FPGA reads every time it resets, and the other is directly programming (which often is described as configuring) the FPGA (the configuration is lost after power down / reset therefore).

Olimex provides a programming tool for Windows that uses the Olimexino-32U4 to program the SPI flash of the iCE40HX1K-EVB. First you need to program Olimexino-32U4 with the iceprogduino sketch as explained here. Arduino works under Windows too so the procedure is same as with Linux.

Then you need winiceprogduino.exe which programs the FPGA with the previously generated bin file. winiceprogduino is same as the linux iceprogduino but re-compiled for Windows with the DevC++ compiler.

You can download project, sources and pre-compiled version from GitHub. winiceprogduino takes COM port (the port that is assigned from Windows for Olimexino-32U4) and target file (the bin file we generated earlier with iCEcube2) as arguments and sends the file to the Olimexino-32U4 which programs it to the SPI flash or directly configures the FPGA, depending on the options you selected.

You can run winiceprogduino.exe and will see all options:

win

When you plug Olimexino-32U4 to your computer go to Device Manager and see which COM port is assigned to it. In our case it was COM10 and to program the blink led bin we should type:

prog

FPGA will be programmed and you will see the LED1 and LED2 blinking.

Now you are set to create your own projects with iCEcube2. Have fun!

 

Weekend – Verilog Programming Challenge – Test your Verilog skills this weekend.

video-1
Do you remember WPC (weekend programming challenge). All problems are on GitHub.

I still get e-mail from people asking why we did stop it, the answer is simple: we just ran out of ideas what challenges in programming to ask you.

You guys were so good and for the last challenges I always had impression that we already have solved something like this.

Now you know I have new toys – iCE40 FPGAs and learning Verilog, so I have few ideas for challenge people like me who want to learn Verilog.

Here is our first challenge: Two days ago I posted tutorial how to program VGA video generator and to move one square on the screen with keyboard.

The challenge for this weekend is: modify the code from GitHub to display ball instead of square:)

You have time to Monday to solve this and submit your solution to info@olimex.com.

In Monday I will upload all ideas on GitHub and comment.

Have fun!

Friday Free Board Quiz – the prize is OLIMEXINO-32U4 – How many routing modes are supported by the interactive router in pcbnew?

OLIMEXINO-32U4-02

 

OLIMEXINO-32U4 is OSHW improved version of Arduino Leonardo. It has ULTRA LOW power regulators, Lipo battery charger and can work from single Lipo battery, 5 and 3.3V operation, shield connectors both with original Arduino messy layout and correct layout next to them:)

You have chance to win this board!

To participate in the Quiz is enough to re-tweet the Twitter Quiz announcement message.

To double your chances  answer the quiz question.

You have time to re-tweet and/or answer until Monday 18th of July.

In Monday we will post the correct answer and ask random.org to generate random number in range then announce the winner and ship the board by post/airmail.

Good Luck!

Previous Older Entries

Follow

Get every new post delivered to your Inbox.

Join 780 other followers