array of records

S

Salvatore Callea

Hallo,
I've a little trouble with vhdl and I hope some one
would help me.
I've an array of records, such as:


type pulse_timing is record
delay : time;
width : time;
end record;

type pulse_generator is array (1 to 2) of pulse_timing;


How can I initialise it?
I've tried through a constant:


constant TG : pulse_generator(1 to 2) := (
( 6 ns, 50 ns),
(31 ns, 10 ns)
);


but it doesn't work properly.
Can anybody suggest to me how to proceed?

Thanks in advance.
Salvatore
 
E

Egbert Molenkamp

Salvatore Callea said:
Hallo,
I've a little trouble with vhdl and I hope some one
would help me.
I've an array of records, such as:


type pulse_timing is record
delay : time;
width : time;
end record;

type pulse_generator is array (1 to 2) of pulse_timing;


How can I initialise it?
I've tried through a constant:


constant TG : pulse_generator(1 to 2) := (
( 6 ns, 50 ns),
(31 ns, 10 ns)
);


but it doesn't work properly.
Can anybody suggest to me how to proceed?

The array is declared as a constrained array. But in the constant
declaration you try to handle it as un uncontrained array.

Solutions:
1)
type pulse_generator is array (natural array <>) of pulse_timing;
constant TG : pulse_generator(1 to 2) := ( ( 6 ns, 50 ns), (31 ns, 10
ns) );

or
2)
type pulse_generator is array (1 to 2) of pulse_timing;
constant TG : pulse_generator := ( ( 6 ns, 50 ns), (31 ns, 10 ns) );

Egbert Molenkamp
 
K

Kris Van Aken

Salvatore said:
Hallo,
I've a little trouble with vhdl and I hope some one
would help me.
I've an array of records, such as:


type pulse_timing is record
delay : time;
width : time;
end record;

type pulse_generator is array (1 to 2) of pulse_timing;


How can I initialise it?
I've tried through a constant:


constant TG : pulse_generator(1 to 2) := (
( 6 ns, 50 ns),
(31 ns, 10 ns)
);


but it doesn't work properly.
Can anybody suggest to me how to proceed?

Thanks in advance.
Salvatore

Not all synthesis tools support record initialization using aggregates, as you
are doing. You could try named association:

constant TG : pulse_generator(1 to 2) := (
(delay => 6 ns, width => 50 ns),
(delay => 31 ns, width => 10 ns)
)

If that doesn't work, the following strategy can be used:
Create a function, taking two time arguments and returning a record of type
pulse_timing that is initialized using the arguments:

function pulse_timing_init(delay: time;
width: time) return pulse_timing is
variable Result: pulse_timing;

begin

Result.delay := delay;
Result.width := width;
return Result;

end pulse_timing_init;

Then you can initialize the array using the function:

pulse_generator := (pulse_timing_init(6 ns, 50 ns), pulse_timing_init(31 ns, 10
ns));

You could of course also define a constant that is initialized using the same
strategy.

Hope this works for you.

Regards,
Kris
 
E

Egbert Molenkamp

Egbert Molenkamp said:
Solutions:
1)
type pulse_generator is array (natural array <>) of pulse_timing;
this should be: ... (natural RANGE <>) ...
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top