Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AVR ATMEGA16 timer0 , timer1 interrupt ,int0, problem

Status
Not open for further replies.

irfan ahmad

Full Member level 3
Joined
Feb 17, 2012
Messages
181
Helped
54
Reputation
108
Reaction score
54
Trophy points
1,318
Location
LAHORE PAKISTAN
Activity points
2,211
i wat to use these interrupts at same time
1; timer0.
2; timer1,
3; external interrupt int0,
i have just enable two interrupts TIMER0 AND TIMER1 but malfunctioning.
if i enable only one interrupt timer0 or 1 then it works fine.
But when i enable both then only timer0 interrupt works.
here is my code.

Code:
#define F_CPU 8000000UL
#include <avr/io.h>    
#include <util/delay.h>
#include	"avr/interrupt.h"
int main(void) 
{	

  DDRC=0XFF;
  PORTC=0X00;
  DDRB=0XFF;
  PORTB=0X00;
  _delay_ms(100);

  ////////////////////////TIMER FOR PWM CALCULATION
TCCR1A=0X00;	//NORMAL MODE
TCCR1B=0X01;	// NO PRESCALER
TCNT1H=0XC1;	//
TCNT1L=0X80;
TIMSK=1<<TOIE1;

////////////////////////////////

TCNT0=0X06;	     // initial value
TCCR0=0X03;		 //TIMER0 CONTROL REGISTER	

//TIMSK=1<<TOIE0;	when i comment this line then only timer0 works 

////////////////////////////////
  sei();					// ENABLE GLOBAL INTERRUPT
  while(1);
}


//////////////////////////////////PWM
ISR(TIMER1_OVF_vect)
{
TCNT1H=0XC1;
TCNT1L=0X80;
PORTB=~PORTB;
}
///////////////////////////
ISR	(TIMER0_OVF_vect)
{
TCNT0=0X06;	     // TIMER COUNTER REGISTER
PORTC=~PORTC;
}

please guide me .
 

Are you expecting interrupt in simultaneously? you can't, since it is sequential access
 
not the same time but at their own time.
but at their own time. as their interrupt flag raise.
 

To enable both timer0 and timer1 interrupts

Code:
TIMSK[COLOR=#339933]=[/COLOR][COLOR=#009900]([/COLOR][COLOR=#0000dd]1[/COLOR][COLOR=#339933]<<[/COLOR]TOIE0[COLOR=#009900])[/COLOR] [COLOR=#339933]|[/COLOR] [COLOR=#009900]([/COLOR][COLOR=#0000dd]1[/COLOR][COLOR=#339933]<<[/COLOR]TOIE1[COLOR=#009900])[/COLOR][COLOR=#339933];

[/COLOR]

Enable timer0 interrupt
Code:
    [FONT=Tahoma]TIMSK[/FONT][COLOR=#339933][FONT=Tahoma]=[/FONT][/COLOR][COLOR=#009900][FONT=Tahoma]([/FONT][/COLOR][COLOR=#0000DD][FONT=Tahoma]1[/FONT][/COLOR][COLOR=#339933][FONT=Tahoma]<<[/FONT][/COLOR][FONT=Tahoma]TOIE0[/FONT][COLOR=#009900][FONT=Tahoma])[/FONT][/COLOR][COLOR=#339933][FONT=Tahoma]|[/FONT][/COLOR][COLOR=#009900][FONT=Tahoma]([/FONT][/COLOR][COLOR=#0000DD][FONT=Tahoma]1[/FONT][/COLOR][COLOR=#339933][FONT=Tahoma]<<[/FONT][/COLOR][FONT=Tahoma]TOIE1[/FONT][COLOR=#009900][FONT=Tahoma])[/FONT][/COLOR][COLOR=#339933][FONT=Tahoma];[/FONT][/COLOR]
set timer0 to 0x00
Code:
 TCNT0=0x00;

set timer0 with pres caller

Code:
TCCR0 = (1<<CS02) | (1<<CS00);

tern on timer1 ( you can change this as you wish )

Code:
 TCCR1B |= (1 << CS10) | (1 << CS12);

isr on
Code:
sei();

while loop
Code:
 while(true)

timer1 overflow
Code:
ISR ( TIMER1_OVF_vect){

port&=~port // your code

}

Code:
ISR ( TIMER0_OVF_vect){

port&=~port // your code

}

hope this will help you
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top