August 2009 ~ MY Thoughts & Learnings

Friday, August 21, 2009

First Page


Hi Visitors,

Besides all tech stuff in this blog i thought that I should have a section for Myself.
This is where i want to write few diary pages filled with my life experiences,any nostalgic dream,or my opinion on a issue which is effecting my country INDIA progress and it's prosperity.

I found that this could be a place where i can interact with the world as a Friend and try to share my feelings and viewpoints and attitude towards life.

To make this section really happening i would also like you to participate through your valuable comments and place your viewpoint too so that maybe we can all learn some Psalm of Life ... morals which make us a better human being.




I found this very interesting widget which would bring me closer to the visitors :





Please feel free to ask or give suggestions.I am always anxiously waiting for them.

Blog Designing


Ever heard of BlogDesigning ?? yes or no...

I don't know about you but i have not such term formally in my life and i have termed it on my own.This post is for you if you are also into blogging and are fed up of the old traditional style Blog with a dull look which no one wants to be see....

I have tried to make lots of changes in this blog to make it appealing to the visitors.

For example
  • Removed the blogspot bar which comes on the top
  • Added a Favicon you can see the dancing penguin
  • Embedded swf files & many cool animated gifs
  • Can you see the Tabbed Menu for your easy navigation to key sections of the blog.
  • & many more
If you want to do anything out of these and make your blog good as well then keep visiting this blog or in comments give your specific requirement & I will post How to of that specific problem in my next post.

Thursday, August 13, 2009

Timer,Usart,Interrupt Basic Steps

While coding for timers Usart etc there are some steps that are always rather generally taken in order to initialize them.

I have tried to just summarize these basic steps for the beginner which they can adopt while writing code for AVR (i use ATmega 8)

Timer

1. Set the prescalar TCCR0 (example using timer0)
2. Enable the timer interrupt TIMSK timer mask register
3. Enable global interrupts
4. Calculate how often OVF interrupt is thrown as timer OVF is periodic in nature


Usart

INIT

1. Set the baud rate register UBRR is 16 bit
2. Enable Receiver and Transmitter UCSRB also enable the RXCIE or TXCIE or both if interrupts are required.
3. Set frame format for assynchronous communication UCSRC.
that is if you are using parity bits or not,which form of start & stop bit are you trying to incorporate


Transmit
1. UCSRA&(1<<UDRE). If done than store the data to be transmitted in the UDR(usart data register).

Receive
1. Check if receive is complete if yes then store the data from the UDR to any variable

further if using the interrupts related to usart events then make sure you enable the global interrupt by SEI();


Disabling the interrupt before atomic statements.

1. Method is to store the status or condition of the MCU by saving the SREG into any 8 bit variable
2. Use _CLI() to clear global interrupt enable bit
3. Restore previous state form variable used in 1.


PWM hardware based

1. Initialize all the timer in the desired pwm mode and set whether you want inverting or non-inverting pwm.
2. Set the prescalar in TCCR1B.wgm13=0 means normal mode.That is timer would start then OVF and then restart from BOTTOM.
3. Set OCR1A/B a 16 bit register
4. Duty cycle is dependent only on OCR values




Some AVR uc related stuff

Hi,

I apologies for not writing blog for few days because of some tight schedule i was having at my college.But Krishna Janam Ashtami gave me some time to make another post.

1. The Input Capture unit is easy to use in normal mode(WGM13=0).However,observe that the maximum interval between the external events must not exceed the resolution of the counter.

Things one can do to increase the resolution :

If the interval between the events is too long,the timer overflow(inc a software counter/any register) or prescalar must be used to extend the resolution of the capture unit.

2. Constants can also be stored in the program memory as they need not to be reprogrammed or changed too often.

How to do that?

#include "avr/pgmspace.h"

const char table[480] PROGMEM ={} also calculate the amount of memory it will eat/consume.

There should be enough memory left for APM(Application Program Memory) & BPM(Bootloader program memory) in the whole progrqam memory map

3. Two stage pipeline in AVR -

Any instruction you give to the micro-controller undergoes following routine of FDE :

Fetch -----Register ---------Decode----Register --------Execute

It appears as if each instruction is taking lesser clock cycle to execute


4. Why two sets of registers in AVR ATmega8 (in 32 General purpose register ):

Explaination :

For example if i have a instruction like :

ldi r6,$3f

$3f is 8 bits,ldi consumes let say 4 bits.then i am left with only four bits which can be used to represent 16 registers.therefore,16-31 are separate and 16 instructions including ldi are possible only with these(16-31)