Oct 18, 2010

National Instrument - MultiSim - Component details

Hi,

Suggested by Rajesh today, I tried to opt out of using Xilinx, which is too much troublesome (for me at least) and use MultiSim (from National Instrument) instead. By far, it has been much more reliable than Xilinx, with just a little problem when started learning (due to the vast component library).


The software can be downloaded at
https://lumen.ni.com/nicif/us/academicevalmultisim/content.xhtml

Here, I will try to document the components and their usage, hope it serves as a good start.
Also, you may want to refer to this getting started tutorial:
http://www.mediafire.com/?2956aws7pekd20p



Here is the list of components (plz note that the name in bold is the comprehensive one that I give it)
The format will be:



<Component name>
Component Image


Purpose: <Usage of this component>
Group: <Group>
Family: <Family>
Component: <Component Name>
Component value list
  • <Value 1>: <Usage 1>
  • <Value 2>: <Usage 2>
  • ...
  • <Value n>: <Usage n>

List


Selection Switch
Purpose: To Select between two different value, interactively. This correspond to a physical switch.
Group: Basic
Family: Switch
Component: SPDT
Component value list
  • Key for toogle: During simulation, you can toggle between the two values by pressing the key specified here. In this example, pressing "Space" will toggle the switch


VCC


Purpose: 5 Volt Vcc Logic
Group: Sources
Family: Power_Sources
Component: VCC
Component value list: None



Dip Switch Pack


Purpose: Used to toggle voltage input
Group: Basic
Family: Switch
Component: DSWPK_X where X is the number of switches
Component value list
  • Switch 1 key: Toggle switch no.1
  • Switch 2 key: Toggle switch no.2
  • ...
  • Switch X key: Toggle switch no.X
 There is a need for explanation here, as it took me half an hour figuring out the operation of the switches here.
Basically, to perform our desired function, you can't simply connect Vcc and the switch. Since when you turn it OFF (disconnecting the input from the output), you make the ouput become FLOATING (not connected to any electrical sources, and this is not a good thing to do in circuit design).

by connecting the switch with a resistor, you created this schematic:
When the switch is turn ON, pin 1 is connected to Ground, hence, it output 0V
When the switch is turn OFF, pin 1 is connected toVcc via the resistor. Normall, there will be a voltage drop and V1 will be less than Vcc. However, if we choose the resistor to be that of high-impedance (high resistance), the current - as derived form Ohm's law - will be very small. Hence, voltage drop is negligible and V1 is approximately equal to Vcc.

    Oct 14, 2010

    Facade pattern in GUI design

    Today's post will be about Facade pattern and its application in GUI programming.


    I would assume that you guys have already know about GUI basic, like event handling (basically, it's a method that is invoked when something happen to the GUI, either by you or by God, haha). Also, if you have tried to integrate several UI (not just GUI, but include TextUI, mobile apps UI...) for your logic classes, you might see that's it is quite trouble some to keep calling methods in Logic from your GUI.
    If you happen to do so, you might end up with something like this:

    <Sr for the hand writing :P> Basically, each of  TextUI and GUI's event handler A and B is calling method A and B in Logic. It's a bit wrong, technically, since TextUI don't normally have handler.
    This is only for 2 UI classes. imagine i you have more: mobile Apps, Web interface, embedded system interface... if you implement it this way, you will have to write the calling code again and again. Plus, if you change your Logic, then the whole code in UI classes have to change. Plus, your UI have to "know" the structure of Logic class, which is considered a bad design in software.

    Instead, people have proposed a design pattern, called Facade pattern.

    A "facade" class will be made and you will be calling methods in that facade class. then, the facade class will call Logic, get result and return it ot UI.
    It won't shorten much of your work, though. You still have to make a call from UI to facade class and back, but it is helpful since your UI only know about the facade, which acts more or less like an API (correct me if I am wrong here :D). Then UI doesn't of whatever happen in Logic, or even if there is a Logic class at all. This will reduce your load when modifying code inside.


    Basicall, it the new structure will be

    <again, hand writing :P> now, event handler in TextUI and GUI will call methods from facade class, then facade class will call logic. So, if by any chance you need to modify your internal logic w/o changing API, you can do it freely. UI classes now only know up to facade class and no more.
    It will be a good design :D

    If you only have 2 class, then you can also consider splitting the facade in half:
    GUI will have a method that receive info from Logic, then checking that info and distribute to respective UI methods
    Logic will also have a method receiving info from UI, checking it and call appropriate logic methods
    Logic and UI will also have a method that sends info to the other class. This method will be invoked each time info need to be passed.
    Logic and UI will only be communicating through these broadcaster and listener methods

    This is, in my opinion, not a recommended approach though :P but it's fast.

    That's all for today :)

    Sep 7, 2010

    Put your C++ code into directory in Visual Studio

    Wow, finally, I found the way to put C++ codes into different folder, as well creating and managing those folders in Visual Studio.

    Before, all I have been doing is creating .cpp and .h files in the same root folder (where all your codes goes) and assign them to created filters. This, however, become an disadvantage when I switch from writing small program on my own to teamwork for my projects.

    A filter in Visual C++ is, basically, a filter. It is not a directory that you put your code files into but rather some kind of "tag" that help you identify your code file. This makes your project cumbersome when you want to put the files into folders, each with a purpose (like Project\Logic, Project\GUI, etc)


    Okay, that's enough of the chit chat, now let's do it



    Show All Files
    First, from the Solution Explorer (left side of the window by default / View-Solution Explorer / Ctrl + Alt + L ), click the "Show all files" button.
    Solution explorer with directory
    After that, you should see something like this panel. All the folders in your project will be displayed here. By default, there will be one folder called Debug (for temporary compiled files during debugging process) and another folder with the name of your project (SRS_HK for my case).
    All you files should also be listed according to the directory they belong.
    You can press the "+" / "-" button to expand, collapse your directories.

    Finally, you can add in folder and files by right-click, Add -> New Folder / New Item




    Of course, putting your files to folders requires some modification to the #include command. For example, you have to use
    #include "SRS_HK\SimpleException_HK.h" 
    to include the header file now.

    Hope it helps :)

    Aug 31, 2010

    OMG - VIM

    Yup, today is the day I started liking VIM
    =)

    This is kinda funny though, as my previous experience with Visual Studio is much much better than using VIM, but somehow, it just feel right.

    Actually, I think that there is something in VIM that all programmer like: the ability to NOT follow convention. Surely, navigating with H, J, K, L is difficult, but why follow everyone else and use arrow key =)). After all, they are just conventions, not compulsory!

    Nevertheless, I should start posting something about coding here:

    This is an old habit of mine ever since I use Windows: CTRL - S to save.
    In VIM, this actually makes the program hangs. However, according to the developers, this only "stop the data from arriving so that you can stop a fast scrolling display to look at it" (Refer Here)

    To compensate for that, just do a CTRL - Q.

    This actually helps a lot since I don't have to disconnect from my Unix server in school again :)

    Aug 25, 2010

    Change the Project's Directory & couldn't find "stdafx.h"

    Last time I built a working program with a GUI.
    After that, I saved it, changed the DIRECTORY NAME that it was in ( so, originally, it was in [Original name]/[Original name], but i changed the directory to [New name]/[Original name] ).
    Then, when I go back and run the program again, I got error: 
    fatal error C1093: API call 'ImportFile' failed '0x80070003' : ErrorMessage: The system cannot find the path specified.
    it seems quite impossible, since "stdafx.h" is already there in my project.
    Confused!!!!

    However, after a while, I found some article online and tried to imitate it, and the issue is solved :)
    Here is what I do:
    • Goto Build - Clean Solution
    • Build & Run again
    Hope this help anyone catching it later