Set_Input(InputValue) AVR221 function

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hy guys!

I'm working on a AVR221 document based PID controller. I'm trying to tune the P, I, D parameter with no luck. If I set I and D term to zero (for Ziegler-Nichols tuning), the return value of the controller (inputValue) is between -255 and 255. If I set the I and/or D term, the return value is between -32767 and 32767 (MAX_INT16 and -MAX_INT16). I'm controlling a pwm output from 0 to 255. According to this, my Set_Input() function looks like this: 

void Set_Input(int16_t InputValue)
{
	uint16_t newValue = OCR2A;
	
	if(InputValue > 0U)
	{
		newValue += (PWM_MAX * (InputValue / (double) (INT16_MAX + 1U))); 
		
		if(newValue < PWM_MAX)
		{
			OCR2A = newValue;
		}
		else
		{
			OCR2A = (PWM_MAX - 1U);
		}
	}
	else if (InputValue < 0U)
	{
		OCR2A -= (PWM_MAX * (InputValue / (double) -(-INT16_MAX + 1U))); 
	}
	else { ; }	
}

Can anybody confirme that it is good? 
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A good software test plan should be designed before the software is written,  then using debug mode, you can test your functions using both expected values and values outside of expected range to see how your function reacts. 

What were you expecting to happen, what does happen when you run the above code? 

 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...