Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Odd counter problems (http://www.chiefdelphi.com/forums/showthread.php?t=25405)

Catastrophy 16-02-2004 13:23

Odd counter problems
 
Ok well, I'm trying to run through a loop where it does

armcounter++;

Armcounter is defined at the top of user_routines_fast.c. I try a print_f to print out armcounter but it gives [null] on the ifi_loader. My motors just keep running for ever because it doesn't ever have armcount equal to the number I supply. Any clues????? :confused::ahh:

Joe Ross 16-02-2004 13:25

Re: Odd counter problems
 
you need to declare armcounter as a static int. Otherwise, it gets created and destroyed on the stack each time you enter and leave the function.

Ryan M. 16-02-2004 13:28

Re: Odd counter problems
 
Quote:

Originally Posted by Catastrophy
Ok well, I'm trying to run through a loop where it does

armcounter++;

Armcounter is defined at the top of user_routines_fast.c. I try a print_f to print out armcounter but it gives [null] on the ifi_loader. My motors just keep running for ever because it doesn't ever have armcount equal to the number I supply. Any clues????? :confused::ahh:

You'd have to show me how you have the printf setup, but you probably got it wrong. This should be similar to what your printf should be:
Code:

printf("\nArm counter: %i\n", (int)armcounter);

Ryan M. 16-02-2004 13:29

Re: Odd counter problems
 
Quote:

Originally Posted by Joe Ross
you need to declare armcounter as a static int. Otherwise, it gets created and destroyed on the stack each time you enter and leave the function.

He says at the top of user_routines_fast.c. I assume that means he made it a global.

PS What type is armcounter?

Catastrophy 16-02-2004 13:56

Re: Odd counter problems
 
its a short.

Ryan M. 16-02-2004 14:02

Re: Odd counter problems
 
Quote:

Originally Posted by Catastrophy
its a short.

Try the printf I showed earlier. It should work. Just copy and paste it over your old one.

Catastrophy 16-02-2004 14:28

Re: Odd counter problems
 
ok I did and now theres nothing there, its not printing anything.

Ryan M. 16-02-2004 14:33

Re: Odd counter problems
 
Quote:

Originally Posted by Catastrophy
ok I did and now theres nothing there, its not printing anything.

Hum, well, try just using the following line. It's guarranteed to print and if it doesn't, it means that it is never getting called and you'll have to look at your code.

Code:

printf("Test");

--EDIT--
If it doesn't work then post your code and people can look at it.

Catastrophy 16-02-2004 14:44

Re: Odd counter problems
 
1 Attachment(s)
It printed test but here it is. I'm using a basic auto right now so i can debug everything first.

Ryan M. 16-02-2004 14:54

Re: Odd counter problems
 
Quote:

Originally Posted by Catastrophy
It printed test but here it is. I'm using a basic auto right now so i can debug everything first.

What exactly is the output say? Does the 'arm value of armcounter' print anything? What does it print?

--EDIT--
Try changing the %i in the printf to %d.

rbayer 16-02-2004 14:57

Re: Odd counter problems
 
A few things I saw after glancing at it:
Code:

if (armcounter = 15) //will raise arm.
  pwm06=0;
else
  armcounter++;
  pwm06=255;

sould be
Code:

if (armcounter == 15) //will raise arm.
  pwm06=0;
else {
  armcounter++;
  pwm06=255;
}

It is VERY rare that you'll actually want to use a single = in an if, so watch out for that, and also be careful with your curly braces.

That said, I believe the code in its original form should have printf'd 15 over and over and over. Was it doing that, or just not printing anything?

Ryan M. 16-02-2004 15:03

Re: Odd counter problems
 
Quote:

Originally Posted by rbayer
A few things I saw after glancing at it:
Code:

if (armcounter = 15) //will raise arm.
  pwm06=0;
else
  armcounter++;
  pwm06=255;

sould be
Code:

if (armcounter == 15) //will raise arm.
  pwm06=0;
else {
  armcounter++;
  pwm06=255;
}

It is VERY rare that you'll actually want to use a single = in an if, so watch out for that, and also be careful with your curly braces.

That said, I believe the code in its original form should have printf'd 15 over and over and over. Was it doing that, or just not printing anything?

Missing a = is an easy thing to do. It's one of those powerful, useful things that C/C++ lets you do, but isn't what you want most of the time. :)

Catastrophy 16-02-2004 15:08

Re: Odd counter problems
 
Well the = was something i accidently did when moving it i had it in the code i was using. and btw its just not printing anything.

Ryan M. 16-02-2004 15:09

Re: Odd counter problems
 
Quote:

Originally Posted by Catastrophy
Well the = was something i accidently did when moving it i had it in the code i was using. and btw its just not printing anything.

So, the "test" prints, but the other thing doesn't?

steven114 16-02-2004 15:09

Re: Odd counter problems
 
Quote:

Originally Posted by Texan
Hum, well, try just using the following line. It's guarranteed to print and if it doesn't, it means that it is never getting called and you'll have to look at your code.

Code:

printf("Test");

--EDIT--
If it doesn't work then post your code and people can look at it.

Try
Code:

printf("Test\n");
instead. If it works anything like printf on any other system, it won't flush the buffer until it gets a newline...


All times are GMT -5. The time now is 20:46.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi