Here is my dilemma:
I am very new to VHDL programming and am currently working on an independent study project for a university class. I did some descent, but I ran into a problem that I could not solve.
What I'm trying to do is display a โregisterโ (or registers) on the LCD monitor and periodically update it. Currently, these values โโwill always be integers.
I have code that correctly displays numbers on the screen if , this value is passed as a variable that never changes or as a hard-coded value. However, I want to update the variable by adding to it, then pass it to my function and display it.
Essentially, I'm trying to do the following:
Each ticking 'x' increments the value of the register, passes it to my update_screen function, which returns a new screen and then displays it below. However, as soon as I increase or change the reassignment (it doesn't seem to matter if it is a variable or a signal), all I see is โ0โ on the screen.
So ... The following code correctly updates my display if I do not uncomment the commented lines. At this point, it simply displays "0".
The problem seems to be related to the integer'image attribute (or, more precisely, to my understanding). When I pass a solid value or a variable that has not been changed, it returns what I expect. However, as soon as I changed the variable / signal ANY way seems to return the string "0".
Below is my update_screen function:
function update_screen(screen: screenData; reg, regVal: integer) return screenData is -- A function may declare local variables. These do not retain their values between successive calls, -- but are re-initialised each time. Array-type parameters may be unconstrained: constant screenWidth: integer := screen'length(2); constant strRegVal: string := integer'image(regVal); constant strRegLen: integer := strRegVal'length; variable newScreen: screenData := screen; begin for dex in 1 to screenWidth loop if dex <= strRegLen then newScreen(reg, dex-1) := strRegVal(dex); else newScreen(reg, dex-1) := ' '; end if; -- The next two ifs were my attempt to figure out what -- was going on... --The value itself never seems to be 0... the screen is not all 5's if regVal = 0 then newScreen := (others => (others => '5')); end if; -- But the string value is "0" if the variable/signal is ever modified... -- 'd' shows up in the designated row. if strRegVal = "0" then newScreen(reg*3, 1) := 'd'; end if; end loop; return newScreen; end update_screen;
A few important points (added 2011-07-26):
- I use the free (web edition) Quartus II to develop / compile my project.
- Code that updates the variables is in process.
- During the initial publication, the only actions I took were compiling my code and programming the Altera DE2 FPGA with the result (I was not sure how to perform any simulations).
Thanks in advance for your help and advice. Also, as I said, I'm new to VHDL programming, so if there is a much better way to do something that I am doing here, please let me know. I also really appreciate useful links to any resources about the language itself.
Update (2011-07-26):
I downloaded GHDL, as Martin Thompson suggested, but I have not used it yet because I donโt know how to do this with my current Quartus II project (or, if possible, even). I will need to read something before it is useful to me. However, yesterday I was able to install ModelSim-Altera, which works directly with Quartus II and allowed me to do some simulation.
I did my best to set up some waveforms that would allow me to test, and at least I was able to study the execution of code that I thought was failing. However, during the simulation, I checked in several ways that the โscreenโ object contains the value that I want it to be contained after running the * screen_update * function. However, when working on Altera DE2, it still does not work.
- Note. I really checked that the screen is really updating by directly setting the value of a specific item on the screen for different values โโdepending on whether currentRegVal is even or odd.
I plan to publish the code tomorrow, but for now:
What are the reasons why a simulation will produce different results? I suppose this is time related, but actually it is just a hunch. If I am right, how can I try to solve the problem?