View Single Post
  #3   Spotlight this post!  
Unread 24-01-2004, 18:10
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,782
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: problems assigning unsigned chars in FRC Code

Quote:
Originally Posted by LoyolaCubs
Whenever I assign variables (including competition_mode, autonomous_mode, pwm01, and pwm02), the variable values turn into 256x whatever I assigned. For instance, if I give pwm01 the value 127, the value returned after I use a printf command is 32512. Here is my code in my Stop function (located in the User_Autonomous_Code function):

void Stop (int counter1) // Drive forward until counter reaches zero
{
while( counter1 > 0 )
{
counter1--;
pwm01 = 127;
printf("pwm01: %d\n", pwm01);
pwm02 = 127;
printf("pwm02: %d\n", pwm02);
printf("should be stopped \n");
printf("counter1: %d\n", counter1);
}
}

Anyone have a similar problem or know how to fix it?
The problem is in your use of printf.
printf always assumes it is printing a signed integer.


Change it to:
Code:
void Stop (int counter1)    // Drive forward until counter reaches zero
	{
	while( counter1 > 0 )
		{
		counter1--;
		pwm01 = 127;
		printf("pwm01: %d\n", (int) pwm01);
		pwm02 = 127;
		printf("pwm02: %d\n", (int) pwm02);
		printf("should be stopped \n");
		printf("counter1: %d\n", (int) counter1);
		}
	}
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle