This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with PWM and PID in temperature-controlled fan

I am doing a temperature-controlled fan, which means that the fan speed will depend on the temperature. I use PWM and PID in this code. My LCD have shown the temperature and humidity but the fan does not work. Can someone explain to this?

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
  MX_TIM4_Init();
  /* USER CODE BEGIN 2 */
	
	HAL_TIM_Base_Start(&htim4);
	
	lcd_init(); //initialize lcd
	lcd_send_string("INITIALIZING.."); //display string on lcd
	HAL_Delay(1000); //wait for 1 seconds
	lcd_clear();
	HAL_TIM_PWM_Start(&htim4, PWM_CHANNEL);
	
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		HAL_GPIO_WritePin(FAN_PORT, FAN_PIN, GPIO_PIN_RESET);
		
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
		
		//Calculate temperature error
		temp_error = temp_setpoint - Temperature;
		
		//Update PWM duty cycle based on temperature error
		update_pwm_duty_cycle(temp_error);
		
		
		Display_Temp(Temperature);
		Display_Rh(Humidity);
		
		/*******DHT11*********/
		DHT11_Start();
		Presence = DHT11_Check_Response(); //record the response from the sensor
		
		//Five bytes of data
		Rh_byte1 = DHT11_Read ();
		Rh_byte2 = DHT11_Read ();
		Temp_byte1 = DHT11_Read ();
		Temp_byte2 = DHT11_Read ();
		SUM = DHT11_Read ();
		
		
		TEMP = Temp_byte1;
		RH = Rh_byte1;
		
		Temperature = (float) TEMP;
		Humidity = (float) RH;
	
		
		
		
		
		HAL_Delay(1200);
  }
	
  /* USER CODE END 3 */
}

Parents Reply Children
No data