4 thoughts on “Finally, actually reading a PGM file in VHDL

  1. Sotiris Thomas

    As I understand it, it works because it’s all enclosed in a bigger loop:


    allpixels : loop
    readline(pgmfile, l);

    exit when l = null;
    exit when l'length = 0;

    loop in question-->
    loop
    read(l, int, good);
    exit when not good;
    ret(x, y) := int;
    exit allpixels when x = width-1 and y = height-1;
    x := x + 1;
    if x >= width then
    x := 0;
    y := y + 1;
    end if;
    end loop;
    end loop allpixels;

    Now that I think of it, this confusion may be due to the format of my pgm files. Every pixel value is on a new line, as exported by Gimp. Example:

    P2
    # CREATOR: GIMP PNM Filter Version 1.1
    450 375
    255
    119
    120
    ...

    That’s why the read() in question reads 1 character per line and then throws the error. I have run your testbench with the changes and it works the same. I’m using the Isim that comes with ISE 12.1 (M.53d)

    Reply
  2. Martin

    I’m not sure that’s a valid fix in general (removing the loop and the exit) – it works fine for one number per line, but shouldn’t work when there’s more than one number per line. That may be a failing of my testcases!

    I think the root-cause of the problem is really just that Isim is whinging a lot. I’ll see if I can replicate it here and come up with a better fix.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax