Search This Blog

Powered By Blogger

Wednesday, September 18, 2013

So,you want to start learning microcontroller and other embedded stuffs?

Hello guys,
Well...this is a post for newbies in microcontroller world.Here,I didnt mean a complete newbie by the term "newbie".I am neither gonna talk about resistor capacitor and transistors nor what is microcontroller etc.This post is for someone who knows at least what a microcontroller is and wants to start learning it and requires a guide line on how to start.

WELL...you know what a microcontroller is...hmm???okay...thats cool.Now lets talk about how to start.Well...the first thing is to choose a microcontroller family.Well...I dont want to hurt the feelings of the fanboys of other families...but AVR from Atmel and PIC from Microchip are the two best families for newbies currently...its because of the gigantic number of tutorials and example projects you are gonna find online. www.extremeelectronics.co.in is an excellent site for learning both these families,or the winavr.scienceprog.com for AVR.One hint for the first site...their tutorials are kept in reverse order...so for getting the basic tutorials...u need to go to the last page of the tutorials.
Now lets come to another very very important thing...availability of microcontroller and tools.Well...u need a microcontroller and a tool to program it.Now if you are  not confident enough to make your own programming tool or if you havent got someone who can do it for you,I recommend you buy one...for PIC,buy Pickkit2 or 3(2nd one isrecommended).If you cant buy them,look for their clones.I am giving a few links here

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en538340&redirects=pickit3

http://www.ebay.com/sch/i.html?_odkw=usbasp&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313.TR0.TRC0.Xpickit2&_nkw=pickit2&_sacat=0

http://www.ebay.com/sch/i.html?_odkw=pickit2&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313.TR0.TRC0.Xpickit3&_nkw=pickit3&_sacat=0

You can check other sources too.

For AVR,

http://www.ebay.com/sch/i.html?_odkw=pickit3&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313.TR2.TRC1.A0.Xusbasp&_nkw=usbasp&_sacat=0
This little programmer is really cool,but its not their official programmer...but you can use it...In fact,I use it for my work and it works just great

http://www.atmel.com/tools/AVRDRAGON.aspx
This is the official one.

Now...a million dollar question...which one to choose???PIC or AVR...well....u guys wont even believe that this question can trigger World war 3(u will see someday,trust me)!!!Well...I would say...go for any.See which one you can afford(Talking about tool),which one is available in your country,..or which one your friend or known ones are using(this suggestion has been given so that you might get help from them).
Now...both Microchip PIC and Atmel AVR are families,not a single microcontroller.There are hundreds of different models of PIC and AVR microcontrollers...My advice is,decide which one you are gonna use,get to the market and buy one model,any model.But onw thing you must know...for starting,choose from 8bit PIC or AVRs...For AVR,I would suggest ATmega16 or ATmega32(a good general purpose microcontroller).For PIC,go for PIC16F877...these micros are highly available AFAIK.
Now...one thing.you might have heard about another thing,ARDUINO....right?????If you havent,dont try to know about it for now.If you have and your friend told you its extremely easy bla bla bla,Now,for that,I want to ask you a question,
Why do you want to learn microcontroller???Is it just for some university term project?Are you going to wipe off all you microcontroller lessons after that project???or do you want to learn microcontroller and become a professional embedded systems expert in your future life?If the first one is the reason,you can go for ARDUINO...but if the second is the reason,dont even think of getting near it for now.Its an excellent platform that uses several microcontrollers from Atmel AVR family(or Microchip PICs or ARMs in different but similar platforms).Its like a magical tool for rapid prototyping etc. and its highly tempting for newbies as well since its extremely easy to use...but sometimes shortcuts DO come with their side effects.If Arduino is your first choice for "learning", you wont even scratch the surface of this vast embedded systems world.First,learn the basics of AVR or PIC,then you will be able to use an Arduino to its limit.So, for now,forget the word Arduino.Its not for newbies who want to become professional.First learn AVR/PIC,then move to Arduino....the path wont be smooth,but at the end of it there is a huge reward.

Wednesday, June 19, 2013

Arduino...What are you???

Well...here I am again and I am going to take some of your precious time and I am gonna talk about Arduino. Well...there are many people talking about it so you guys might think its another general Arduino project talk where I am gonna show you how easy Arduino is and all that.The answer is a BIG NOOOO!!!
All I am gonna talk about here is what Arduino is and I am gonna answer to some of the common stuffs in a visual way.
SO...NUMBER 1 ... WHAT IS ARDUINO????

Answer:
Arduino IS NOT A NEW microcontroller...its merely AVR
So...this is the image of an ATmega328P sitting on an ARDUINO board.Now you believe it????If you dont,then I have got nothing to say.

NOW...NUMBER 2...WHY DO WE CALL IT ARDUINO THEN?????

Answer:
Well...Arduino is a development board.I am talking about the nice blue boards u see or any other board having the name Arduino or usually any "duino".But I should say its a development platform based on AVR microcontroller...THATS ALL...

NOW...NUMBER 3...YOU KNOW MAN,I KNOW ITS AVR...BUT I HEARD THEY HAVE PUT SOME ALIEN STUFF LIKE BOOTLOADER  INSIDE THE CHIP...IS IT STILL LIKE NORMAL AVRs OR HAS IT BEEN TRANSFORMED BY THE MYSTICAL BOOTLOADER????

Answer:
To be honest...this was my question as well when I was a newbee.But I read about things etc and came to know that the idea of such "Alien Transformation was merely a BULLSHIT".Actually ,this BOOTLOADER STUFF is nothing but a sweet small piece of program which sits in a specified place in the flash memory and its characteristics is....IT STARTS RIGHT AFTER YOU POWER UP YOUR MICROCONTROLLER AND IF THERE IS ANOTHER PROGRAM(YES...I AM NOT INSANE,BOOTLOADER AND SOME OTHER PROGRAM,BOTH CAN FUNCTION WHILE BEING IN THE SAME MICROCONTROLLER FLASH MEMORY),THAT RUNS AFTER THE EXECUITION OF BOOTLOADER.
Alright....so why do we need a bootloader????Well...bootloaders are capable of doing a magical thing.They can make an mcu SELF PROGRAMMABLE!!!!That means this bootloader can get data from some source in some way and put the data into the empty space of mcu's flash memory...so inshort...its capable of putting a SECOND PROGRAM into mcu program memory and THAT SECOND program is the program that you want to put into the mcu(sounds cool!!!)...so if we provide the mcu some way to communicate with a PC or programming source,it can program itself!!!And AVRs in arduino boards come with this bootloader thingy loaded,and the bootloader allows the micro to get program data from its UART(I guess u know what that is)!!!! so we dont need another programmer,just an usb to serial converter or a serial port on pc and any program we use to put our program into the mcu will actually communicate with the mcu via serial port!!! Thats the case of the mystical bootloader!!!

ALRIGHT...NUMBER 3...OK I GET IT...THEN WHY DID THEY MAKE THE WHOLE NEW COMPILER/IDE FOR ARDUINO????WHY ALL THESE TROUBLES?THEY COULD HAVE CREATED JUST A LOADER PROGRAM RIGHT?????

Answer:
Hmm...Now I should tell you the truth....the Arduino guys were trying to create a whole new platform for rapid prototyping.They wanted to create a simple looking interface with vast amount of libraries so that it might become easy for us to do our mcu works fast.So basically what they did is,they used the same good old avr-gcc and avrlibc(WinAVR for windows people) and put some libraries over it and then they designed a simple looking IDE interface(or the Arduino Interface) and integrated everything into one folder called the arduino folder.If you browse through different folders of arduino,u will know that.

So basically general arduino boards come with an USB 2 Serial converter and the target AVR microcontroller with bootloader into it and the IDE simply communicates with the target micro via the usb2 serial converter.

OKAY...OKAY....NUMBER 4...YOU SAID THAT WE BASICALLY USE WINAVR....AM I RIGHT????WELL...I DONT RECALL WRITING ANY pinMode() FUNCTION OR digitalWrite() FUNCTION IN WINAVR COMPILER AND MOREOVER,THE PIN NUMBERS ARE COMPLETELY DIFFERENT?HOW DO YOU EXPLAIN THAT....MHMMM???

Answer:
If you have ever used any C/C++ compiler,then you should be aware of #define.This preprocessor command can make things easy for us in many ways....alright,before I answer to your questions,lets have a look at Arduino UNO pinmapping image:


Okay...this picture also verifies that Arduino is merely AVR...this pinmapping is for Atmega168,almost the same pinout or this pinout is applicable for Atmega328 as well....
Now...look at it...the have created a new set of pinouts by providing a few definitions over the standard AVR pinout...thats all....and those pinMode and digitalWrite functions are either functions or definitions

NOW...a question...can we use the original AVR IO PORT definitons in Arduino compiler????OF COURSE AND YES!!!!!WE CAN!!!We can use almost everything unless its not being used by some arduino library such as timer 0 and etc.


NOW.....the BIG BURNING QUESTION.....CAN I USE ANY COMPILER WITH ARDUINO BOARD????

Answer:
YES,YES AND YES,you can.You can use any avr compiler with arduino...All you need to know is the actual pin numbers since on ardunio board its not written.You can use the picture attached above for atmega168 and for other,simply google the name of your arduino board with the word "pinmapping" at hte end, such as "Arduino Mega 2560 pinmapping" annd you will have the pin map.

Now another thing...how can you upload the code????Well...very simple!!!Like other compiler and IDEs,Arduino software generates its hex files as well but for some weird reason,it puts that file in the temporary folder.so you dont see it.But if you have a hex file of your program....here is how to do it


1.Download XLoader or AVRpal.NET
   XLoader link(http://russemotto.com/xloader/)
2.Connect you Arduino board to PC.
3.If you have downloaded XLoader,then open it...it should look like this
The interface is straightforward...select your arduino board,select the COM port its connected to and then select the hex file you want to upload and then simply click "Upload"
If you have downloaded AVRpal.NET then when you open it,it should look like this

Alright...this software isnt just for arduino...its for AVR programmer USBasp as well...so click on ArduHexLoader button...a window like this should appear


This is same as XLoader...select your board,the COM port and then the file and hit upload!!!

So...now you see...ARDUNIO ISNT SOMETHING COMPLETELY NEW!!!!IT'S A CONCEPT BASD ON AVR....IF YOU HAVE ANY QUESTION,FEEL FREE to LEAVE IT IN THE COMMENTS.