Search This Blog

Powered By Blogger
Showing posts with label avr. Show all posts
Showing posts with label avr. Show all posts

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.

Saturday, March 31, 2012

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!!!