EmbDev.net

Forum: FPGA, VHDL & Verilog Need help with VHDL reading from Hex file


Author: Darren Seow (Company: STP) (lift)
Posted on:

Rate this post
0 useful
not useful
Hi Guys,I previously posted a thread about reading from a file in VHDL 
modelsim.Now I am stuck at another part of my Project.My project is to 
implement a Data Encryption Standard(DES)using VHDL,I am supposed to 
convert a Image into Hex,Binary,etc...,Then encrypt the data and convert 
it back into an image.

I have managed to convert a image into Hex,But cant seem to get Modelsim 
to read the hex file
I would like to request your help if it is possible to read from the 
following input file.
Pardon my english and thanks for taking your time to read this!


Input File
_________________________________________________ 
00000000 FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 ÿØÿà.JFIF...
00000010 00 01 00 00 FF DB 00 84 00 09 06 07 14 13 12 14 ...ÿÛ.„..
00000020 14 12 14 16 15 15 15 15 18 16 17 17 17 17 18 17
00000030 17 18 18 14 18 18 17 17 18 18 17 18 1E 28 20 19 (
00000040 1A 25 1F 18 17 21 31 22 26 29 2B 2E 2E 2E 17 1F %!1"&)+...
00000050 33 38 33 2C 37 28 2D 2E 2B 01 0A 0A 0A 0E 0D 0E 383,7(-.+
00000060 1B 10 10 1B 34 24 20 24 2C 35 2C 32 2F 30 2C 2C 4$ $,5,2/0,,
00000070 34 2C 34 2C 2F 2C 2F 2C 2D 2F 2F 2F 34 2C 2C 2C 
4,4,/,/,-///4,,,
00000080 2C 34 2F 2F 34 2C 2C 2C 2C 2C 2C 34 2C 2C 2C 2C 
,4//4,,,,,,4,,,,
00000090 2C 2C 2C 2C 2C 2C 2C 2F 2C 2F FF C0 00 11 08 00 ,,,,,,,/,/ÿÀ..
000000A0 DB 00 E6 03 01 22 00 02 11 01 03 11 01 FF C4 00 Û.æ".ÿÄ.
000000B0 1B 00 00 01 05 01 01 00 00 00 00 00 00 00 00 00 ...........
000000C0 00 00 00 01 02 03 04 05 06 07 FF C4 00 39 10 00 ...ÿÄ.9.
000000D0 01 03 03 03 02 04 05 02 06 02 01 05 01 00 00 01 ..

Author: Verne (Guest)
Posted on:

Rate this post
0 useful
not useful
I can't see in how far this thread differs from the other one. 
Furthermore: You wrote you have managed to read the file. Now, you've 
not. That's ridiculous. :-{

However, what is your exact problem? What have you tried so far? What 
are the error messages? What is the unwanted behavior? Please do not 
post overall questions but specific ones instead.

Author: Darren Seow (Company: STP) (lift)
Posted on:

Rate this post
0 useful
not useful
Hi Verne,Thanks for taking the time to read my post.Previously I was 
supposed to read from this input file.

Input File(.txt)
_______________
785AC3A4BD0FE12D
123456789ABCDEF0
785AC3A4BD0FE12D

Now I need to read from the above Input file(Hex)which was converted 
from a image using a software I downloaded on the internet.It has weird 
characters on the right side that cant' be shown fully here.

There were no error massages and modelsim was able to 
compile/simulate,But the modelsim read the input as just 
zeros(00000000000....).

Hence,I would like to request for help if it is possible to read this 
code or
I would have to modify it so that modelsim is able to read the code.

Cheers!

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

Rate this post
-1 useful
not useful
Darren Seow wrote:
> But cant seem to get Modelsim to read the hex file
> 00000000 FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 ÿØÿà.JFIF...
> 00000010 00 01 00 00 FF DB 00 84 00 09 06 07 14 13 12 14 ...ÿÛ.„..
> 00000020 14 12 14 16 15 15 15 15 18 16 17 17 17 17 18 17 00000030 17 18
> 18 14 18 18 17 17 18 18 17 18 1E 28 20 19 ( 00000040 1A 25 1F 18 17 21
> 31 22 26 29 2B 2E 2E 2E 17 1F %!1"&)+...
Obviously this is not a hex file. And so Modelsim ist right to do 
nonsense. Why do you not simply read the image file directly in modelsim 
and convert it with VHDL? What format is this image file? Is it a kind 
of raw format or something like a jpeg?

> which was converted from a image using a software I downloaded on the
> internet
It looks like this software is a little buggy. Maybe you find another 
piedce of software working better...

Author: Darren Seow (Company: STP) (lift)
Posted on:

Rate this post
0 useful
not useful
Actually it is just a jpeg image file,I opened it using the 
software(Irfanview)and also another software,and viewed it using the Hex 
viewer on both softwares.

But both software are unable to save the opened Hex viewer as a txt file 
or any other formats.Hence,I had to copy the hex data and paste it onto 
a txt file.It appears weird in here because some characters can only be 
viewed on the hex viewer.

I am kinda at a loss at what to do,But would try my best while checking 
the forums too.

Thanks for your reply!

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

Rate this post
-1 useful
not useful
Darren Seow wrote:
> Actually it is just a jpeg image file,I opened it using the
> software(Irfanview)and also another software,and viewed it using the Hex
> viewer on both softwares.
Convert the JPEG picture to plain BMP format. That one is easy to read 
directly with VHDL...

: Edited by Moderator
Author: Darren Seow (Company: STP) (lift)
Posted on:

Rate this post
0 useful
not useful
Hi Lothar,I managed to put it as a .txt file,I also found out that the 
text on the right colum is actually hex string.Is it possible to get 
Modelsim to read this input file?

Input file
____________________________

00000000  FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01  ÿØÿà.JFIF...
00000010  00 01 00 00 FF DB 00 84 00 09 06 07 14 13 12 14  ...ÿÛ.„..
00000020  14 12 14 16 15 15 15 15 18 16 17 17 17 17 18 17
00000030  17 18 18 14 18 18 17 17 18 18 17 18 1E 28 20 19  (
00000040  1A 25 1F 18 17 21 31 22 26 29 2B 2E 2E 2E 17 1F  %!1"&)+...
00000050  33 38 33 2C 37 28 2D 2E 2B 01 0A 0A 0A 0E 0D 0E  383,7(-.+

Author: Uwe (Guest)
Posted on:

Rate this post
0 useful
not useful
-On the left side is the Hexadecimal representation of the address.

-In the middle is the hexadecimal representation of the Data (this is 
what you want).

-On the right side is the ASCII representation of the Data (this you 
don´t want)

You could use Software like Notepad++ to copy and past in column mode 
(edit->column mode or alt+left mouse).
So you can get the middle columns you need.

But you can use in Notepad++:
 plugins->converter->ASCII to HEX
and also backward

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

Rate this post
0 useful
not useful
Darren Seow wrote:
> Is it possible to get Modelsim to read this input file?
Did you read my previous post?

> Is it possible to get Modelsim to read this input file?
You can read it as a binary file, search for a 000000 pattern (or 
similar) and fetch the next bytes, convert it to text and then to 
numbers...

Author: Marius S. (lupin)
Posted on:

Rate this post
0 useful
not useful
Do you want to make a jpeg decoder in VHDL? If you already have troubles 
reading a JPEG file into your simulation, I think it will be quite hard 
for you to complete a JPEG decoder in VHDL :-)

You should write a small program that converts the original jpeg file 
into a format that is easy to read using VHDL. I would read each byte 
from the original jpeg file, convert it into an 8 bit string of 1s and 
0s and then read the new file as an array of std_logic_vectors in VHDL.

So your file will look like this:
11001010
01001100
11101110
etc.....

Read each line in VHDL and it should work.

: Edited by User
Author: Darren Seow (Company: STP) (lift)
Posted on:

Rate this post
0 useful
not useful
Hi Guys,Thanks for the replies!Thank you Uwe for the fabulous idea!I 
downloaded the notepad++ and edited the columns and here is the result 
for afew of the lines

Input file
__________________
00000000  FFD8FFE000104A464946000101000001  ÿØÿà.JFIF...
00000010  00010000FFDB00840009060714131214  ...ÿÛ.„..
00000020  14121416151515151816171717171817
00000030  1718181418181717181817181E282019  (
00000040  1A251F181721312226292B2E2E2E171F  %!1"&)+...


Actually this is a part of my project,I am implementing Data Encryption 
Standard(DES)using VHDL.

(1)Convert a image(jpg,png...)into text(binary,hex,etc...)
(2)Encode the text(I written the code for encoding)
(3)Convert it back into an image(it should look different from the 
original)
(4)Convert it back into text(encrypted text)and decrypt it
(5)It should look like the original text(above input file)

Thank you for all the replies/help guys!I would be needing your help as 
my instuctor is unable to help me(He says he isnt good with software).

Author: mouna (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Hello,
Can you plzzzzzzzzzz send me the vhdl code for reading text file ?
You send it to my email mounaho@gmail.com
Thank you in advance,

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.