ATmega8515 - OCR0 wont be set.

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

Hi all,
I am in a big rush so any help will be greatly appreciated.

I am using;
WINAVR GCC with AVR Studio 4 with a STK500 to program a ATmega8515.

If I goto project -> configuration options, under device it says: "atmega8515".

as verified when I compile the build prompt says
"AVR Memory Usage
----------------
Device: atmega8515

"

The included IO header file is:
c:\winavr-20100110\avr\include\avr\iom8515.h

From the data sheet:
$31 ($51) OCR0 Timer/Counter0 Output Compare Register

From the included file

/* Timer/Counter 0 Output Compare Register */
#define OCR0    _SFR_IO8(0x31)

When I simulate with AVR studio 4, when it gets to writing the value for OCRO, it remains 0. I am using another TCNT and the value OCR1A can be set fine, its just OCR0 for some reason it will not accept the assignment when stepping through the code.

As you can see by the attached picture, as I step through the assignments of setting OCR0 to random values:

//Output Compare Register - 1 = Match after each count
OCR0 = 17;	
OCR0 = 18;
OCR0 = 29;

OCR0 remains zero.

I dont know what else to try, its such a simple thing!
Thanks very very very much for any help!

Attachment(s): 

Just a noob in this crazy world trying to get some electrons to obey me.

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

The complete TCNT0 initilisation code if required is here:

//TIMER COUNTER 0 (8 BIT)
//Every 1 count, causes an match interrupt, then update the count value.

//Timer/Counter Mode of Operation - 10 = CTC
TCCR0 |= (1<<WGM01)|(1<<WGM00);		

//Clock Select - 110 = External clock source on T0 pin. Clock on falling edge
TCCR0 |= (1<<CS02)|(1<<CS01)|(0<<CS00);	

//Output Compare Register - 1 = Match after each count
OCR0 = 1;
						
//Timer/Counter Interrupt Mask Register - Timer/Counter0 Output Compare Match Interrupt Enable
TIMSK |= (1<<OCIE0);

sei();	

Just a noob in this crazy world trying to get some electrons to obey me.

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

If you want CTC mode, it is PWM#2.
You have chosen PWM#3 or Fast PWM.

No, I have not bothered with the Simulator.
However in real life, OCR0 will not get updated until the BOTTOM.

Why do you use |= when initialising. = is far more appropriate.

AVR timers are very simple. You can initialise in 3 statements. TCCR0=, OCR0=, TIMSK |=

David.

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

Quote:

However in real life, OCR0 will not get updated until the BOTTOM.


Good catch. "One off", I think--datasheet says BOTTOM. (And the sim snapshot shows TCNT0 at 0 so isn't that BOTTOM?)

Anyway if OP really wants CTC, then set up the timer for that and see if the sim operates as expected--in CTC update is "Immediate".

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Quote:
And the sim snapshot shows TCNT0 at 0 so isn't that BOTTOM?
It updates when it reaches BOTTOM, not when it is at BOTTOM. Since the timer was just started, the timer has never been anything but 0.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

Good catch. "One off", I think--datasheet says BOTTOM. (And the sim snapshot shows TCNT0 at 0 so isn't that BOTTOM?)


I had a brain f___. Datasheet says TOP, which is what I was thinking when I said "one off". Anyway, OP should be on his way now.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.