[solved] Code does not work with newer version of WinAVR.

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

Hi

Pardon me this question but I cannot figure out exactly what changes were made to newer versions of winavr. I am using WinAVR20071221 and I would like to jump to newer version of WinAVR20100110.

Problem is that when I install new version and compile code, program doesn`t work as it used to. I assume some major changes were made to newer versions.

Could you tell me or give me some reference what was changed and how to transform code?

Thanks in advance...

Last Edited: Thu. Oct 20, 2011 - 10:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
program doesn`t work as it used to.

Which program GCC or your target code?
In what way is the behaviour different?
Any compiler errors or warnings?

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

It may be better if you post the errors you get or even the program for someone to look at.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

No compiler errors. Compiles smoothly...
First problem which I see is with reading peripheral buttons.
When I press buttons they don`t work.
ISR routine for debouncing code doesn`t work?

Quote:
Which program GCC or your target code?

I meant target code.

Target code works with older version of Winavr and doesn`t work with newer one.

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

Quote:
When I press buttons they don`t work.
ISR routine for debouncing code doesn`t work?

Missing pull-up resistors?
Later revision of Silicon?
You may have a latent bug in your code/hardware which has possibly been exposed by changes in GCC(optimizer?).
Rather than trying to debug(?) GCC, you would be best off fixing the latent bug!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

I am using internal pull-up resistors.
Silicon is ok it works.

Quote:
ou may have a latent bug in your code/hardware which has possibly been exposed by changes in GCC(optimizer?).
Rather than trying to debug(?) GCC, you would be best off fixing the latent bug!

Yes you are right this can be this problem...

I am pasting code of ISR debouncing routine. I changed it slightly to read keypad. It works but doesnt want to work with newer version.

ISR(TIMER0_OVF_vect)
{
	static uint16_t ct0, ct1, rpt;
	uint16_t i,odczyt_4bity;


  TCNT0 = 	(uint8_t)(int16_t)-(F_CPU / 1024 * 2.5e-3 );	// preload for 10ms
  
	

	if (row==0)
	{
		odczyt_4bity=((KEY_PIN >>4)&(0x000f));
		odczyt|=odczyt_4bity; //ustawiam jedynki
  		odczyt&=(odczyt_4bity|=0xfff0); //ustawiam zera
	}
	if (row==1)
	{
		odczyt_4bity=KEY_PIN &0x00f0;
		odczyt|=odczyt_4bity; //ustawiam jedynki
  		odczyt&=(odczyt_4bity|=0xff0f); //ustawiam zera
			
	}

	if (row==2)
	{
		odczyt_4bity= (( KEY_PIN <<4 )&(0x0f00));
		odczyt|=odczyt_4bity; //ustawiam jedynki
  		odczyt&=(odczyt_4bity|=0xf0ff); //ustawiam zera
	}

	if (row==3)
	{
		odczyt_4bity= (( KEY_PIN <<8 )&(0xf000));
		odczyt|=odczyt_4bity; //ustawiam jedynki
  		odczyt&=(odczyt_4bity|=0x0fff); //ustawiam zera
	}

  
  i = key_state ^ ~odczyt;		// key changed ? ~ wtedy gdy zero jest active
  ct0 = ~( ct0 & i );			// reset or count ct0
  ct1 = ct0 ^ (ct1 & i);		// reset or count ct1
  //ct2 = (ct0 & ct1) ^ (ct2 & i);
  //ct3 = (ct0 & ct1 & ct2) ^ (ct3 & i);
  i &= ct0 & ct1;				// count until roll over ?
  key_state ^= i;				// then toggle debounced state
  key_press |= key_state & i;	// 0->1: key press detect
  
  
  PORTD|=(1<<row);
  if (row==3)
	{
		row=0;
		
	}	
  else
	row++;
  
  PORTD&=~(1<<row); // sprawdzaj odpowiedniÄ… kolumnÄ™ nie wiem czy akurat w tym miejscu !!!	
  
  
 if( (key_state & REPEAT_MASK) == 0 )	// check repeat function
	rpt = REPEAT_START;					// start delay
  if( --rpt == 0 )
	{
		rpt = REPEAT_NEXT;		// repeat delay
		key_rpt |= key_state & REPEAT_MASK;
		//dodana przeze mnie linia umozliwiajaca o holdzie nie zliczanie key_pressa, :)
		//key_press&= ~REPEAT_MASK;
	}


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

Are you using optimization? Is it still at the same level as before? Which level?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

It looks all Greek to me! (Sorry George!)

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

I have always used -Os optimization. Always had the same optimization set in make file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
TCNT0 =    (uint8_t)(int16_t)-(F_CPU / 1024 * 2.5e-3 ); 

This line looks fishy, [wrong text removed, see post by sternst]
Also you're casting a negative number to an unsigned variable.

Shouldn't this be something like

#define TCNT0VAL (F_CPU / 1024 / 400)
..
TCNT0 = TCNT0VAL ;

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

Last Edited: Thu. Oct 20, 2011 - 10:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I really don't understand the ISR and the debouncing technique used.
However, IMHO, your ISR to long and that cannot be good!
ISR's should be short & fast!
Use CTC mode rather than overflow to make your ISR shorter & faster.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

Quote:
This line looks fishy, you're using floating point ops at runtime to calc this, while it is a constant known at compile time. Let the preprocessor calc it.
Also you're assigning a negative number to an unsigned variable.

That`s why casting is used there. I have tested it on AVRstudio and this line works although indeed maybe newer compiler interprets it differently.

ISR maybe looks long but it is one of the best codes for debouncing. It is long here because I had to use line testing for keypad and needed 16 keys.

Quote:
Use CTC mode rather than overflow to make your ISR shorter & faster.

Assigning new value to TCNT0 has this advantage that next overflow will be exactly after time I want including code in ISR. Using CTC gives me time + time for code in ISR.

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

Quote:
Using CTC gives me time + time for code in ISR.

No, in CTC mode, the time between entry of each ISR will be exactly the same each time unless main code is running an atomic access block while the interrupt occurs, then it will be a few instructions later, but that is also the case for your current method.

Whether the ISR takes 10 or 100 instructions to finish, the time will always be the same as long as the interrupt is not overrun.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

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

thygate wrote:

TCNT0 =    (uint8_t)(int16_t)-(F_CPU / 1024 * 2.5e-3 ); 

This line looks fishy, you're using floating point ops at runtime to calc this, while it is a constant known at compile time. Let the preprocessor calc it.

Sorry, but that is nonsense. The preprocessor never calculate something (with one exception). His version is also calculated by the compiler at compile time, just as your version.

Stefan Ernst

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

Quote:
No, the timer keeps running, and is reset by the peripheral before entry into the isr.
The time between entry of each interrupt will be exactly the same each time unless main code is running an atomic access block while the interrupt occurs, then it will be a few instructions later, but that is also the case for your current method.

Pardon me it is late at night you are right. I was thinking about something else.

I have changed suspicious line for simple assigning and it is still the same.

TCNT0 = 27;

And now surprise.
I have changed optimalization to -0 and it works.

Quote:
You may have a latent bug in your code/hardware which has possibly been exposed by changes in GCC(optimizer?).
Rather than trying to debug(?) GCC, you would be best off fixing the latent bug!

Yes I wonder what is wrong for the compiler.

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

Quote:
Sorry, but that is nonsense. The preprocessor never calculate something (with one exception). His version is also calculated by the compiler at compile time, just as your version.

Yes, you are right, the preprocessor still just substitutes it and the compiler will see it's a constant and actually calculate it. It's not using any float ops at runtime. I still think it obfuscates the line when "* 2.5e-3" is used as opposed to "/400", and using a definition is probably a personal preference.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it"

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

Quote:
I am pasting code of ISR debouncing routine.
And where are the declarations of key_state, key_press, and key_rpt?

Stefan Ernst

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

Quote:
And where are the declarations of key_state, key_press, and key_rpt?

What a shame guys I mad a newbie mistake I forgot or missed volatile before Key_press and key_state :(

I would like to thank you for your impact helping me. Once again I am glad I am part of this forum and this amazing community. :)

P.S. I will improve code by switching to CTC mode.

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

To Stefans list above, add "row"

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

LDEVRIES wrote:
To Stefans list above, add "row"
I didn't ask for "row" and "odczyt" because they don't need to be volatile. ;-)

BTW: It would make sense to put them into the ISR as static local.

Stefan Ernst