4 GPIO_TypeDef *GPIO_Port, uint16_t GPIO_Pin,
bool direction,
7 this->channel = channel;
8 this->direction = direction;
9 this->GPIO_Port = GPIO_Port;
10 this->GPIO_Pin = GPIO_Pin;
11 this->max_duty = max_duty < 1.0f ? max_duty : 1.0f;
12 this->pwm_resolution = 0;
13 this->current_duty = 0.0f;
25 if (htim ==
nullptr || pwm_resolution == 0) {
30 if (duty > max_duty) {
32 }
else if (duty < -max_duty) {
39 const bool dir = (duty >= 0.0f);
40 const float abs_duty = dir ? duty : -duty;
45 uint32_t value =
static_cast<uint32_t
>(pwm_resolution * (abs_duty));
46 __HAL_TIM_SET_COMPARE(htim, channel, value);
DCMotor(TIM_HandleTypeDef *htim, uint16_t channel, GPIO_TypeDef *GPIO_Port, uint16_t GPIO_Pin, bool direction=1, float max_duty=1.0f)
モーターを設定する (PWM はまだ出力しない)