Does not work after implementing 2 interrupts

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

Hi,

i have two interrupt service routines and i am sure they both work as i've test them individually along with the main program.

However when i want to implement both of them together, my atmega48 doesn't even response to any of my button pushes.

the interrupt service routines are for the USART and the debouncing algorithm by the "Debouncing Bible" by Jack G.Ganssle.

I used a timer overflow to implement the ISR for my debounccing algo.

Is it possible that one of the ISR is causing the problem ? but i suspect it might be the timer overflow used in the debouncing algo might be probing my input buttons too often.

Please advise .. Thanks !!

Cheers

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

An advice would be to show the code before we can help..

- Jani

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

And if you can't see the code running on the actual AVR using a JTAG or DebugWire interface then it can always be illuminating to have a look at it in the AVr Studio simulator to see what's going wrong/not happening. (except that you have to fake any external stimulation of the AVR to do this)

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

ok ill take a look at AVR studio , cuz my code is quite long , not sure how to show u guys. thanks anyway !

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

hmm , i am currently trying AVR Studio,
imported all my source files and makefiles in there
it compiles but when i pressed "build and run"
tonnes of errors popped out saying like those predefined register named (eg: ADCH , PD0 , PORTD etc etc) are undeclared ?

i've already include the library
which has already defined them.

what did i do wrong ?

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

Don't try to BUILD the code in Studio. Presuambly your existing build systems ends up with the production of a .elf file? You just load that into Studio to debug it.

But if you want to build within Studio do one of two things:

1) visit project-configration options and make sure "device" is set to your AVR, also change "optimisation" to be -Os and under the libraries tab move libm.a from the left pane to the right one

OR

2) under project-configuration options just tick the "use external makefile" box and direct it to the Makefile you were using previously

Cliff

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

yep thanks ! got it to work.

i was wondering how can you generate theses dummy variables ? like i want to test the USART
how can i generate a dummy signal interrupt for the RX pin of atmega ?

i tried assigning the receiving register with some value in avr studio but it keeps changing back to 0x00 whenever i step through the program.

Last Edited: Tue. Apr 17, 2007 - 05:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Studio simulator does not support simluation of external input to the UART (either VMLab or Hapsim - both free - does though). What you have to do in Studio simulator is set a breakpoint where it's about to read UDR then fake a value into the register (maybe wait for it to do the IN/LDS and then just load the value into Rn). Alternatively replace your uart_readchar() routine with:

unsigned char uart_readchar(void) {
 const char fake_data[] = { "Hello world\n"};
 static unsigned char fake_ptr;
 unsigned char retval;

 retval = fake_data[fake_ptr];
 fake_ptr++;
 if (fake_ptr > strlen (fake_data)) {
   fake_ptr=0;
 }
 return retval;
}

Or something along those lines.

Cliff

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

i found my problem using hapsim and avr studio simulator

#define 	TMR0START 		0x00 //set it to define how long to probe input
#define 	MAXCHECKS		10
void setupTimer0(void);
static volatile unsigned int Debounced_State;
static volatile unsigned int State[MAXCHECKS];
static volatile unsigned int Index =0;
	


//--------------------------------------------------------------
// interrupt routine to service overflow on counter 0
// see avr_libc reference manual \winavr\doc\avr-libc
SIGNAL(SIG_OVERFLOW0)
{

	TCNT0 = TMR0START;		//restart counter	
//////////////////////////////////////////////
	int i,j;
	State
=PINC; ++Index; j=0xFF; for(i=0; i=MAXCHECKS)Index=0; ////////////////////////////////////////////////////// TIFR0 &= ~(1<<TOV0); //clear interrupt flag } void setupTimer0(void) { // set prescale TCNT0 = TMR0START; // set counter0 to initial value TIMSK0 |= (1<<TOIE0); //enable timer0 overflow interrupt. }

and i found out that my once i initiated sei() (global interrupts) in my main program. the interrupt service routine doesn't return to the main program ?

my usart returned back to the main program but my debouncing code using the timer interrupt vector doesn't at all !

i am not sure whats wrong ! hmm please advise . thank you

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

Well where DOES it return to ?

Put a breakpoint on the interrupt vector and when it occurs look at the stack state. Then single step the operation of the ISR (it should be ISR() not SIGNAL() by the way!) and when it gets to the epilogue and finally the RETI compare the stack state to that on entry - did something over-write the return address?

Cliff

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

ahhh i found my mistake , was clearing my interrupt flag the wrong way. now this has been solve. another problem arised

regarding my debouncing algo above, whenever it jumps into ISR of the debouncing algo , State[n] does not save whatever is in PINC.
Tried using HapSim with AVR Studio (im quite sure i did it right) .

thanks clawson :) u've been of great help.