View Single Post
Old 07-23-2009, 09:18 AM   #2068 (permalink)
JayC
EcoModding Lurker
 
Join Date: Jul 2008
Location: Memphis, TN
Posts: 58

2010 Prius - '10 Toyota Prius IV
Last 3: 51.4 mpg (US)
Thanks: 0
Thanked 1 Time in 1 Post
You are controlling the PWM power via PI loop. But are you controlling the acceleration from one value to the next? In a pump controller I wrote, I wanted to control the acceleration smoothly. Why not add code that slews the current limited by some acceleration value.

Code:
#define RAMP_SPEED			20			// how much to increase the OCR0A value from one step to the next.
...
// This function runs every ms to ramp the actual PWM value from one speed to the next smoothly
	{
		// Read the current PWM value
		TC0_READ_16_BIT_OCR0AB(temp16);			// safe inside an interrupt
		if(requested_speed < temp16)				// is the requested spped less than the current speed?
		{
			// Our requested speed is either higher or lower than what we need
			temp16 -= RAMP_SPEED; 
			TC0_WRITE_16_BIT_OCR0AB( SERVO_CLIP(temp16) );
		}
		else if(requested_speed > temp16)
		{
			temp16 += RAMP_SPEED;
			TC0_WRITE_16_BIT_OCR0AB( SERVO_CLIP(temp16) );
		}
	}
	// ------------------------------------------------End Ramp
  Reply With Quote