no interrupts tho main() is executing

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

When I start the 8535, the main() function exectutes (indicated by a LED) but the timer0 interrupt won't work (2nd LED doesn't flash). If I disconnect Vcc and reconnect it, sometimes the interrupt starts working. Any clue how/why that is and what to do?

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

Present some code, and we'll be able to tell.

Tobias

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

It's possible Yoa are not initiate a stack pointer.

admin's test signature
 

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

/* Here's the code (main-function code removed)
All the main() did was flash a LED on PORT B */

#include
#include
#include

/* Timer test: flashes LEDs on PORTC
once a second through timer0-interrupt */

unsigned char led;

/* timer0 interrupt flashing all LEDs on PORTC */
SIGNAL(SIG_OUTPUT_COMPARE1A)
{
PORTC = led;
led=~led;
}

void init(void)
{
outp(0xFF,DDRC); /* LEDs on pin0-7, output */

outp((1<<OCIE1A), TIMSK);
TCCR1B |= 0x0C; /* reset counter on match */
outp(0x0000, TCNT1); /* reset counter */
OCR1A = 31250; /* interrupt every second (at 8Mhz) */

led = 0x0F; /* LED0-3 off, 4-7 on */
PORTC = 0xAA; /* pattern that SHOULD disappear... */
/* ...one second after startup */
}

int main(void)
{
init();
sei();
for(;;);
}

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

I don't have the datasheets in front of me, or AVRCalc, but IIRC at /1024 divider, the 8 bit timers reach about 32ms. at 8MHz clock. IF that is correct, I don't think that timer0 can reach 1 second.

Next, upon inspection of the code, I see references to timer1, not timer0.

Then, I looked more, and saw that the code was entered for the output compare interrupt, not the timer overflow interrupt that I was expecting.

I am not familiar with the compiler and syntax, but it looks to me like most things are in pretty good shape--global interrupts enables with SEI, OCR1A set (I assume correctly), TIMSK bit set, TCCR1B to start the timer and interrupt on compare match.

One thing interests me a little bit, not knowing your compiler--why is there an outp() call for DDRC & TIMSK, but no outp() for PORTC--just straight assignements.

Lee

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

You're right. I use timer1, which is a 16-bit counter. My fault, but still there should be some interrupt.

The reason why I don't use the overflow interrupt is simply that I want an interrupt after 1s. Prescaler set to 1/256 means 8M/256=31250 ticks per second, right? So when the counter1 reaches 31250 it's reset to 0 and starts counting again, and the interrupt-routine is called.

I use the GCC-compiler which refers to outp() as "black magic". I don't know what the heck that means, but maybe that's what's causing the problem. I know writing to an interrupt register can cause malfunction if you reset bits associated with other interrupts, and not just the one you're working with. I'll avoid outp() in the future and see how that works.

Another thing I'm curious about is how to write 16-bit instructions in C. That is writing 16 bits with ONE instruction. Since the counter is 16 bits wide I want to clear them with the same instruction. Is "dest=0x0000" correct?

(Come to think of it I think the datasheet says something about writing the low word first and then the high... At least the A/D converter register...hmmm)

OK, cheers.