Author Topic: Timer0 and overflow interrupt help  (Read 2857 times)

0 Members and 1 Guest are viewing this topic.

Offline TazdevilTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Timer0 and overflow interrupt help
« on: June 14, 2009, 06:15:46 AM »
Hello,

I have been trying to get this working for a few days now. I plan to use timer one to control a servo which will change due to inputs on a interval of 5 min or so. I have done the math to figure out all the details of timer0 to get the required time interval but I know it is long so I am prescaling at 1024 and using normal mode to get the 255 steps.

The counter appears to be working but I don't seem to be generating any interrupts as that code never seems to execute. I have left all the timer1 stuff in and I hope it is not too confusing.

Can anyone see why this is not working? I tried setting things beyond what I thought was nessasary and have tried evey setting I can find to enable the interrupt on overflow for timer 0

Thanks for any help I am mainly a hardware guy and C is a little new to me. I am sure it is something I have misunderstood but just can't see the problem. I am using a ATmega168 set at 8 Mhz clock.

Code: [Select]
int main()
{
int i;
int OvenH;
int Ovenlo;
int Previous_temp;
int timer1;
int timer256;
int timerlastbyte;
int Speed;

uartInit();  // initialize the UART (serial port)
uartSetBaudRate(38400);// set the baud rate of the UART for our debug/reporting output
rprintfInit(uartSendByte);// initialize rprintf system
rprintf("Start****************************************************************************************\r\n");
DDRD=0xFF;
DDRB =0x00;//|= (_BV(1));// | _BV(2)); //0xFF;      // make port B1 an output pin data sheet says to put this last???

//setup timer 0 for counting time using timer1,256,lastbyte to keep enough space

TCCR0A=0x00;// set for normal counting
OCR0A=250; // not needed but added for testing purposes same goes of B
OCR0B=250;
//set mode for normal and prescale 1024

TCCR0B=0x05; //prescale 1024
//enable overflow interupt
TIMSK0=0x01;
TCNT0=0; // to see if anythng changed no difference in output
TIFR0=0; // can't seem to clear out the 4 and 2 bit????
sei();
Prn_all(); // prints a bunch of timer registers
// I am getting
/*
Print all active timer 1
TCNT1 0
OCR1A 0
OCR1B 0
TCCR1A 0
TCCR1B 0
TCCR1C 0
ICR1 0
DDRB 0
PINB 0
Print all active timer 0
TCNT0 52
OCR0A 250
OCR0B 250
TCCR0A 0
TCCR0B 5
TIMSK0 1
Print TIFR0 7 181
Print TIFR0 7 216
Print TIFR0 7 251
Print TIFR0 7 30
Print TIFR0 7 63
Print TIFR0 7 96
Print TIFR0 7 129
*/
// setup Timer1 for slow pulses to debug change later to drive servo at 1.5 ms

//disable all PWM just in case
TCCR1A=0x00;

ICR1 = 10000;// 16 HZ

// 1024x prescaling CS10 CS12
//8x cs11
// PWM  phase and frequency correct  wgm13

TCCR1B = (1 << WGM13) | (1 << CS11); //| (1<<CS12);

Speed=750; //stop

OCR1A = Speed; // 2ms pulse to left motor on PB1
OCR1B= Speed;
TCCR1A =0xA0;  // 0b1010000 enable PWM on port B1 to use non-inverting mode com1a1=1 com1a0=0 com1b1=1 com1b0=0 wgm11=0 wgm10=0
DDRB =0xFF;
   





PORTD=1<<PD5;
delay_cycles(100000);
PORTD=1<<PD4;
delay_cycles(100000);
PORTD=1<<PD3;
delay_cycles(100000);
PORTD=0;



while(1)
{


i=TIFR0;
if (i=7)
{
rprintf("Print TIFR0 %d %d\r\n",i,TCNT0);
PORTD=0;
}


// rprintf("Print TIFR0 %d\r\n",i);
PORTD=1<<PD5;
delay_cycles(100000);
PORTD=0;
// delay_cycles(100000);
}


return 0;

 

}
ISR(TIM0_OVF_vect )
{

TIFR0=0;
PORTD=0;
PORTD=1<<PD4;

PORTD=1<<PD3;


}
« Last Edit: June 14, 2009, 06:24:03 AM by Tazdevil »

Offline TazdevilTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Timer0 and overflow interrupt help
« Reply #1 on: June 14, 2009, 09:45:05 AM »
I think it has something to do with

ISR(TIMER0_OVF_vect)

In a message box I see

gcc plug-in: Error: Object file not found on expected location C:\RobotProjects\Smoke_control1\Smoke_control1.elf
Make sure your makefile specifies the output .elf file as Smoke_control1.elf


The make file is correct as far as I can tell and works without the interrupt ISR in place.

When I use

ISR(TIMER0_OVF0_vect)

The compiler gives me a warning

Smoke_control1.c:102: warning: 'TIMER0_OVF0_vect' appears to be a misspelled signal handler


which I think is true if I read everything correctly.

Offline TazdevilTopic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
Re: Timer0 and overflow interrupt help
« Reply #2 on: June 14, 2009, 07:41:19 PM »
Don't know why it originally didn't work. I started again from scratch and found I was able to compile and load the program. Interrupt is now working. go figure must have been the mess of a program I had going although I left out the timerx8.h and timerx8.c includes. Still a little confused on how to use the includes correctly I guess. On to the next problem only 99 more to go.


 


Get Your Ad Here