Changeset - f153d4ca027c
[Not reviewed]
default
0 4 0
Ethan Zonca - 8 years ago 2017-07-27 13:12:04
ezonca@sealandaire.com
PID control kinda working, still can't do 0percent duty
4 files changed with 18 insertions and 8 deletions:
0 comments (0 inline, 0 general)
inc/pwmout.h
Show inline comments
 
@@ -9,7 +9,7 @@
 

	
 

	
 
void pwmout_init(void);
 
void pwmout_process(uint16_t duty);
 
void pwmout_process(int16_t duty);
 
TIM_HandleTypeDef* pwmout_get_tim(void);
 

	
 
#endif
src/main.c
Show inline comments
 
@@ -52,9 +52,10 @@ int main(void)
 
    uint32_t last_1hz = 0;
 
    uint32_t last_5hz = 0;
 
 
	float duty = 0.0;
 
 
	while (1)
 
	{
 
		float duty = 0.0;
 
 
		if(HAL_GetTick() - last_1hz > 750)
 
		{
 
@@ -84,7 +85,7 @@ int main(void)
 
            last_thermostat = HAL_GetTick();
 
        }
 
 
        pwmout_process(duty);
 
        pwmout_process((int16_t)duty);
 
        display_process();
 
        watchdog_feed();
 
src/pid.c
Show inline comments
 
@@ -52,7 +52,7 @@ float pid_process(void)
 
		ssr_output = 0.0;
 
	}
 

	
 
	return ssr_output;
 
	return ssr_output; //ssr_output;
 
}
 

	
 
int16_t pid_update(void)
 
@@ -64,7 +64,7 @@ int16_t pid_update(void)
 
	float temp = status->temp;
 

	
 
	// Calculate instantaneous error
 
	int16_t error = status->setpoint * 10 - temp; // TODO: Use fixed point fraction
 
	int16_t error = status->setpoint - temp; // TODO: Use fixed point fraction
 

	
 
	// Proportional component
 
	int32_t p_term = set->val.k_p * error;
 
@@ -78,7 +78,7 @@ int16_t pid_update(void)
 
	// it cant help be cold despite its best efforts)
 
	// not necessary, but this makes windup guard values
 
	// relative to the current iGain
 
	int32_t windup_guard_res = (set->val.windup_guard * 10) / set->val.k_i;
 
	int32_t windup_guard_res = (set->val.windup_guard) / set->val.k_i;
 

	
 
	// Calculate integral term with windup guard
 
	if (state.i_state > windup_guard_res)
src/pwmout.c
Show inline comments
 
@@ -86,10 +86,19 @@ void pwmout_init(void)
 
// functionality. this is a problem.
 

	
 
// also duty cycling isn't working correctly...
 
void pwmout_process(uint16_t duty)
 
void pwmout_process(int16_t duty)
 
{
 
	if(duty == 0)
 
	{
 
		HAL_GPIO_WritePin(SSR, 0);
 
		HAL_GPIO_WritePin(LED, 0);
 
		// TODO: Disable timer
 
	}
 
	if(duty < 0)
 
		duty = -duty;
 

	
 
	htim17.Instance->CCR1 = duty;
 

	
 
	htim17.Instance->CCR1 = duty; //duty;
 
//	HAL_GPIO_TogglePin(SSR_GPIO_Port, SSR_PIN);
 

	
 
//	uint32_t ssr_output = duty; // meh
0 comments (0 inline, 0 general)