Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
nebk
PostPosted: Jul 02, 2012 - 11:50 PM
Newbie


Joined: Feb 11, 2011
Posts: 8


Hi,
I'm using an attiny2313 for a 3x3x3 led cube, but I'm running into trouble with the interrupt routine. It only seems to fire once. I've chopped down the code for debugging.

main.c
Code:

#define F_CPU 1000000
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "hardware.h"

//definitions
void start_interrupt(void);//init
int main(void);

int main(){
   DDRD=0x7F;//enable lights
   DDRB=0x3F;
   start_interrupt();
   for(;;){
      _delay_ms(250);//delay to show lights
      PORTB=0x00;//clear all
      PORTD=0x00;
   }
   return 0;
}

void start_interrupt(){
   TCCR0A|=(1<<WGM01);//set to CTC mode
   TCCR0B|=(1<<CS01);//set prescaler to 1/8
   OCR0B=125;//interrupt every 1/1000th of a second
   TIMSK|=(1<<OCIE0B);//enable compare interrupt B
   sei();//enable interrupts
}

ISR(TIMER0_COMPB_vect){//compare interrupt B
   PORTB|=(1<<L2);//enable 2nd layer
   PORTD|=(1<<A5);//enable middle led
}


hardware.h
Code:

/*
 * hardware.h hardware specific information
 */
#ifndef _HARDWARE_
#define _HARDWARE_

//layers
#define L1   4 //PORTB
#define L2   3
#define L3   2
//anodes
#define A1   0 //PORTD
#define A2   1
#define A3   2
#define A4   3
#define A5   4
#define A6   5
#define A7   6
#define A8   0 //PORTB
#define A9   1

#endif   


thanks,
nebk


Last edited by nebk on Jul 03, 2012 - 01:19 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 02, 2012 - 11:53 PM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20360
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

And how are you debugging? Are you using a DW tool to set breakpoints in different areas?

And why the strange main sequence?

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
sternst
PostPosted: Jul 03, 2012 - 12:14 AM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2438
Location: Osnabrueck, Germany

nebk wrote:
It only seems to fire once.
Because you are using the wrong compare match. CTC works with A (OCR0A), not B.

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
nebk
PostPosted: Jul 03, 2012 - 01:17 AM
Newbie


Joined: Feb 11, 2011
Posts: 8


Thanks sternst,
That was the problem, but why is there a TIMER0_COMPB vector for the attiny2313 if the interrupt doesn't work?
Thanks for all the replies.
-nebk
 
 View user's profile Send private message  
Reply with quote Back to top
sternst
PostPosted: Jul 03, 2012 - 02:16 AM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2438
Location: Osnabrueck, Germany

nebk wrote:
That was the problem, but why is there a TIMER0_COMPB vector for the attiny2313 if the interrupt doesn't work?
Who said that it does not work? It does work! It is only useless for your setup. There are more possible configurations for the timer than the single one you are currently using.

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
nebk
PostPosted: Jul 03, 2012 - 03:01 AM
Newbie


Joined: Feb 11, 2011
Posts: 8


Thanks for the explanation.
-nebk
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits