View Single Post
  #1   Spotlight this post!  
Unread 14-01-2007, 20:31
Noah Kleinberg Noah Kleinberg is offline
Registered User
FRC #0395 (2TrainRobotics)
Team Role: Driver
 
Join Date: Jan 2006
Rookie Year: 2006
Location: New York
Posts: 196
Noah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to behold
Send a message via AIM to Noah Kleinberg
Re: PWM 13-16 Replacement Code Beta Test

Is there any reason that you couldn't use "int"s to store your motor speeds and have a greater range of values with the higher precision obtained by using the CCP (that is, instead of using the gain and center #defines)? I looked through the code and don't see why this wouldn't work, what i mean is something like this as a change to the PWM() function:

Code:
void PWM(unsigned int pwm_13, unsigned int pwm_14, unsigned int pwm_15, unsigned int pwm_16)
{
//	int temp_pwm_13;
//	int temp_pwm_14;
//	int temp_pwm_15;
//	int temp_pwm_16;

// .........
	// calculate the number of 100 ns timer ticks 
	// needed to match the desired PWM pulse width 
	temp_pwm_13 = (PWM_13_GAIN * ((int)pwm_13 - 127)) + PWM_13_CENTER;
	temp_pwm_14 = (PWM_14_GAIN * ((int)pwm_14 - 127)) + PWM_14_CENTER;
	temp_pwm_15 = (PWM_15_GAIN * ((int)pwm_15 - 127)) + PWM_15_CENTER;
	temp_pwm_16 = (PWM_16_GAIN * ((int)pwm_16 - 127)) + PWM_16_CENTER;

	// load the CCP compare registers
	CCPR2L = LOBYTE(pwm_13);
	CCPR2H = HIBYTE(pwm_13);

	CCPR3L = LOBYTE(pwm_14);
	CCPR3H = HIBYTE(pwm_14);

	CCPR4L = LOBYTE(pwm_15);
	CCPR4H = HIBYTE(pwm_15);

	CCPR5L = LOBYTE(pwm_16);
	CCPR5H = HIBYTE(pwm_16);

//..............
Also, could CCPR1L and CCPR1H (or 2-5) each be 255? I ask this because with the default GAIN and CENTER values, the maximum I believe is 21400 (that is for the two combined as one word), as opposed to 65535.