EmbDev.net

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


von Darren S. (Company: STP) (lift)


Rate this post
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 ..

von Verne (Guest)


Rate this post
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.

von Darren S. (Company: STP) (lift)


Rate this post
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!

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
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...

von Darren S. (Company: STP) (lift)


Rate this post
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!

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
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
von Darren S. (Company: STP) (lift)


Rate this post
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(-.+

von Uwe (Guest)


Rate this post
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

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
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...

von Marius S. (lupin)


Rate this post
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
von Darren S. (Company: STP) (lift)


Rate this post
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).

von mouna (Guest)


Attached files:

Rate this post
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,

von Van Loi L. (fpga4student)


Rate this post
useful
not useful
mouna wrote:
> 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,

Example VHDL code for reading a text file:
http://www.fpga4student.com/2016/11/two-ways-to-load-text-file-to-fpga-or.html
http://www.fpga4student.com/2016/11/matrix-multiplier-core-design.html
http://www.fpga4student.com/2017/01/a-low-pass-fir-filter-in-vhdl.html

von Ricky T. (Company: Toshiba) (rickyterzis)


Rate this post
useful
not useful
Hi...i am a new user here. As per my observation 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?

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.