Thursday, June 25, 2015

Building your own Computer with NAND gates

Have you ever wondered how our computers works, how they display colorful graphics and let us play some awesome games. What are those tiny black things inside my laptop?

Recently I came across an online course on building your own computer starting with NAND gates.
Ok, then What is NAND gates? Well NAND gates are basic building block for any digital device ex- Laptops, Mobiles, Camera and many other devices.

Ok, then how to make NAND gates? NAND gates are made using even smaller components called as Transistor, they are like switch which can be turned ON and OFF, but by flowing a small current through them not the we have traditional tick tack type switches.

Ok, so you are telling me that everything is made from Transistors? Yess you got it.. every digital device is made from Transistors.

So, lets talk about that course. The name of the course is nand2tetris in which we have to make our own computer and run own softwares all starting with simple NAND gates. There is also a course on coursera by the same professors with video lectures. I think is worth to see once that site and course for every engineer who is interested in computers and digital devices.

So, I decided to write my own blog on how to build our own computer. This is just a guide for people to help and share whatever i learnt using that course. I will follow materials from there and build my own HACK computer using the resources provided on nand2tetris website.

Though there is no pre-requisite for this course but, I think if you have taken any course on Digital Circuits or Basic Electronics, It will be easier to follow up the course.

The course goes like this:

  • First Project: Simple Gates and Computational Logic like AND, OR, NOT, Muxes and DeMuxes.
  • Second Project: Adders, Incrementer and full ALU.
  • Third Project: Memory elements like Registers and RAMs.
  • Fourth Project: Machine Language Programming i Assembly.
  • Fifth Project: Combining everything you made in First Second and Third project to full functional CPU.
  • Sixth Project: Writing an Assembler Program to translate code written in Fifth project to Machine Code which your CPU will understand. 

Then there are more projects which i will discuss in future blogs. I will start with building our simple gates in next blog. Thanks for reading please have a look at nand2tetris website.

Saturday, June 13, 2015

Computer Vision - SURF Feature Extraction and Object Tracking using MATLAB

I am currently working on a Mobile robot which will use Vision based Navigation for automatically finding Charging spots when the battery is low and get attached to itself.

For this task first the steps are broken down into following pieces:

  • Taking a number of reference images of the object to be detected. (For checking purpose of my code i took a "POW"(power) written on a notebook and tracking those characters. Depending on the location of "POW" in the image, i will generate the control command for the robot, whether it should go left or right and by how much amount using PID controller.) 


  • Detection and Extraction of SURF features (which is faster version of SIFT features) from the reference images and making a feature vector by stacking features from different reference images. In my case, I have only taken a single reference image shown below but you take multiple images and create the feature vector.
  • Detection and Extraction of SURF features from the images captured from camera in real-time.
  • Matching of those features using different algorithms. In MATLAB, there is only one feature matching function which is very robust, but if you using openCV, you can go for Brute-Force Matcher of FLANN based matcher. I have done this same thing in openCV. If anyone want the code using openCV, comment below in comment section.
  • Depending on the matched feature, Calculate centroid of the "POW" symbol and if the symbol is right half plane, generate right command to the motor otherwise left command.
The MATLAB code is embedded below,


Here is a working demo of my code:

For any suggestion, comment below. Thanks!


Friday, January 09, 2015

Arduino 101 - Blinking LED using Arduino

This tutorial is for the beginners who have just bought a arduino and want to start using it. Just like while learning programming we start with a simple program of Hello World!, in embedded systems we start by blinking an led. Before we start i want to give a brief introduction of how a arduino program or sketch looks like? For writing and uploading sketch to arduino you will need arduino IDE which can be downloaded from here

Arduino Sketch:

Every arduino program also called as sketch has 2 parts:
  1. Initialization Part : Where we define things and initialize any arduino peripheral like Serial or USB Connection and Input / Output Port.
  2. Infinite Loop : After initialization is complete there is a infinite loop in which arduino runs till it is not reset or switched off.
If things are not clear, after you will see the code below, i hope everything will be clear.

Code for Blinking Led: 


Some Explanation of Code: 

The two parts discussed above are implemented in code as setup() function and loop() function. In arduino led is connected to pin number 13 so we name a variable ledPin for our convenience.

The setup() block runs only once and initializes all the peripherals and assignments. Then the pinMode(pinNumber, direction) function assigns the mode of pin, (in our case pin number 13 or ledPin) as OUTPUT, because we want to output high or low voltage level so that our led lights up. If you are reading the voltage level of the pin then you have to choose the  direction as INPUT.

Now, the loop() function block, this block runs continuously till the reset or power off of the board. In this block there are two functions digitalWrite(pinNumber, Value) and delay(milliseconds). digitalWrite(pinNumber, Value) writes value (either LOW or HIGH) to the pinNumber and delay(milliseconds) is used to give accurate time delays between any two sequence of instruction.

Now upload this code using Arduino IDE to Arduino Board and you will see the led light blinking at an interval of 1sec.