Convert boolean to std_logic


M

manolis kaliorakis

Hello to all,

I am a beginner in using vhdl. I want to convert a signal boolean to
std_logic. How could I achieve this?
I am using these libraries:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

Thanks in advance
 
Ad

Advertisements

K

KJ

Hello to all,

I am a beginner in using vhdl. I want to convert a signal boolean to
std_logic. How could I achieve this?
I am using these libraries:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

KJ note: Do not use the following libraries, use ieee.numeric_std
instead
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

You have to create your own function...here it is

function To_Std_Logic(L: BOOLEAN) return std_ulogic is
begin
if L then
return('1');
else
return('0');
end if;
end function To_Std_Logic;

Kevin Jennings
 
M

manolis kaliorakis

KJ note:  Do not use the following libraries, use ieee.numeric_std
instead

k
You have to create your own function...here it is

    function To_Std_Logic(L: BOOLEAN) return std_ulogic is
    begin
        if L then
            return('1');
        else
            return('0');
        end if;
    end function To_Std_Logic;

Kevin Jennings

Thanks for your response.It was very helpfull
 
Ad

Advertisements

Joined
Feb 2, 2021
Messages
1
Reaction score
0
No, you don't have to do it in a process with an IF statement or a function. There is a more elegant approach:

Some_std_logic_signal <= '1' when boolean_true else '0'; -- Where "Boolean" is a boolean variable or equation

Here are a couple of examples

CR_INTERLOCK <= '1' when crState = cr_s1a or
crState = cr_s1 or
crState = cr_s2a or
crState = cr_s2
else '0';

And

currentColumnUp <= '1' when outputState = output_s3 or
(spaceState = space_s3 and latchedSpace = '1')
else '0';

Indeed this works in an even more generalized way, and is not restricted to a std_logic output - here is an example of an Integer output:

R5Motion <= 5 when PW_CONS_PRINTER_R5_SOLENOID = '0' else 0;

JRJ
 

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

Top