User manual
Tutorial: Handel-C and VGA graphics output
static unsigned 1 Test = 1;
unsigned 8 a;
unsigned 32 b, c, d;
while (Test == 1)
{
par
{
a++;
Test = ((b * c) + d) > (d - b);
}
}
6.2.3 Avoiding combinatorial loops
A combinatorial loop is a series of logic components connected in a loop with no latches or delay
elements inserted. Combinatorial loops are typically generated from
if() statements and while()
loops in Handel-C, as shown in the example code below:
while (Wait == 1)
{
a = 0;
}
if (Wait == 1)
{
a = 0;
}
The
while() loop shown can generate a combinatorial loop as it may take zero cycles to execute.
Similarly, the
if() statement could take zero or one cycle to execute, depending on the value of Wait.
Code which causes combinatorial loops is bad for two reasons:
• The number of cycles to execute the code at runtime is unclear, making the design difficult.
• As the code could take zero cycles to execute, the Place and Route tools will assume the
worst case when calculating the maximum clock rate, which will be the time taken to
execute the
if() or while() condition added to the time taken to execute the following
line of code.
To avoid these problems for
while() loops, ensure that they always take at least 1 cycle to execute, by
carefully selecting the condition or by using
do...while() instead. For if() statements, always
include an
else block which takes at least 1 cycle to execute, as shown below:
if (Wait == 1)
{
a = 0;
}
else
{
delay;
}
Note that this also applies to
switch() statements where a default case should always be included,
even if it only contains a single
delay statement.
www.celoxica.com
Page 76