Creating Nets Instancing the Diode

Instancing the Push Button Switch

Now we move onto device instances. These take place after the 'begin' keyword in a design declaration.

design LED_Dice is
   
begin
   
   <Device Instances Go Here!>
   
end design LED_Dice;

The basic syntax is the word 'inst' followed by the name of the instance followed by the keyword 'of,' the name of the device being instanced, and the keyword 'is.' Then you are free to add attribute delcarations or modifications and pin connections after the keyword 'is.' The device instance is terminated with the keyword 'end' (optionally followed by the keyword 'inst' and optionally followed by the name of the instance) and lastly a semicolon.

The basic structure of the push button switch device instance looks like this:

inst mySW of PBSwitch is
   
end inst mySW;

This would not compile unfortunately, since PBSwitch has pins that haven't been wired up. Recall that the device declaration for PBSwitch looked like this:

device PBSwitch is
   attr refPrefix = "SW";
   attr pkg_type = "th_pbswitch20";
   pin off_a = {1};
   pin off_b = {3};
   pin on_a = {2};
   pin on_b = {4};
end device PBSwitch;

There are four pins that need to be hooked up-- namely "off_a," "off_b," "on_a," and "on_b." However, when the switch is in the off position, nothing should happen, meaning that those respective pins shouldn't be hooked up to anything.

Let's look at the significant nets hooked up to the switch.

As we can see, the switch's "on" pins are connected to the "+5V" and "SD_junct" nets. The new device instance would therefore look like the following:

inst mySW of PBSwitch is
    on_a = +5V;
    on_b = SD_junct;
end inst mySW;

Great! We're done, right?

Sorry, but the compiler will still throw an error with this code. There are two pins that haven't been hooked up yet! "But," you protest, "the 'off' pins don't need to be hooked up to anything!" You're right, but PHDL tries very hard to make sure you don't make any passive mistakes. In other words, you can't just leave pins open-- you must declare them as such. This is done using the keyword 'open' as shown below:

inst mySW of PBSwitch is
    on_a = +5V;
    on_b = SD_junct;
    off_a = open;
    off_b = open;
end inst mySW;

There we go! Now we've create a Push Button Switch and hooked it up to the board! Congratulations; you are that much closer to completing your board! Let's go ahead and instance another device.


Creating Nets Instancing the Diode