viernes, 21 de agosto de 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.

jueves, 13 de agosto de 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