Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Help, Compiler ignores some part of the function! [RSS Feed]

#1 Dec. 2, 2005 22:21:37

MuRaT K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Help, Compiler ignores some part of the function!


Title:MessageHello All,Using WinAVR-20050214, I try to compile the following
function, but the section between and 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. What is wrong? Thanks.Murat Karadenizhttp://www.onlinefavbar.com/mukas   Note: target CPU is ATMEGA16 and avr-size after
compilation gives:text data bss dec hex filename11065 78 585 11728 2dd0 main.elf void ProcessPID_Vertical(){#define encoder Motor1_Counter#define PWMchannel 1#define IntegralActivationLimit 12static 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 axisErrorVertical = error = ( DestinationVertical /
enc1_constant ) - encoder; #endif#ifndef USE_INTERNAL_ENCODER_CONSTS
//destinationVertical given in encoder ticks at the motor encoder for the same
final motionErrorVertical = error = DestinationVertical -
encoder;#endifif (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;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);elsecontroller = (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);elsecontroller = (int) ( p1*error + d1*(error
-prev_prev_error)/2);}/*if ( controller > 0 )SetDirection2(LEFT);elseSetDirection2(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));}_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Dec. 2, 2005 23:40:33

Mike Y.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Help, Compiler ignores some part of the function!


Title:MessageI would think the lst file is in error rather than the
compiled result. (How else can we continue on with any sanity?) It's not unusual
for the compiler to inline static functions, but that likely isn't the situation
here. Maybe try rewriting the condition as an extern (as opposed to
static) function: If nothing else, it will clean up the error value
calc.     if (IsInRange(errVal, lowVal,
HiVal))    { ... }    else    { ...} Turning off optimization won't give you meaningful information
about optimized assembler. Try adding a debug print statement in the true and false
sections. (Flash a light, bleep a bleeper, write to the usart, ...) ----- Original Message -----From:MuRaT KaRaDeNiZTo:avr-gcc-l***@*ongnu.orgSent:Friday, December 02, 2005 4:20
PMSubject: Help, Compiler
ignores some part of the function!Hello All,Using WinAVR-20050214, I try to compile the
following function, but the section between and 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. What is
wrong?_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Dec. 3, 2005 04:15:58

Daniel O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Help, Compiler ignores some part of the function!


On Sat, 3 Dec 2005 08:50, MuRaT KaRaDeNiZ wrote:
> Using WinAVR-20050214, I try to compile the following function, but the
> section between and 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. What is
> wrong?

It is being optimised away.
The variable 'controller' has no effect because the last line of the function
is commented out.

Also, the formatting is fairly hard to read. A good convention is to make
#defines all upper case so that you can easily distinguish them.

The preprocessor supports #else too, so you should probably do stuff like..

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

If you are going to paste code and error messages and your email client
insists on wrapping them, please send them as attachments. That way they
are _much_ easier to read.

Another style issue - if your function takes no arguments you should
declare it like..

void Foo(void)
{
..
}

Some indenting makes things easier to read, eg..
if (foo) {
abc;
def;
} else {
bar;
baz;
}

If you wish to comment out a block of code it is safer to use '#if 0' as
you don't get any problems with nested comments.

I'm not sure if you're compiling with -Wall, but that is almost always
a good idea as the compiler will usually tell you when you make mistakes
even if it feels like it's being too picky :)

--
Daniel O'Connor software and network engineer
for Genesis Software -http://www.gsoft.com.au"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8Cpgp22AOTb82TM.pgpDescription:PGP signature_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Attachments:
attachment pgp22AOTb82TM.pgp (187 bytes)

Offline

#4 Dec. 3, 2005 11:58:05

MuRaT K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Help, Compiler ignores some part of the function!


Hello,

Thanks for the help. As you stated, the compiler was optimizing and
removing that section of the code.
I'll consider your additional comments on coding style & posting.

I'm compiling with -Wall, but no warning appears for the local variable
"controller", that it is not utilized properly.


Regards

Murat Karadenizhttp://www.onlinefavbar.com/mukas-----Original Message-----
From: Daniel O'Connor
Sent: Saturday, December 03, 2005 6:15 AM
To: avr-gcc-l***@*ongnu.org
Cc: MuRaT KaRaDeNiZ
Subject: Re: Help, Compiler ignores some part of the
function!


On Sat, 3 Dec 2005 08:50, MuRaT KaRaDeNiZ wrote:
> Using WinAVR-20050214, I try to compile the following function, but
> the section between and 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. What is
> wrong?

It is being optimised away.
The variable 'controller' has no effect because the last line of the
function is commented out.

Also, the formatting is fairly hard to read. A good convention is to
make #defines all upper case so that you can easily distinguish them.

The preprocessor supports #else too, so you should probably do stuff
like..

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

If you are going to paste code and error messages and your email client
insists on wrapping them, please send them as attachments. That way they
are _much_ easier to read.

Another style issue - if your function takes no arguments you should
declare it like..

void Foo(void)
{
..
}

Some indenting makes things easier to read, eg..
if (foo) {
abc;
def;
} else {
bar;
baz;
}

If you wish to comment out a block of code it is safer to use '#if 0' as

you don't get any problems with nested comments.

I'm not sure if you're compiling with -Wall, but that is almost always
a good idea as the compiler will usually tell you when you make mistakes
even if it feels like it's being too picky :)

--
Daniel O'Connor software and network engineer
for Genesis Software -http://www.gsoft.com.au"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#5 Dec. 3, 2005 12:42:40

Daniel O.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Help, Compiler ignores some part of the function!


On Sat, 3 Dec 2005 21:16, MuRaT KaRaDeNiZ wrote:
> I'm compiling with -Wall, but no warning appears for the local variable
> "controller", that it is not utilized properly.

Yeah, it won't warn you about those sort of problems alas.

--
Daniel O'Connor software and network engineer
for Genesis Software -http://www.gsoft.com.au"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8CpgpuRd4v7MXKn.pgpDescription:PGP signature_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Attachments:
attachment pgpuRd4v7MXKn.pgp (187 bytes)

Offline

#6 Dec. 3, 2005 21:33:44

Nigel W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Help, Compiler ignores some part of the function!


> On Sat, 3 Dec 2005 21:16, MuRaT KaRaDeNiZ wrote:
> > I'm compiling with -Wall, but no warning appears for the
> local variable
> > "controller", that it is not utilized properly.
>
> Yeah, it won't warn you about those sort of problems alas.
>


Oh yes it will, but you have to add the specific warning

-Wunreachable-code

I had to perform much hacking of your code sample to get it to compile.
When you enable the above warning you'll receive the following compiler
messages:

avr-gcc -c -mmcu=atmega32 -gdwarf-2 -Os -funsigned-char -funsigned-bitfields
-fpack-struct -fshort-enums -fno-loop-optimize -mcall-prologues -Wall -Wstr
ict-prototypes -Wunreachable-code -Wno-char-subscripts -Wsign-compare -W -Wa
,-adhlns=murat.lst -std=gnu99 -MD -MP -MF .dep/murat.o.d murat.c -o

murat.c:14: warning: function declaration isn't a prototype
murat.c: In function `ProcessPID_Vertical':
murat.c:69: warning: will never be executed

Line 69 is, of course: controller = (int)
p1*error*PTERM_AMPLIFICATION_MAGNITUDE_V ...

Nigel Winterbottom




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Help, Compiler ignores some part of the function! [RSS Feed]

Board footer

Moderator control

Enjoy the 23rd of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support