2. Start a New Project



Create a new project and add a module with a relevant interface based upon the summary written above. As with the previous two shift register modules, a register is required to store the current state of the counter between events. Because our output is 8-bits wide, so will our internal register.

Now that we have a module framework, including the internal registers, it is time to determine how the inputs interact with the internal registers and the output. So what do we want the design to do? Try this sentence...

On the rising edge of the signal from the Button, if the control signal from the slide switch is '1' then the number stored in the register takes the value of the number stored in the register plus one. Else then the number stored in the register takes the value of the number stored in the register minus one.

See if you can translate this into HDL. Note that to add 1 to a number you can just use "Value <= Value + 1;" and similarly to subtract you can use "Value <= Value - 1;".



HINT 1

On the 'rising edge (see posedge)' of the signal from the Button, 'if' the control signal from the slide switch is '1' then the number stored in the register takes the value of the number stored in the register plus one. 'else' then the number stored in the register takes the value of the number stored in the register minus one.



You will need one always@(...) statement as well as an if statement with two different signal assignments, one for if the control signal is true (1) and one for if it is false (0).



And Finally...

After you have written your conditional synchronous logic (that is the 'if' and 'else' syntax within an always@(...) statement that utilises a clock), you now need to write one last piece of code to tie the output to the register using an 'assign' statement. You should be now very familiar with this. As a side note, the condition logic (e.g. inside the 'if' statement condition), can be written in a number of ways. So far you have only seen one of them.

if("Some 1-bit signal")

. . . . . do something

else

. . . . . do something else

However, all that is requires is a Boolean expression (true or false), which can be created through various methods, such as:

if( "Something" == "SomthingElse" )

if( "Something" > "SomthingElse" )

if( "Something" >= "SomthingElse" )

if( "Something" ~= "SomthingElse" )

if( ~"Something" )

Each of the statements inside the brackets is reduced to a true or false, which is then used by the 'if' syntax.

Finally synthesise your design and look at the RTL schematic. You will notices that as you start to build more complicated ciruits, the RTL schematic becomes much more useful, as it maintains the hierarchy of you design and therefore doesn't sprawl over multiple pages as much.

Additionally, as you will see with this design, the RTL schematic infers more complex components (in this case an up/down counter), whereas the Technology schematic will use the FPGA primitive components.