এই ব্লগটি সন্ধান করুন

বুধবার, ১৮ সেপ্টেম্বর, ২০১৩

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.

বুধবার, ১৯ জুন, ২০১৩

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.

শনিবার, ৩১ মার্চ, ২০১২

Simple Fun Morse Code decoder with AVR microcontroller




Hi people...let's have some fun with AVR micros.This is my first post on any hardware project based on microcontroller except programmer or programming hardware.It's just a fun project but can also be useful to those who practice morse code...Well by this time u know what that thing is...it's a simple morse code decoder with one button,ATmega16(not overkill,kind of superkill for anything like this,but at that time,that was easy to work with for me as I had a development board for 40pin avrs),LCD for showing output.

Unfortunately,that circuit is a history now so I cant post any image of it(Sorry folks).But I will post the schematic and a video I uploaded then to youtube(Though the video quality is...better see for yourselves).
Okay let's come to the point.Many of you know what morse code is...it's an old system of electrical communication where messages are sent as a combination of Dash(long duration beeps or current flow) and dots(shot beeps or current flow).This was used in morse telegraph communications systems.The morse code chart is given below for interested people from wikipedia:


Though I didnt follow the timing issues then,only used the codes.

Now,why this old stuff using new things right???Well,answer is simple...mainly for fun and some skill testing also :) .
Here goes my schematic:

Circuit is pretty simple...just one button for taking input.

I had to add some extra things for displaying to LCD and clearing the LCD etc. such as a 7sec delay after entering the code to show the result on LCD.

The source code was written in Bascom AVR.Its a pretty cool compiler and easy to work with and awesome for string handling and code optimization.The source code is not BIG so It is posted here.

THE CODE:

'8th pin of PORTA used for input

$regfile = "m16def.dat"

$crystal = 8000000

$lib "lcd4busy.lib"
'defining LCD pins
Const _lcdport = Portb
Const _lcdddr = Ddrb
Const _lcdin = Pinb
Const _lcd_e = 2
Const _lcd_rw = 1
Const _lcd_rs = 0
Dim A As Integer 'the delay counter
Dim Bttn_pressed As Integer 'variable to check if the button has been pressed before when released
Dim Mrsc As String * 32 'string for holding the morse code input
Dim Strf As String * 32 'string for holding the processed output
Dim X As Integer 'LCD upper line character position

Mrsc = ""
Strf = ""
Ddra = 0
Cursor Off
Cls
X = 1
Do
If Pina.7 = 1 Then
A = A + 1
Bttn_pressed = 1
Waitms 500
Elseif Pina.7 = 0 Then
If Bttn_pressed = 1 Then
If A = 1 Then
A = 0
Bttn_pressed = 0
End If
If A > 1 And A < 3 Then
Upperline
Locate 1 , X
Lcd "."
Mrsc = Mrsc + "."
A = 0
'Waitms 10
Bttn_pressed = 0
X = X + 1
Elseif A >= 3 And A < 6 Then
Upperline
Locate 1 , X
Lcd "_"
Mrsc = Mrsc + "_"
A = 0
Bttn_pressed = 0
X = X + 1
'Waitms 10

Elseif A >= 6 And A < 12 Then
Select Case Mrsc
Case "._"
Strf = Strf + "A"
Case "_..."
Strf = Strf + "B"
Case "_._."
Strf = Strf + "C"
Case "_.."
Strf = Strf + "D"
Case "."
Strf = Strf + "E"
Case ".._."
Strf = Strf + "F"
Case "__."
Strf = Strf + "G"
Case "...."
Strf = Strf + "H"
Case ".."
Strf = Strf + "I"
Case ".___"
Strf = Strf + "J"
Case "_._"
Strf = Strf + "K"
Case "._.."
Strf = Strf + "L"
Case "__"
Strf = Strf + "M"
Case "_."
Strf = Strf + "N"
Case "___"
Strf = Strf + "O"
Case ".__."
Strf = Strf + "P"
Case "__._"
Strf = Strf + "Q"
Case "._."
Strf = Strf + "R"
Case "..."
Strf = Strf + "S"
Case "_"
Strf = Strf + "T"
Case ".._"
Strf = Strf + "U"
Case "..._"
Strf = Strf + "V"
Case ".__"
Strf = Strf + "W"
Case "_.._"
Strf = Strf + "X"
Case "_.__"
Strf = Strf + "Y"
Case "__.."
Strf = Strf + "Z"
Case "____"
Strf = Strf + " "
End Select
Cls
Lowerline
Lcd Strf
Mrsc = ""
A = 0
X = 1
Bttn_pressed = 0


Elseif A >= 15 Then
Cls
Bttn_pressed = 0
Mrsc = ""
Strf = ""
A = 0
X = 1
End If
End If
End If
Loop
End


Code has been commented so It should be easy to understand...

Here is the (Sorry again for quality)...well...video...:)

If you need some information...tell me.Have fun!!!

সোমবার, ৩০ জানুয়ারী, ২০১২


CEMSTech AVRpal.NET

An easy to use avrdude GUI for Windows platform

CEMSTech AVRpal.NET is a very easy to use avrdude GUI.NOw,avrdude is a very popular programmer application for AVR microcontroller mainly because its cross platform and its small in size but it has one major drawback...ITS COMM
AND LINE!!!!(well...I hate typing commands).So I decided to go for making an avrdude GUI.Now,avrdude is the "dude" of AVRs so I named my app. "AVRpal"(:D :D)...Now many of you will try to shoot me as I havent added any support for parallel,serial programmers and NOT even for USBtinyISP...IT only supports USBasp...its because
I had only USBasp and this works great,may be popular than USBtinyISP(Dont blame me if I am wrong guys).So,as I built this app. for me at first,I couldn't so didn't add any support for other programming hardwares but avrdude supports a lot.Now I did one thing for you,I made it OPEN SOURCE!!!If you can code in VB.NET,just download the code from here and enjoy!!!
Now...a screenshot of this app:

Now you can see that the interface looks funny...well it was made so intentionally(I didn't provide support for many programmers,so at least I hope this is gonna save me from getting beaten up by embedded people(well...I hope so)).So guys,go to sourceforge.net and download the binary from here.

Now this application requires a modified firmware for USBasp to enable the slow sck control feature from the application window.I will upload the modified firmware soon.

ENJOY!!!


রবিবার, ১৮ এপ্রিল, ২০১০

Softwares needed

Hmm...this is the part where we will know which softwares are to be used for uC coding,simulation and programming.Well...the architecture of uC and your PC is different and so you can't use your computer compiler softwares to program your uC.Well...there are several compilers for programming avr like avr-gcc,bascom avr etc.they support the coding architecture of PC(For instance,avr-gcc is a c code compiler for avr uCs) but compiled output is different.But you can configure your programming editor(Hope you know the editor you use to write the code and the compiler you use to compile your code is different) with this uC compilers.Well,uCs can also be programmed with assembly language(a low level language) in which you can directly access memory addresses etc. but it's not as user friendly as a mid level language like c or high level language like basic(bascom avr).In this tutorial we will use avr-gcc as our compiler(for assembly,there is a good tutorial here).
Here is the list of softwares.First I am giving you the list for Windows OS,then Linux(Ubuntu,other distributions should also be compatible).

Softwares for windows:

1.AVR Studio:
This is a very good software and a complete IDE for avr uCs by Atmel with built in assembler(assembly compiler).You can also use it to compile C(if you have WinAVR installed) codes.It has a simulator in which you can run your codes to see if they are bug free.You can even program your uC right through this IDE if you have a AVR Studio compatible programmer(List of programmers can be found in it's menu) .This great software is absolutely free and requires only a free registration.The link is here.
Visit the link and download "AVR Studio 4.18"(requires a free registration) then download the service pack(SP2 or SP3).Install AVR Studio 4.18 first then the service pack(because service pack is not the complete software,just an update).Check "install USB driver"(When shown).

2.WinAVR: A collection of compiler and all the files you need(some you don't).A software for programming uC(avrdude) is integrated with it(This is highly necessary if you are using USBasp as programmer).Can be downloaded from here.(That's a open source one,so you can modify it if you want).An integrated editor(Programmer's Notepad) can be used as a code editor for avr-gcc.
N.B. :- It may show some errors if you are using windows vista or 7 (64 bit version). To fix it,you need to patch winavr.The patch can be found here.Download it and follow the instructions(May be you need to replace a file given there as patch).Recent releases of WinAVR should be free from this problems.If not...then write to me.
DURING SETUP,CHANGE THE INSTALLATION DIRECTORY NAME FROM "WinAVR - something" to simply "WinAVR".

Proteus VSM:A simply awesome software for simulating circuit you want to make(means you can just draw the circuit in it's workspace and run the circuit in you PC virtually).This software supports a lot of avr uCs and you can just add the compiled file there.You can even design PCBs for your circuits here.Unfortunately...this is not a free software and too much costly(>$2000 or $3000).There are many cracked versions available online.Search them(I can't give it's link here...the admin guys may shut my blog up!).

Well...there are other IDE's available...such as Eclipse.To know how to use it with winavr,click here.

Ponyprog:You can use this one if you are planning to build a parallel/serial programmer stated in the previous chapter.This is a very handy tool and can be downloaded from here.

AVR-Burn-O-Mat:AVRdude is a command line software(aahh...I hate command typing).This is a GUI(Graphical User Interface) for avrdude(means you give command to avrdude via this software by simply clicking things,REMEMBER,this is not an alternative to avrdude,just a GUI for it).Link is here.

Well...I am writing a GUI for avrdude.You will get it soon!It's is not as versatile as Burn-O-Mat but a simple one to use.

Softwares for Linux:

Hmm...the OS with ever growing popularity.Here is the list of softwares for it.

avr-libc,avrdude,uisp : there is no collection like WinAVR available for Linux.In ubuntu,you will get them in your Synaptic Package Manager(Preference menu).Download them and this manager software will automatically mark necessary extra apps needed before download.After downloading,they will be installed automatically.

Kontrollerlab:A very good IDE for Linux.You can even add any avrdude compatible programmer in it.That means it can even be used to program your uC.Link is here.
Download the compatible package from the link.This is the one I am using in my Ubuntu OS.

Eclipse can be used as a IDE for Linux too.

Installing Driver for programmer(Only if you are using USBasp):Hmm...something else I still need to say...how to install the driver for USBasp.Well...download the latest zip archive from fischl.de then extract it.When you insert the USB cable of your USBasp hardware,a "Found New Hardware Box appears"(If you have already written the firmware into Atmega8 of USBasp and your connections are alright).There you show the "bin/win-driver" folder of your extracted USBasp folder.Then the setup will automatically locate driver for USBasp.
Now,time to test the hardware.Go to command prompt and type "avrdude -c usbasp -p m16" or replace the "m16" with "m8" or "m32" if you are using them as target uC.(No need to worry,I'll explain that!).Most probably,you will see "avrdude: error: could not find USB device "USBasp" with vid=0x16c0 pid=0x5dc".Well, this is because of the version difference between the driver given with avrdude and the one you installed.If you're lucky and you have set everything up,you should see an ok message.Otherwise,if you haven't connected the target uC or if there is any connection error in the connection between the uC and USBasp (Or in the power connection of target uC) and the driver version is perfect then you should see "target doesn't answer" message.If you haven't connected the target uC,then you can jump saying "yeppi,my USB device works!" or if you have,then you can say to yourself,"No problem...just to fix the target uC connections...my USBasp is alright!".
Now,if you have got an error message like "could not find USBasp",then unplug the hardware and reconnect it.If this does't work,copy the libusb0.dll & libusb.sys file to "WinAVR/bin" directory.A message will appear saying that these files already exist...but just press yes.Now test it,you should see a positive result.If not,then check your USBasp for connection errors.

শনিবার, ১৭ এপ্রিল, ২০১০

Hardwares needed

Well...now we are preparing for our voyage to uC world!This tutorial is about the hardwares or precisely programming hardware you need to insert the program into your avr chip.Well... what about other parts you need to make project circuits or your own circuits,right?well...you will get their values in schematics of projects and when you are making a project of your own...that's up to you!
First we need to build a power supply for our uC.uCs are mostly operated with +5V.This should be regulated(specially when you are using timing or communication features or ADC etc. because voltage ripples can cause incorrect data outputs).
This is the Schematic of the power supply for uC.This is actually not a full power supply.It's just the voltage regulator part.Build it according to schematic and don't forget to use a heatsink with 7805 IC(It may get terribly hot when used for a long time)
N.B. :- There are two ground pins in your uC,connect both of them to your circuit ground.
Parts list(picture is fair as schematics , not for seeing parts list):
  1. IC-7805(see Datasheet for pin config)
  2. Capacitor-220uF,16V(others voltage ratings will work)
  3. Resistor-1k
  4. LED
  5. Power connector
  6. Switch
Now let's come to program the uC.avr uCs can be programmed in two ways:
  1. Parallel programming(don't mistake,it doesn't mean programming with parallel port of pc)
  2. Programming through SPI bus(this is what we will discuss,because this the way of in system programming.For informations on parallel programming,see datasheet)
In system programming hardware:Well...there are several programming hardwares for that.We will give schematics of the most popular hardwares.Some of them are commercially available(STK500,AVRISP mk II etc.).If you can afford them...then buy one(But we advise you to have the experience of building one of these hardwares)Here are the schematics:
1.Parallel port programmer:If you have an old PC(Old is gold!),then this one can be the starting programmer for you.There are several parallel port programmers.This one was tested by us.Schematic:
N.B. : SCK,MOSI,MISO are the pins of SPI bus of your uC.Find their pin number from Datasheet(same applicable for RESET)In this circuit, a buffer IC has been used(74HC125).You may be thinking about the strange connection pattern of this circuit(You should be,if not experienced).Don't worry, that circuit is easy.But you need parallel port diagram to make this.Ok,here is it:This is the female side of the DB25 Connector Cable used here.You can directly connect the circuit without using the cable but I recommend you shouldn't(You may get some shocks due to earthing).
The Whole circuit can be built on a breadboard(including the power supply).
After building it,we shall use a program Ponyprog to send the program from PC.(will be discussed in the next chapter)
2.Serial port programmerI haven't seriously tested this one but many use it(may be!).It's a bit complex than the first one.
N.B. : This one is not supported by USB 2 Serial Converters
Here is the Schematic:Here,Serial port config is already given.So I haven't shown it.
N.B. : I don't guarantee if it works but since I know,this is a popular one.
USB programmer:
Hmm...now we are getting modern.Well...the programmers stated above are backdated as serial and parallel ports are not available in today's PCs or Laptops(However,if you have an old one,you can still build them...after a while...you will know why I said "Old is gold")To do something with USB port,Hardware driver is needed and to let the PC know what kind of hardware is connected to USB,some id codes and high/low operations are needed.That's why,in almost every USB device,there is a microcontroller or dedicated USB controller chip. Now you may have felt why I said "Old is Gold",because to make a USB programmer,you need a USB controller Chip or uC as driver in which you need to write the hardware program(firmware).Here is a diagram on how USB programmers work.
To know why we need to do that for USB,search google with the following keyword "USB in a nutshell".This is a very good book on USB.
Luckily , if you have an old PC/Laptop,you can make any of the first two programmers(they don't require a uC or controller chip to program your uC) and to be modern,you may use them temporarily to write the driver program(also called firmware) to your USB programmer's driver uC and forget them.Here is the Schematic of one of the most popular(may be the most) USB programmer(that I use at present),USBasp by Thomas Fischl(http://www.fischl.de/usbasp):Well...It looks horrible may be but quite easy to make.Here,as driver uC an Atmega48 has been used.But you can also use Atmega8(Even others if you understand the firmware code).This programmer requires a driver.It's available at the website stated above the schematic.
To build this, you need to know the usb pin config.to know this,visit this site.
N.B. :- Some connections are not very necessary in this circuit.For example...the connection between pin 1 and pin 16(self programing) is for firmware upgrading and not important so it can be deducted from the circuit(But NOT THE ONE FROM PIN 16 TO x2).Connections from pin 2 and 3 to X2 are also not important(keep them if you want).X2 is a connector.You can simply use serial rail to make this one(this would be better if you want to keep your uC circuit on breadboard).This circuit can be built on breadboard but I recommend you build it on a veroboard or PCB.PCB Layouts are available at the site stated above schematic.
Some useful pics: My USBasp board The ISP connector of the board(just serial rail....X2 in the schematic)
These pins are connected to Atmega8's MOSI,MISO,SCK,pin 16 and ground....
Others are unnecessary

One thing to tell you about this circuit is that if you are planning to build a PCB in which you will put your target uC to program,then keep the VCCINT(the target uC will be powered by USB).Otherwise,for ISP operation,deduct it.

Getting Started with avr microcontroller

Well...time to stop this history lecture and come to the point.We are using atmel avr microcontroller.Many of you may ask why we are using this one.Well...actually I have already answered it but missed one point.Atmel guys write their datasheets very well and they are easy to understand(Datasheet is the documentation of the device you are using...means pin configs,register descriptions etc.).
Atmega16 is an 8bit avr microcontroller with 16k in system programmable flash.Well...after all these almost non-technical stuffs,the aforesaid one is like instantly changing speed from as slow as a cycle to as fast as a bullet train!!!Well, avr is a computer architecture developed by Atmel.It's a modified harvard architecture system.8bit means the register size(a temporary memory where data can be stored,exchanged etc.) is limited to 8bits and more precisely...the arithmetic logic unit(CPU) can process 8bit data at a time(maximum).Register is like a set of memory blocks.Each of them can store one bit(0 or 1).So each register of avr should have 8blocks for 8bits.There are some 10bit,16bit registers too,but they are actually collections of several 8bit registers(We shall see them in datasheet).
Now...what is that "in system programmable flash" thing?Well...flash is a non-volatile memory and in avr microcontroller(and in many others),this is the memory where the program you have written is kept."In system" means you can program the microcontroller even after installing it in your circuit.That's a great thing because you don't need to remove uC from circuit to program it.You just power your circuit and connect your programming hardware to it and just send the program from your PC or Laptop!
Now...I have stated something new here what I haven't stated before:"Programming Hardware".Well...Since the beginning of this tutorial I have been saying that uC can be "programmed".But how?You can't just load the program into a pendrive and then insert it into uC!You need a circuit that will work as an interfacing medium between the uC and your PC.This is the programming hardware.There are many kinds of programming hardwares available for avr(We will discuss it soon).
Besides, you also need a software that will use the hardware to send the program to uC.Well...we will discuss it too!
Now...let's come to datasheet.I said you need it to know about the uC you are using.Seeing it you can know the features of your uC,pin config, internal devices and how to access them through your code etc.A very good video on accessing the datasheet is about to be published(It's on atmega8 but you can easily get the main theme).Well...let's move to our next chapter.

শুক্রবার, ১৬ এপ্রিল, ২০১০

How to select a perfect microcontroller for your work

Well...after having a basic knowledge of uCs (microcontroller) , we move to an essential part...there are many uC models and manufacturers....which uC should we select for our work,right? Well...it's a bit like choosing other electronic components.For example, for timing pulse operation,we select NE555 IC , not CD4017.Like this, we will select our uC according to what we want to do with it....means what integrated facilities it must have to meet our demands.Cost is also a big factor if you want to go commercial.If your desired work can be done with a $1 uC,then it is impractical to choose a $5 uC for that.Size can also be a big factor.two uCs can be of same price but different size and sometimes you may have to choose the smaller one to make your circuit compact.
Well...internal facilities or hardwares play the main role so this factor has the first priority in case of choosing a suitable uC.Like,for your work , you need an analog to digital converter or a higher clock rate or built in USB hardware(this stuffs will be discussed later...so don't get scared seeing them) etc. etc. etc. There are some uCs that may meet all your demands...means you may use one like them in every application but they may be costly so you have to choose cheaper , specially dedicated uCs("dedicated" doesnt mean these uCs can only do a single job,they can do other jobs but are "specialized" for doing that single job).
A good example is this tutorial...as we are explaining every basic thing of uCs...so we have to choose a uC in which every general hardware is present(means the common hardwares found in most of the uCs).So we are using Atmega16.There is another reason behind choosing this one.This is a general purpose uC and...almost all the tools you need(software,circuit schematics) to work is free(except hardware) and AVR microcontrollers are good to be used in novice level.

What is microcontroller and why it is used

We live in electronics age.Electronic stuffs are all around us and doing a lot of works for us every day...every moment.Many of them are quite smart and complex too.For example,let's take a look at a very familiar thing...mobile phone!They are like small computers and have so many functionalities. Of course these functions...no matter how complex... are built with many logics...to know what logic is...simply visit this link.
Now...to make this logic gates "electronically",there are many logic gate IC's available or you may make them using simple equipments like relays,transistors etc.You can do this when you are building a very simple circuit. But...what about complex ones...huh?Like your mobile phone?there you need to control the LCD,display various informations on it...that requires very complex logic operation,let alone controlling other thing such as network communication,phone book,internet ,application...bla bla bla.Well,if u want to make a phone without microcontroller, then the size would be as big as a truck(!!!!!!!!!!!!!) and to add a new function,you will have to change the entire circuit.Well...there is one thing that will stand with you to face such challenges...microcontroller. Image : Atmega16 Microcontroller (We will use it)
Microcontroller is a small computer in a single chip.I mean,it has almost everything a computer consists of...CPU,RAM,Non- Volatile memory like Hard disk(not actually like that,in a solid state form without any rotating parts).Like a computer you can program it and through it's I/O pins,you can send command or take datas for processing.And logics can be programmed,so you don't need a truck size board now(Yeppi!) .So, your circuits can now be extremely small...highly customizable...and very easy...and secure.Now where is this security stuff coming from...right?
Well...you want to sell a complex (with many logics) circuit you have built with great labour.You sell it...and someone buys it and copies it and...sells it at a lower price..because he has just copied it...so he can cut the extra cost you added for research(ohhhh)...but if that was a microcontroller based one...you could just "lock" the microcontroller code and sell it and...that copier guy cannot make your circuit because he doesn't have your code to run the circuit(Now do that...copier).So it makes your work easy and safe too.
Now...where can we find microcontrollers?Well...they are everywhere,mobile phone,washing machine,microwave oven,television,printer,photocopier,modem,toys(aaahhh)...and many other.
So,we can say that...they have become a part of our life

রবিবার, ১৪ মার্চ, ২০১০

Atmel microcontroller tutorial - Index

hi guys.I am Shovon(M.E. BUET).I am an electronics and robotics enthusiast.I have been working with uCs for a long time and I have collected valuable infos and willing to share 'em. I am writing a tutorial on uC(Microcontroller).The uC I'm gonna use is Atmel Atmega16(8,32 will be ok).Well,let's keep this mumbo jumbos short...and move to the tutorial
N.B. :-For descriptions...see other blog posts
Here is the complete index:
Atmel uC tutorial
  1. 8 bit timer
  2. 16 bit timer
  3. Project - a clock
  4. Special application - the PWM
  • Analog to digital converter - the magical connector between analog and digital world!!
  1. ADC description
  2. Some Coding
  3. Project - voltimeter
  • LCD Display...your monitor for uC Computer!!
  1. Overview
  2. LCD pin configuration
  3. Now... some coding
  4. Project...LCD Clock!!
  • Make your uC remember things even when it's turned off - the EEPROM
  1. Overview
  2. Registers
  3. Some Coding
  4. Project...Alarm Clock
  • Tick...Tick...Tick...tititi...Time to communicate with your pc...the USART
  1. Overview
  2. Serial Communication Basic
  3. Register
  4. Project...computer controlled stepper motor
  • Some other uC stuffs
  1. Serial Peripheral Interface - SPI
  2. I2C/TWI
  3. Some good tutorials on uCs