Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Help, Compiler ignores some part of the function!

Help, Compiler ignores some part of the function!

2005-11-11 by karademu

Hello All,

Using WinAVR-20050214, I try to compile the following function, but 
the section between [BOOKMARK1] and [BOOKMARK2] does not get compiled 
without any error indication. İ checked the routine in the .lst file, 
this section is not compiled to assembly. The rest is there. Any idea, 
what is wrong?


Thanks.

Murat Karadeniz
http://www.onlinefavbar.com/mukas




Note: target CPU is ATMEGA16 and avr-size after compilation gives:

   text    data     bss     dec     hex filename
  11065      78     585   11728    2dd0 main.elf	


void ProcessPID_Vertical()
{	
	#define encoder Motor1_Counter
	#define PWMchannel 1
	#define IntegralActivationLimit 12

	
	static long integral_error = 0;
	static long prev_error = 0;
	static long prev_prev_error = 0;

	long error;
	
	int controller;


#ifdef USE_INTERNAL_ENCODER_CONSTS 				//
destinationVertical given in angles at the final moving axis
	ErrorVertical = error = ( DestinationVertical / enc1_constant ) 
- encoder; #endif
#ifndef USE_INTERNAL_ENCODER_CONSTS				//
destinationVertical given in encoder ticks at the motor encoder for 
the same final motion
	ErrorVertical = error = DestinationVertical - encoder; 
#endif

	if (error  == 0)
		controller = 0;
	else
	{
		integral_error += i1*error*10;

		if (integral_error > INTEGRAL_LIMIT_V)  integral_error = 
INTEGRAL_LIMIT_V;
		if (integral_error < -INTEGRAL_LIMIT_V) integral_error = -
INTEGRAL_LIMIT_V;

[BOOKMARK1]				
		if ((d1*(error -prev_prev_error)/2 < 
IntegralActivationLimit) && (d1*(error -prev_error)/2 > -
IntegralActivationLimit)) 
		{
			if ((error < PTERM_AMPLIFICATION_CLOSURE_V) && 
(error > -PTERM_AMPLIFICATION_CLOSURE_V))
				controller = (int) ( 
p1*error*PTERM_AMPLIFICATION_MAGNITUDE_V + integral_error/10 + 
d1*(error -prev_prev_error)/2);
			else
				controller = (int) ( p1*error + 
integral_error/10 + d1*(error -prev_prev_error)/2);

		}
		else
		{
			if ((error < PTERM_AMPLIFICATION_CLOSURE_V) && 
(error > -PTERM_AMPLIFICATION_CLOSURE_V))
				controller = (int) ( 
p1*error*PTERM_AMPLIFICATION_MAGNITUDE_V + d1*(error -prev_prev_error)
/2);
			else
				controller = (int) ( p1*error + d1*(error -
prev_prev_error)/2);

		}
[BOOKMARK2]	
		/*
		if ( controller > 0 )
			SetDirection2(LEFT);
		else
			SetDirection2(RIGHT);
		*/

		if ( controller > SPEED_LIMIT_V ) controller = 
SPEED_LIMIT_V;
		else if ( controller < -SPEED_LIMIT_V ) controller = -
SPEED_LIMIT_V;
		
	}

	prev_prev_error = prev_error;
	prev_error = error;

	//WritePWM(PWMchannel, abs(controller));

}

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.