Optimize problem

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

Hi all,

I'm trying to make software keypad4x4 by using ATMEG64 with GCC. The software will get the keypad and convert it to 16bit key status (bit0 = KEY1 status...bit15 = KEY16 status), then using danni debounce routine to debounce these key status. After test with optimization -O0 level it work fine. But not work on others optimization level. Could any one point me to solve this problem ? Can I make it work with optimize setting ?

Regards,
firmware

     Keypad connecting

       |   |   |   | 
PD4  --|- -|- -|- -|--
PD5  --|- -|- -|- -|--
PD6  --|- -|- -|- -|--
PD7  --|- -|- -|- -|--
       |   |   |   |
      PD0 PD1 PD2 PD3

Attachment(s): 

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

This shows all the signs of the avr-libc FAQ #1: Variables that are assigned in the ISR(s) and used in other parts of the program must be declared volatile.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Perhaps this thread would help to sort you out.

https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=70618

Basically same question that you have.

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

JohanEkdahl wrote:
This shows all the signs of the avr-libc FAQ #1: Variables that are assigned in the ISR(s) and used in other parts of the program must be declared volatile.
'

I didn't debounce key in the ISR. Only one shared variable between ISR and main I already attached valatile keyword.

Thank you.

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

It seem the problem was solve. I Just move " key_bit " variable to the global type not use auto type.

u16 scan_key( void )
{
	u08 col, row;                   
	u16 keybit = 0, count_bit = 0;  

   KEY_DDR = 0xF0;                 
   KEY_PORT = 0x0F;               
	if(~KEY_PIN&0x0F) 						
	{
		KEY_PORT = 0xFF;             
		          
		for(col=0; col 1)     
				 			return 0;            
       		}
      	}
		 	}
		}
	}                                  

	return key_bit;                    
}

Modified to

u16 key_bit;

u16 scan_key( void )
{
	u08 col, row;                   
	u16 count_bit = 0;  

   KEY_DDR = 0xF0;                 
   KEY_PORT = 0x0F;               
	if(~KEY_PIN&0x0F) 						
	{
		KEY_PORT = 0xFF;             
		key_bit = 0;
		          
		for(col=0; col 1)     
				 			return 0;            
       		}
      	}
		 	}
		}
	}                                  

	return key_bit;                    
}