Problem with timers on atmega8 (Precision Led blinking) HELP

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Everybody :)
I have started programming atmega8 recently in C lanuage and I have problem with timers.
I want to make precise Led blinking on port D using TIMER 2 (TCCR2). Presented below chunk of code is not working! What am I doing wrong ? Please help me
Adam

// Precised LED switching

#include
#include
#include
//#include Should I use this library or //not ?? 

unsigned char milliseconds=0;
 
 int main(void)
 {
 DDRD= 0xFF;
 TIMSK=(1<<OCIE2); //compare match is enabled on TCCR2
 OCR2=125; 
 TCCR2 = ((1<<WGM21)|(0<<WGM20)|(1<<CS21)); 
 
 for(;;)
 {
  asm volatile(
	"WDR"::);
 }
 return(0);
 }
 
 SIGNAL(SIG_OUTPUT_COMPARE2)
 {
 PORTD =(milliseconds++);
 }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what about setting the clock source?

CS22, CS21, CS20

I don´t know if you have to "SEI" in C.

Klaus
********************************
Look at: www.megausb.de (German)
********************************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Everything looks fine apart from the missing sei() to get the ball rolling!

With one of those added it hits my breakpoint in the ISR in the simulator. Though I switched the CS21 to CS20 to make them happen quicker as the simulator is slow!

By the way SIGNAL() and SIG_OUTPUT_COMPARE2 are now deprecated. You should be using ISR()

This is why you'll have been getting the:

c:/winavr-20070525/bin/../avr/include/avr/signal.h:36:2: warning: #warning "This header file is obsolete.  Use ."

warning when bulding the code.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a million !
I forgot to add sei() // stupid tit ;)
How you would do that using ISR() ???

//SIGNAL(SIG_OUTPUT_COMPARE2)
 ISR(TIMER2_COMP_vect)
 {
 PORTD =(milliseconds++);
 }

Doing this in this way it is not working ??
I suppose my AVR-GCC is too old v2.0.5.32
Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I suppose my AVR-GCC is too old v2.0.5.32

You should be using the latest AVR-GCC along with the latest AVR Studio (if you are using that).

Regards,
Steve A.

The Board helps those that help themselves.