Only working when single steping

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

Using JTAG, -01 optimization and -g3 debug.

This function is called every 10mS to poll a button from the main loop.

It seems like If I don't put breaks on every case on this case statement, it goes haywire and skips or crashes. It runs single step fine, but not free running. button_A_state is not modified anywhere else in my project other than what you see here.

What could cause this type of behavior?

void Poll_Buttons(void){
	//button states
	// 0 - idle
	// 1 - pressed and evaluated to be pressed once, waiting for bounce to end.
	// 2 - wait for button to be released
	// 3 - timeout
	// 4 - timeout
	// 5 - start increment it for inactive time after a complete press 
	// 31 - active again
	//default - increment the state 
	switch (button_A_state){
		case 0: //idle button
			if(bit_get(PINA,BIT(1)) == 0){ //if 0 then the button is pressed we need to wait for de-bounce
				button_A_state = 1; 
			}						
			break;
		case 1://testing the button again
			if(bit_get(PINA,BIT(1)) == 0){ //if still 0 then the button is pressed
				button_A_state = 2; 
				buttonA=1; //register for the main program to poll for a button press
			}
			else{
				button_A_state = 0;
			}			
			break;
		case 2: //wait for button to be released
			if(bit_get(PINA, BIT(1))){ //test to see if the button was released yet
				button_A_state = 3; 
			}			
			break;
		case 3: //this case is just to give a bounce timeout for the end of the button
			NOP;
			button_A_state = 4;
			break;
		case 4: //this case is just to give a bounce timeout for the end of the button
			NOP;
			button_A_state = 5;
			break;
		case 5: //here we are going to set it to 6 which there is no case for, which will send it to default which will increment it till it reaches 31
				// this will give a 250mS time out before the button is considered active again
			button_A_state =6;
			break;
		case 31: //total buttons state is complete, make it active again
			button_A_state = 0; 
			break;
		default: 
			button_A_state ++;
			break;
	}	
}
void Buttons_Setup(void){
	DDRA|= (IN << PINA1)| (IN << PINA2) | (IN<< PINA3); //the switch inputs
	PORTA |= (1<<PORTA1) | (1<<PORTA2) | (1<<PORTA3); //the switch inputs pull up resistor enable
	
	//DDRC|= (IN << PINC3); //this is the sheared JTAG pin, need to disabled it for debugging
	//PORTC |= (1<<PORTC3);
}

You don't gno-me!

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

Maybe the problem is elsewhere?

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

yup. I had a run away someplace else :-(
It works fine now.

NEVERMIND!

You don't gno-me!

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

Never knew there were avrfreaks in Clearwater. I'm in Zephyrhills everyday.

Imagecraft compiler user