View Single Post
  #10   Spotlight this post!  
Unread 04-12-2004, 19:40
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: pwm ouput limiting

Quote:
Originally Posted by stephenthe1
Code:
	signed char distance = p1_y - p2_y;
	if (distance < 0)
	distance = -(distance);     //the absolute value of distance
	else if (distance <= 14)
	{
	p1_y = p2_y = (p1_y + p2_y)/2;
	}
	pwm01 = pwm02 = p1_y;
	pwm03 = pwm04 = p2_y;
the only possible problem I can see is how it converts (but doesn't really convert) a signed char to an unsigned char (the pwm values). is this a problem?
No, p1_* is unsigned char. The problem may be, though, if the sum of p1_y and p2_y is greater than 255. This would cause wrap around. (eg, 128+128 equals 0).

this would work, though
Code:
p1_y = p2_y = ((long)p1_y + p2_y)/2;