User manual

DSM tutorials
while (1)
{
par
{
/*
* Increment up to 15, then wrap round to 0
*/
Count++;
/*
* Write Count and (Count[2:0] @ 0) to display
*/
PalSevenSegWriteDigit (PalSevenSegCT (0), Count, 0);
PalSevenSegWriteDigit (PalSevenSegCT (1), Count[2:0] @ 0, 0);
}
}
The
@ operator joins together two operands to form a result whose width is equal to the sum of the
operand widths. In this case that means the
adju() macro does not need to be called, as three bits are
selected from
Count, and DK will infer that the concatenated zero should be one bit wide, giving the
required total of four bits.
The value of
Count is shown on the first 7-segment display, while the second display shows the value of
the low three bits of
Count with zero concatenated at the right. The result is that while the first display
counts once from 0 to 0xF, the second counts 0, 2, 4, 6, 8, A, C, E twice, as shown in the table below.
Count 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Display 1 0 1 2 3 4 5 6 7 8 9 A B C D E F
Count[2:0]@0 0000 0010 0100 0110 1000 1010 1100 1110 0000 0010 0100 0110 1000 1010 1100 1110
Display 2 0 2 4 6 8 A C E 0 2 4 6 8 A C E
CONCATENATE EXAMPLE DISPLAY VALUES
4.1.4 Using signals
Signal variables can be assigned to and read from in the same clock cycle. They hold their value ONLY
for that clock cycle.
The
signalexample project in the TutorialHCBasics workspace contains the source code shown below. This
sets a signal equal to the value of
Count1 + 1, then uses this signal in two separate places, to set
counters used to drive the two 7-segment displays. Although this example is very simple, it illustrates
how signals can be used to eliminate common sub-expressions, and make code more readable.
www.celoxica.com
Page 52