Outputting signal values to terminal Within Character Array

Dec 9, 2021
Reaction score
Hey all,

I'm self teaching myself a lot of FPGA programming with VHDL for a personal project, and I'm running into an issue getting signal values to output to my terminal via UART bridge. Apologies if I don't give enough information in the initial thread, and also sorry if this is a super simple question, since I'm pretty much entirely self taught.

Right now, I have a Cmod A7 FPGA hooked up to an analog to digital voltage converter via a standard SPI interface. I managed to write and create a code that configures the AD converter, and the converter is sending me binary signals corresponding to an external input voltage I can manually control. What I eventually want to do is perform some operations on the signal and output it from the FPGA into another digital to analog converter, so the next step in the project is I want to confirm the data is being stored in the FPGA correctly, and to do that I want to output a message to an external terminal hooked up to the FPGA via a USB UART bridge that is pre-packaged with the FPGA.

I have had a lot of issues getting this to work correctly through my own code, so I found a demo project on the Digilient website that has the framework that is pretty close to what I want to do (found here https://digilent.com/reference/learn/programmable-logic/tutorials/cmod-a7-gpio-demo/start). Using that code, I was able to cobble together a working code that still communicates with the AD converter like it should, but can also output hardcoded messages when one of the buttons on the FPGA is pressed. My idea is to modify the hard coded message so that rather than outputting a string of characters, it outputs the value currently on the SDO pin. The relevent code is below.

type CHAR_ARRAY is array (integer range<>) of std_logic_vector(7 downto 0);

constant TMR_CNTR_MAX : std_logic_vector(26 downto 0) := "101111101011110000100000000"; --100,000,000 = clk cycles per second
constant TMR_VAL_MAX : std_logic_vector(3 downto 0) := "1001"; --9

constant RESET_CNTR_MAX : std_logic_vector(17 downto 0) := "110000110101000000";-- 100,000,000 * 0.002 = 200,000 = clk cycles per 2 ms

constant MAX_STR_LEN : integer := 31;

constant WELCOME_STR_LEN : natural := 31;
constant BTN_STR_LEN : natural := 24;

--Note that the values stored at each index
--are the ASCII values of the indicated character.

--Button press string definition.
constant BTN_STR : CHAR_ARRAY(0 to 23) := (X"42", --B
X"75", --u
X"74", --t
X"74", --t
X"6F", --o
X"6E", --n
X"20", --
X"70", --p
X"72", --r
X"65", --e
X"73", --s
X"73", --s
X"20", --
X"64", --d
X"65", --e
X"74", --t
X"65", --e
X"63", --c
X"74", --t
X"65", --e
X"64", --d
X"21", --!
X"0A", --\n
X"0D"); --\r

More specifically, what I want to do is update (for example) the (X"42", part of the line

constant BTN_STR : CHAR_ARRAY(0 to 23) := (X"42", --B

so that rather than outputting a B corresponding to the hex value 0x42, it outputs the value of a signal I have later in the code? I know that the code controlling the button press outputting the above string works, so all I would need is to change the character at the above locations. A comparable line of code from C would be something like

printf("This variable has value %d\n", variable_name);

so I'm basically asking is there is if there is a comparable syntax in VHDL to %d, and how would I call the value of a specific variable? If it helps, the variable I am trying to ouput is a a std_logic_vector and idea is to basically output one value per line, so the final code would look something kind of line this.

constant BTN_STR : CHAR_ARRAY(0 to 23) := (variable(6),

I am also pretty sure I need to change the type for the BTN_STR to signal, but other than that I am not sure.

Thanks again for your help in advance, and please let me know if you need any further clarification.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads