46 lines
1.3 KiB
C
46 lines
1.3 KiB
C
/*
|
|
* PWM_control.h
|
|
*
|
|
* Created on: 07.07.2024
|
|
* Author: Hamza
|
|
*/
|
|
|
|
#ifndef INC_PWM_CONTROL_H
|
|
#define INC_PWM_CONTROL_H
|
|
|
|
#include "stm32f3xx_hal.h"
|
|
#include "state_machine.h"
|
|
|
|
/* The PWM period (1/FPWM) is defined by the following parameters:
|
|
ARR value, the Prescaler value, and the internal clock itself which drives the timer module FCLK.
|
|
F_PWM = (F_CLK)/((ARR + 1) * (PSC + 1))
|
|
(ARR + 1) * (PSC + 1) = (F_CLK)/(F_PWM)
|
|
(PSC + 1) = (F_CLK)/(F_PWM * (ARR + 1))
|
|
|
|
F_CLK = 16 MHz
|
|
|
|
POWERGROUND ESC Signal: pulse every 20 ms, 1 ms = 0%, 2 ms = 100%
|
|
FREQ = 50 Hz -> 16 MHz/50 Hz = 320000 = ((39999 + 1) * (7 + 1))
|
|
DUTY CYCLE = 1/20 -> 0%, DUTY CYCLE = 2/20 -> 100%
|
|
CCR * DUTY_CYCLE
|
|
CCR: 1/20 -> 500, 2/20 -> 1000
|
|
*/
|
|
// UNUSED
|
|
#define POWERGROUND_FREQ 50
|
|
#define POWERGROUND_PRESCALER 7
|
|
#define POWERGROUND_ARR 39999
|
|
#define POWERGROUND_MIN_DUTY_CYCLE 0.05
|
|
#define POWERGROUND_MAX_DUTY_CYCLE 0.1
|
|
|
|
//#define BATTERY_COOLING_FREQ 20000
|
|
|
|
extern uint8_t current_powerground_status;
|
|
extern uint8_t target_powerground_status;
|
|
|
|
void PWM_control_init(TIM_HandleTypeDef* pg, TIM_HandleTypeDef* bat_cool, TIM_HandleTypeDef* esc_cool);
|
|
void PWM_powerground_softcontrol();
|
|
void PWM_powerground_control(uint8_t percent);
|
|
void PWM_battery_cooling_control(uint8_t percent);
|
|
|
|
#endif /* INC_CHANNEL_CONTROL_H */
|