Quick ATTiny45 timer 1 question

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

Hi guys

I'm trying to start my timer1 in the ATTiny45, I'm using in my current project.
However, when simulating, I can't get the timer started.
The processor is running on the internal 8MHz RC oscillator with no prescale.

Here's the code that I'm using:

//TIMER1 SET-UP
TCCR1=0x00; 
PLLCSR=0x00;
TIMSK|=0x06; //Timer0 and timer1 overflow enable set.
TCCR1=0x01;

This should be straightforward, but I must be missing something...
What did I do wrong?

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

Quote:

when simulating,

Which simulator?

When I run this in simulator 2:

#include 

int main(void) {
	//TIMER1 SET-UP
	TCCR1=0x00;
	PLLCSR=0x00;
	TIMSK|=0x06; //Timer0 and timer1 overflow enable set.
	TCCR1=0x01; 
	while(1) {
		PORTB = PINB;
	}
}

I see TCNT counting up as expected.

BTW you may want to set bits symbolically as it makes the code more readable.

Also why enable the interrupts if you aren't going to sei()s and don't have ISR()s ?

Last Edited: Sun. Sep 18, 2011 - 02:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR Simulator..

Ok, I'll try AVR Simulator 2. If the first one doesn't work, why is it available for use.. ?

Also, the code was just an exerpt so you didn't have to look through tons of unrelated code. The I bit is actually set. My bad.

I know my coding is a little hard to read. It's a handicap I have from doing my first programming in assembler, so I never really got used to setting bits the "right" way.

Last Edited: Sun. Sep 18, 2011 - 02:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See my edit above - that works just fine in Sim2. The fact you are using sim1 suggests you haven't read the manual yet - I suggest you do.

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

Sweet. Now it works. Thanks man :)
Reading manuals is the absolute last desperate thing a man does, just before crying and calling for his mom.
Which one are you referring to, exactly? The AVR Studio manual?

Anyway, I read the data sheet about 20 times over and couldn't figure out what the problem was.

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

Quote:

Which one are you referring to, exactly? The AVR Studio manual?


Within the AVR Studio online help you'll find a manual about the simulator. Writ large is "if your AVR is supported by Sim2 always use that". Sim1 is there for the old models that have not made the transition yet.

Last Edited: Sun. Sep 18, 2011 - 03:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, will do.