I'm starting a new project so I need to come up the learning curve again. I always forget details of the language when I don't use it for some time.ends of the statement.
I think I'm not so much not remembering something that is in the language as it is I'm thinking of something that's NOT in the language, but I wish it were. I'm probably mixing my poor recollection of C with my poor recollection of VHDL.
VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
I can do what I want to do using when and else, but they tend to make the line more crowded, so if the expression is a bit wordy (what isn't in VHDL) it runs onto two lines. I also don't like the syntax which spreads the two alternatives to opposite
The syntax I'm remembering is something like
A <= condition ?? X : Y
I think this is the C construct. I just have this image in my mind of this being trotted out as a new VHDL feature, or something like it.
So someone tell me I'm totally misremembering it. I've dug the Internet and not found any gold. I'm pretty sure I would have found it if it were there.
Or is there a conversion for boolean to std_logic? I seem to remember searching that the other day and finding nothing other than examples of your own conversion function.
On 08/09/2020 03:44:30, Rick C wrote:ends of the statement.
I'm starting a new project so I need to come up the learning curve again. I always forget details of the language when I don't use it for some time.
I think I'm not so much not remembering something that is in the language as it is I'm thinking of something that's NOT in the language, but I wish it were. I'm probably mixing my poor recollection of C with my poor recollection of VHDL.
VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
I can do what I want to do using when and else, but they tend to make the line more crowded, so if the expression is a bit wordy (what isn't in VHDL) it runs onto two lines. I also don't like the syntax which spreads the two alternatives to opposite
The syntax I'm remembering is something like
A <= condition ?? X : Y
I think this is the C construct. I just have this image in my mind of this being trotted out as a new VHDL feature, or something like it.
So someone tell me I'm totally misremembering it. I've dug the Internet and not found any gold. I'm pretty sure I would have found it if it were there.
Or is there a conversion for boolean to std_logic? I seem to remember searching that the other day and finding nothing other than examples of your own conversion function.
That works for C. I presume you're looking for something like this?
For VHDL
s <= waveform_1 when condition_1 else
waveform_2 when condition_2 else
...
waveform_n;
As per:
https://www.ics.uci.edu/~alexv/154/VHDL-Cookbook.pdf
In a process it would be more usual to use an if statement
On Tuesday, September 8, 2020 at 8:36:14 AM UTC-4, Mike Perkins wrote:..
On 08/09/2020 03:44:30, Rick C wrote:
..VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
Yeah, I'm trying to make this construct a simple one line piece of code. For the time being I've created a function:
function b_to_sl (X : boolean) return std_logic is begin
if X then return '1'; else return '0'; end if; end b_to_sl;
On 08/09/2020 14:35, Rick C wrote:
On Tuesday, September 8, 2020 at 8:36:14 AM UTC-4, Mike Perkins wrote:..
On 08/09/2020 03:44:30, Rick C wrote:
..VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
Yeah, I'm trying to make this construct a simple one line piece of code. For the time being I've created a function:
function b_to_sl (X : boolean) return std_logic is begin
if X then return '1'; else return '0'; end if; end b_to_sl;
I hit exactly the same issue many years ago and a VHDL guru's called
Tricky (if I remember correctly) suggested to use simple functions. Like most VHDL engineers I now have a package with lots of helper functions I collected over the years. Here is a good site with lots of conversion functions:
https://www.nandland.com/vhdl/tips/tip-convert-numeric-std-logic-vector-to-integer.html
However, the reason for replying is that I also tried to use the ??
operator recently and failed to make it work, I had something like:
if (?? (OR slvarray(1 downto 0)) OR (a > b)) then..
however, to make it work you need extra brackets as in :
if ((?? (OR slvarray(1 downto 0))) OR (a > b)) then..
Or to simplify, you need (??(non_boolean))
Apparently this is described in section 9.2.9 of the 1076-2008 LRM but I just added the brackets and moved on with life.....
I am sure somebody with more VHDL knowledge can explain why the extra (non-obvious) brackets are required.
Hans
www.ht-lab.com
On Tuesday, September 8, 2020 at 8:36:14 AM UTC-4, Mike Perkins wrote:ends of the statement.
On 08/09/2020 03:44:30, Rick C wrote:
I'm starting a new project so I need to come up the learning curve again. I always forget details of the language when I don't use it for some time.
I think I'm not so much not remembering something that is in the language as it is I'm thinking of something that's NOT in the language, but I wish it were. I'm probably mixing my poor recollection of C with my poor recollection of VHDL.
VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
I can do what I want to do using when and else, but they tend to make the line more crowded, so if the expression is a bit wordy (what isn't in VHDL) it runs onto two lines. I also don't like the syntax which spreads the two alternatives to opposite
input signal and make everything from that point on high true to keep the logic easier to read.
The syntax I'm remembering is something like
A <= condition ?? X : Y
I think this is the C construct. I just have this image in my mind of this being trotted out as a new VHDL feature, or something like it.
So someone tell me I'm totally misremembering it. I've dug the Internet and not found any gold. I'm pretty sure I would have found it if it were there.
Or is there a conversion for boolean to std_logic? I seem to remember searching that the other day and finding nothing other than examples of your own conversion function.
That works for C. I presume you're looking for something like this?
For VHDL
s <= waveform_1 when condition_1 else
waveform_2 when condition_2 else
...
waveform_n;
As per:
https://www.ics.uci.edu/~alexv/154/VHDL-Cookbook.pdf
In a process it would be more usual to use an if statement
Yeah, I'm trying to make this construct a simple one line piece of code. For the time being I've created a function:
function b_to_sl (X : boolean) return std_logic is begin
if X then return '1'; else return '0'; end if; end b_to_sl;
Called thusly:
Spkr_Blip <= b_to_sl(Button_Press(I) = Buttons_Past(I));
It just seems something like b_to_sl should/could be part of the language or a standard library. I noticed when I google searched on it, there was no shortage of others asking the same question.
The above test is checking for a change in the button state. The input is Buttons which is low true so Buttons_Past is low true while Button_Press is the debounced version and high true. I think I should add Buttons_ht, a high true version of the
On 2020-09-08 08:35, Rick C wrote:opposite ends of the statement.
On Tuesday, September 8, 2020 at 8:36:14 AM UTC-4, Mike Perkins wrote:
On 08/09/2020 03:44:30, Rick C wrote:
I'm starting a new project so I need to come up the learning curve again. I always forget details of the language when I don't use it for some time.
I think I'm not so much not remembering something that is in the language as it is I'm thinking of something that's NOT in the language, but I wish it were. I'm probably mixing my poor recollection of C with my poor recollection of VHDL.
VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
I can do what I want to do using when and else, but they tend to make the line more crowded, so if the expression is a bit wordy (what isn't in VHDL) it runs onto two lines. I also don't like the syntax which spreads the two alternatives to
input signal and make everything from that point on high true to keep the logic easier to read.
The syntax I'm remembering is something like
A <= condition ?? X : Y
I think this is the C construct. I just have this image in my mind of this being trotted out as a new VHDL feature, or something like it.
So someone tell me I'm totally misremembering it. I've dug the Internet and not found any gold. I'm pretty sure I would have found it if it were there.
Or is there a conversion for boolean to std_logic? I seem to remember searching that the other day and finding nothing other than examples of your own conversion function.
That works for C. I presume you're looking for something like this?
For VHDL
s <= waveform_1 when condition_1 else
waveform_2 when condition_2 else
...
waveform_n;
As per:
https://www.ics.uci.edu/~alexv/154/VHDL-Cookbook.pdf
In a process it would be more usual to use an if statement
Yeah, I'm trying to make this construct a simple one line piece of code. For the time being I've created a function:
function b_to_sl (X : boolean) return std_logic is begin
if X then return '1'; else return '0'; end if; end b_to_sl;
Called thusly:
Spkr_Blip <= b_to_sl(Button_Press(I) = Buttons_Past(I));
It just seems something like b_to_sl should/could be part of the language or a standard library. I noticed when I google searched on it, there was no shortage of others asking the same question.
The above test is checking for a change in the button state. The input is Buttons which is low true so Buttons_Past is low true while Button_Press is the debounced version and high true. I think I should add Buttons_ht, a high true version of the
VHDL2008 contains functions to do comparisons of std_logic, which would normally return a Boolean result, but return a std_logic result.
From the 2008 IEEE std_logic_1164.vhdl package source file:
-- the following operations are predefined
-- function "?=" (l, r : STD_ULOGIC) return STD_ULOGIC;
-- function "?=" (l, r : STD_ULOGIC_VECTOR) return STD_ULOGIC;
-- function "?/=" (l, r : STD_ULOGIC) return STD_ULOGIC;
-- function "?/=" (l, r : STD_ULOGIC_VECTOR) return STD_ULOGIC;
-- function "?<" (l, r : STD_ULOGIC) return STD_ULOGIC;
-- function "?<=" (l, r : STD_ULOGIC) return STD_ULOGIC;
-- function "?>" (l, r : STD_ULOGIC) return STD_ULOGIC;
-- function "?>=" (l, r : STD_ULOGIC) return STD_ULOGIC;
Charles Bailey
On Tuesday, September 8, 2020 at 11:21:54 AM UTC-4, HT-Lab wrote:
On 08/09/2020 14:35, Rick C wrote:
On Tuesday, September 8, 2020 at 8:36:14 AM UTC-4, Mike Perkins wrote:..
On 08/09/2020 03:44:30, Rick C wrote:
..VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
Yeah, I'm trying to make this construct a simple one line piece of code. For the time being I've created a function:
function b_to_sl (X : boolean) return std_logic is begin
if X then return '1'; else return '0'; end if; end b_to_sl;
I hit exactly the same issue many years ago and a VHDL guru's called
Tricky (if I remember correctly) suggested to use simple functions. Like
most VHDL engineers I now have a package with lots of helper functions I
collected over the years. Here is a good site with lots of conversion
functions:
https://www.nandland.com/vhdl/tips/tip-convert-numeric-std-logic-vector-to-integer.html
However, the reason for replying is that I also tried to use the ??
operator recently and failed to make it work, I had something like:
if (?? (OR slvarray(1 downto 0)) OR (a > b)) then..
however, to make it work you need extra brackets as in :
if ((?? (OR slvarray(1 downto 0))) OR (a > b)) then..
Or to simplify, you need (??(non_boolean))
Apparently this is described in section 9.2.9 of the 1076-2008 LRM but I
just added the brackets and moved on with life.....
I am sure somebody with more VHDL knowledge can explain why the extra
(non-obvious) brackets are required.
Hans
www.ht-lab.com
Can't say for sure, but likely it's a matter of precedence. The second OR tries to operate on the boolean and the std_logic from the first OR before the ?? has had a chance to do its thing. The extra set of parenthesis set the order straight.
On 08/09/2020 19:03, Rick C wrote:
On Tuesday, September 8, 2020 at 11:21:54 AM UTC-4, HT-Lab wrote:
On 08/09/2020 14:35, Rick C wrote:
On Tuesday, September 8, 2020 at 8:36:14 AM UTC-4, Mike Perkins wrote: >>>> On 08/09/2020 03:44:30, Rick C wrote:..
..VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
Yeah, I'm trying to make this construct a simple one line piece of code. For the time being I've created a function:
function b_to_sl (X : boolean) return std_logic is begin
if X then return '1'; else return '0'; end if; end b_to_sl;
I hit exactly the same issue many years ago and a VHDL guru's called
Tricky (if I remember correctly) suggested to use simple functions. Like >> most VHDL engineers I now have a package with lots of helper functions I >> collected over the years. Here is a good site with lots of conversion
functions:
https://www.nandland.com/vhdl/tips/tip-convert-numeric-std-logic-vector-to-integer.html
However, the reason for replying is that I also tried to use the ??
operator recently and failed to make it work, I had something like:
if (?? (OR slvarray(1 downto 0)) OR (a > b)) then..
however, to make it work you need extra brackets as in :
if ((?? (OR slvarray(1 downto 0))) OR (a > b)) then..
Or to simplify, you need (??(non_boolean))
Apparently this is described in section 9.2.9 of the 1076-2008 LRM but I >> just added the brackets and moved on with life.....
I am sure somebody with more VHDL knowledge can explain why the extra
(non-obvious) brackets are required.
Hans
www.ht-lab.com
Can't say for sure, but likely it's a matter of precedence. The second OR tries to operate on the boolean and the std_logic from the first OR before the ?? has had a chance to do its thing. The extra set of parenthesis set the order straight.
I am not sure, from what I know ?? is just an overloaded function so
??() should be resolved before OR which has the lowest precedence,
Regards,
Hans.
On Wednesday, September 16, 2020 at 3:04:59 AM UTC-4, HT-Lab wrote:
On 08/09/2020 19:03, Rick C wrote:
On Tuesday, September 8, 2020 at 11:21:54 AM UTC-4, HT-Lab wrote:
On 08/09/2020 14:35, Rick C wrote:
On Tuesday, September 8, 2020 at 8:36:14 AM UTC-4, Mike Perkins wrote: >>>>>> On 08/09/2020 03:44:30, Rick C wrote:..
..VHDL has a ?? operator that converts a std_logic or bit value to Boolean. It took me a while to realize I'm looking for something that does the opposite, converts a Boolean to a std_logic value.
Yeah, I'm trying to make this construct a simple one line piece of code. For the time being I've created a function:
function b_to_sl (X : boolean) return std_logic is begin
if X then return '1'; else return '0'; end if; end b_to_sl;
I hit exactly the same issue many years ago and a VHDL guru's called
Tricky (if I remember correctly) suggested to use simple functions. Like >>>> most VHDL engineers I now have a package with lots of helper functions I >>>> collected over the years. Here is a good site with lots of conversion
functions:
https://www.nandland.com/vhdl/tips/tip-convert-numeric-std-logic-vector-to-integer.html
However, the reason for replying is that I also tried to use the ??
operator recently and failed to make it work, I had something like:
if (?? (OR slvarray(1 downto 0)) OR (a > b)) then..
however, to make it work you need extra brackets as in :
if ((?? (OR slvarray(1 downto 0))) OR (a > b)) then..
Or to simplify, you need (??(non_boolean))
Apparently this is described in section 9.2.9 of the 1076-2008 LRM but I >>>> just added the brackets and moved on with life.....
I am sure somebody with more VHDL knowledge can explain why the extra
(non-obvious) brackets are required.
Hans
www.ht-lab.com
Can't say for sure, but likely it's a matter of precedence. The second OR tries to operate on the boolean and the std_logic from the first OR before the ?? has had a chance to do its thing. The extra set of parenthesis set the order straight.
I am not sure, from what I know ?? is just an overloaded function so
??() should be resolved before OR which has the lowest precedence,
Regards,
Hans.
I don't think being overloaded affects the priority. Why do you say OR is lower than ??...
Turns out ?? is hard to search on. In Google it is treated as nothing at all. Bing will return proper results on just ??, but not on VHDL ?? or even VHDL "??" . Go figure.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 82:03:16 |
Calls: | 6,658 |
Calls today: | 4 |
Files: | 12,203 |
Messages: | 5,333,417 |
Posted today: | 1 |