EmbDev.net

Forum: FPGA, VHDL & Verilog Improving my code!


Author: Enrique Perez (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello buddys!

I am working with a image sensor which delivers 4 pixels (12 bits/pixel) 
every system clock.

The pixel output of the sensor is 6 Lines x 2112 pixels. And I want to 
throw away some pixels per line according to the parameter SHIFT_COL.

For example,
- if SHIFT_COL = 1, the 1st pixel of every line should be skipped 
resulting 2111 pixels.
- if SHIFT_COL = 2, the 2 first pixels of every line should be skipped 
resulting 2110 pixels
- and so on...

Here is the code that I have already programmed. But I think that it 
could be a better coding for this issue. Any suggestion?
  -- Valid Pixels Management:
      -- Receiving 4 pixels on every clock cycle and skip some of them
    -- according to the parameter SHIFT_COL
    SHIFT_DAV  <= '0';
    -- New "4pixels" or The limit number of pix is not achived!                   
    if VID_I_DAV = '1' or (SHIFT_CNT > 0 and (SHIFT_CNT < 2112+(4*unsigned(SHIFT_COLr)))) then
      VID_I_CNT <= VID_I_CNT + 4;      
      SHIFT_SEL    <= SHIFT_SEL + 1;
      -- Binning 6x6 => Max. 10 pixels to shift!
      if FPGA_MODE_l = "100" then                                       
        case SHIFT_COLr is
          when x"0000" => -- No shifting 
            if SHIFT_SEL = 0 then 
              SHIFT_DATA_REG <= VID_I_DATA;
              SHIFT_DAV  <= '1';
              SHIFT_SEL  <= (others=>'0');
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;      
          when x"0001" => -- Shifting 1 column
            if SHIFT_SEL = 0 then               
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
            elsif SHIFT_SEL = 1 then               
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
              SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 2 then
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
              SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"1";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;                   
          when x"0002" => -- Shifting 2 columns
            if SHIFT_SEL = 0 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
            elsif SHIFT_SEL = 1 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 2 then
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"1";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;                             
          when x"0003" => -- Shifting 3 columns
            if SHIFT_SEL = 0 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
            elsif SHIFT_SEL = 1 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 2 then
              SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"1";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;
          --
          when x"0004" => -- Shifting 4 columns
            if SHIFT_SEL = 1 then 
              SHIFT_DATA_REG <= VID_I_DATA;
              SHIFT_DAV  <= '1';
              SHIFT_SEL  <= x"1";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;      
          when x"0005" => -- Shifting 5 columns
            if SHIFT_SEL = 1 then               
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
            elsif SHIFT_SEL = 2 then               
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
              SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 3 then
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
              SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"2";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;                   
          when x"0006" => -- Shifting 6 columns
            if SHIFT_SEL = 1 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
            elsif SHIFT_SEL = 2 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 3 then
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"2";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;                             
          when x"0007" => -- Shifting 7 columns
            if SHIFT_SEL = 1 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
            elsif SHIFT_SEL = 2 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 3 then
              SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"2";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;                                         
          --
          when x"0008" => -- Shifting 8 columns
            if SHIFT_SEL = 2 then 
              SHIFT_DATA_REG <= VID_I_DATA;
              SHIFT_DAV  <= '1';
              SHIFT_SEL   <= x"2";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;      
          when x"0009" => -- Shifting 9 column
            if SHIFT_SEL = 2 then               
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
            elsif SHIFT_SEL = 3 then               
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
              SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 4 then
              SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
              SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);                            
              SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"3";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;                   
          when x"000A" => -- Shifting 10 columns
            if SHIFT_SEL = 2 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
            elsif SHIFT_SEL = 3 then 
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';
              SHIFT_CNT <= SHIFT_CNT + 4;
            elsif SHIFT_SEL = 4 then
              SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
              SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
              SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
              SHIFT_DAV <= '1';            
              SHIFT_SEL   <= x"3";
              SHIFT_CNT <= SHIFT_CNT + 4;
            end if;                             
          when others => null;
        end case;        
      end if;    
    end if;    

Thanks anyway!

: Moved by Moderator
Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
I moved your thread from the German (uc.net) to the Englisch spoken 
forum (embdev.net).

Enrique Perez wrote:
> But I think that it could be a better coding for this issue.
For sure. This code looks like a copy-and-paste structure.

> Any suggestion?
DON'T_WRITE_ALL_THE_NAMES_IN_UPPERCASE_LETTERS! IT_MAKES_THE_ CODE 
NEARLY_UNREADABLE!

> And I want to throw away some pixels per line according to the parameter
> SHIFT_COL.
> For example,
> - if SHIFT_COL = 1, the 1st pixel of every line should be skipped
> resulting 2111 pixels.
> - if SHIFT_COL = 2, the 2 first pixels of every line should be skipped
> resulting 2110 pixels - and so on...
I would do this "skipping" during reading the line. Then its very easy: 
just don't read a value.
If you already read the line, then Skipping would be just a 
recalculation of the offset for accessing the data.

Author: Enrique Perez (Guest)
Posted on:

Rate this post
0 useful
not useful
Ok I am sorry, I would not know where to place it

The problem is that I need to buffer a complete line in order to make 
the skipping of the pixels, and I don't have enough space in the FPGA to 
implemente a FIFO o RAM to buffer a complete line...

Any other suggestion?

Thanks

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Enrique Perez wrote:
> The problem is that I need to buffer a complete line in order to make
> the skipping of the pixels
Why that?

> and I don't have enough space in the FPGA to implemente a FIFO o RAM to
> buffer a complete line...
Why not?
>> output of the sensor is 6 Lines x 2112 pixels ... (12 bits/pixel)
That means 6x2112x12 = 152064 bit. Even an ancient XC3S200 has 221,184 
bits of RAM...

Author: Enrique Perez (Guest)
Posted on:

Rate this post
0 useful
not useful
Now the FPGA is almost 93%. I think I can't make that
 implementation in
 the FPGA.

 Anyway in the initial post ( I am very sorry). What I want to have is
 always 2112 pixels. So when for example, SHIFT_COL = 1 and the input of
 the sensor is so:
          Input                                      Output
 Pixel1 Pixel2 Pixel3 Pixel4           Pixel1   Pixel2   Pixel3   Pixel4
    0     1      2       3               1        2         3       4
    4     5      6       7               5        6         7       8
    8     9      10      11      =>      9        10        11      12
 ..                                     ..
 ..                                     ..
  2108   2109   2110  2111              2109     2110    2111    2112

 As you can see the amount of pixels is always the same: 2112.

 A lot of thanks

: Edited by Moderator
Author: -gb- (Guest)
Posted on:

Rate this post
0 useful
not useful
You want to shift all values by 1 to the left?

And the leftest value from the next line N becomes the rightes in the 
line (N-1)?

What du you want to do with the Values? I think you could store the 
values in an BRAM and just offset the readaddress by one or two. The 
missing additional values in line 6 at the right can be stored 
seperatly.

Author: Enrique Perez (Guest)
Posted on:

Rate this post
0 useful
not useful
No really, what I want to do is throw away the values according to the 
parameter SHIFT_COL. But alway I have to deliver 2112 pixels.

In my previous post, you can see that the incoming data are 4 pixels in 
parallel and I am capturing 2112 pixels always. If for example the 
content of every pixel is directly the number of the pixel (this is 
something theoretical, in reality I am going to have the pixel value 
coded in 12 bits), when SHIFT_COL = 1, I have to throw away the first 
pixels of the 4 incomming paralles pixels. When SHIFT_COL=2, I have to 
throw away 1st and 2nd pixel of the 4 incomming parallel pixels and so 
son...But always I have to provide a packet of 2112 pixels (You can 
shift the window of the sensor until 2202 pixels).

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Enrique Perez wrote:
> but always I have to provide a packet of 2112 pixels
To whom? And by which means? What interface? Do you have "to deliver" it 
parallel? Or with a serial protocol pixel by pixel?

Thousands of questions. No one of them answered...

Enrique Perez wrote:
> Now the FPGA is almost 93%.
Let me say it that way: a beginner will need a much bigger FPGA due to 
not using properly components inside it. The far I can see it you can 
easily reduce that footprint: let me simply assume there is a big 
monster array somewhere in the not posted code...

> Now the FPGA is almost 93%.
Are those 93% with or without RAM blocks?

Author: Enrique Perez (Guest)
Posted on:

Rate this post
0 useful
not useful
I have to provide 2112 pixels to the PC via Ethernet!

The sensor is delivering in parallel 4 pixels. Then I make a data 
processing where I have to do the sikiping of the pixels and a binning 
later.

It is 93% using 3 RAMs to store pixel to make the data processing.

Author: Sigi (Guest)
Posted on:

Rate this post
0 useful
not useful
Transmitting Pixels via Ethernet means: a kind of serial process.
Receiving Pixels from Camera 4 Pix/Clock: another kind of serial
process.

Receiving Pixels: just use a simple address counter (start with 0
at line start), incremented every camera clock cycle and store
the (4) pixels in several (FPGA internal) Block RAMs.

Transmitting Pixels: use a second address counter, depending on
SHIFT_COL starting with 0,1,2,... incremented every transmitting
cycle.

Ethernet: complexity depends on the underlying protocol, but a
std. frame can be stored in an additional BlockRAM(s).

Simple Example: a Xilinx Spartan XC3S200 or XC3S250E is big
enough wrt number of BlockRAMs, the receiver/transmitter logic
needs not more than 10% of all logic recources.
The only remaining problem can be the Ethernet Protocol, but a
simple UDP-Transmitter is not so complex.

Author: Enrique Perez (Guest)
Posted on:

Rate this post
0 useful
not useful
Thank you very much. I will test your solution on Monday!!!

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.