View Single Post
  #7   Spotlight this post!  
Unread 09-12-2004, 16:23
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
how about this code.

we tried to keep the motor speed down so the encoder will read each tick before the program refreshes. so the motor doesn't "beat" the program before it reads the encoder.

Code:
//the encoder is at 50 resolution
	//the arm motor is attatched to pwm_02
	//the encoder is attatched to rc_dig_in06
	static unsigned int encoder;
	static unsigned int pressedornot;
	if (p1_sw_trig == 1)
{
	if (encoder <= 10)
{
    pwm_02 = 150;
	if (rc_dig_in06  == 1)
{
	encoder = encoder + 1;
	if (encoder > 10)
{
	pwm_02 = 127;
}
}
}
}