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:

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.

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:


printf("
Arm counter: %i
", (int)armcounter);

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

PS What type is armcounter?

its a short.

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

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.


printf("Test");

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

It printed test but here it is. I’m using a basic auto right now so i can debug everything first.

New Text Document.txt (6.15 KB)


New Text Document.txt (6.15 KB)

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.

A few things I saw after glancing at it:


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

sould be


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. :slight_smile:

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?

Try

printf("Test
");

instead. If it works anything like printf on any other system, it won’t flush the buffer until it gets a newline…

Yeah, that is true, but it did print for him. The wierd thing is, at least from what he has said, the line that is right below it doesn’t say print anything, even though it should. :confused:

Well for the variable, it print Arm and then nothing after it.

Could you paste the output from the code here?

Well, I can’t figure it out. It should work. Any suggestions, The Lucas?

–EDIT–
I know you’re watching. :slight_smile:

Obviously not. Try:


printf("Arm: %d", armcounter);

–EDIT–
If that doesn’t work, I don’t know what to do. Sorry. :frowning: