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<<
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
No hay comentarios:
Publicar un comentario