diff --git a/Drivers/MotorChannel/Inc/ZP_D_PWMChannel.hpp b/Drivers/MotorChannel/Inc/ZP_D_PWMChannel.hpp index c6695a56..c6880b66 100644 --- a/Drivers/MotorChannel/Inc/ZP_D_PWMChannel.hpp +++ b/Drivers/MotorChannel/Inc/ZP_D_PWMChannel.hpp @@ -8,19 +8,19 @@ class PWMChannel : public MotorChannel { public: PWMChannel(TIM_HandleTypeDef* timer, - uint16_t timer_channel); + uint16_t timerChannel); void set(uint8_t percent); private: - //set to minimum and max amount of counts in a duty cycle - uint32_t MIN_SIGNAL; - uint32_t MAX_SIGNAL; - uint32_t PERIOD_TICKS_; - TIM_HandleTypeDef *TIMER_; //handle to the timer - const uint16_t TIMER_CHANNEL_; //channel of the timer + // set to minimum and max amount of counts in a duty cycle + uint32_t minSignal; + uint32_t maxSignal; + uint32_t PERIOD_TICKS; + TIM_HandleTypeDef *TIMER; // handle to the timer + const uint16_t TIMER_CHANNEL; // channel of the timer - const uint32_t CLOCK_FREQUENCY_ = SystemCoreClock; //system clock frequency - const uint16_t DESIRED_FREQUENCY = 50; //PWM frequency in hz + const uint32_t CLOCK_FREQUENCY = SystemCoreClock; // system clock frequency + const uint16_t DESIRED_FREQUENCY = 50; // PWM frequency in hz }; #endif // ZP_D_PWM_CHANNEL_HPP_ diff --git a/Drivers/MotorChannel/Src/ZP_D_PWMChannel.cpp b/Drivers/MotorChannel/Src/ZP_D_PWMChannel.cpp index 278cb942..888fa2b7 100644 --- a/Drivers/MotorChannel/Src/ZP_D_PWMChannel.cpp +++ b/Drivers/MotorChannel/Src/ZP_D_PWMChannel.cpp @@ -1,29 +1,29 @@ #include "ZP_D_PWMChannel.hpp" PWMChannel::PWMChannel(TIM_HandleTypeDef* timer, - uint16_t timer_channel) : - TIMER_(timer), - TIMER_CHANNEL_(timer_channel) + uint16_t timerChannel) : + TIMER(timer), + TIMER_CHANNEL(timerChannel) { - /*Sets up the PWM, pre-scaler, duty cycle ranges, + /* Sets up the PWM, pre-scaler, duty cycle ranges, * and starts the timer*/ - PERIOD_TICKS_ = TIMER_->Init.Period; - MIN_SIGNAL = PERIOD_TICKS_ * 0.05; // sets counts for 5% duty cycle - MAX_SIGNAL = PERIOD_TICKS_ * 0.10; // sets counts for 10% duty cycle + PERIOD_TICKS = TIMER->Init.Period; + minSignal= PERIOD_TICKS * 0.05; // sets counts for 5% duty cycle + maxSignal = PERIOD_TICKS * 0.10; // sets counts for 10% duty cycle - //Calculate new pre-scaler - uint16_t prescaler_ = (CLOCK_FREQUENCY_ / DESIRED_FREQUENCY - / PERIOD_TICKS_) - 1; + // Calculate new pre-scaler + uint16_t prescaler = (CLOCK_FREQUENCY / DESIRED_FREQUENCY + / PERIOD_TICKS) - 1; - __HAL_TIM_SET_PRESCALER(TIMER_, prescaler_); - HAL_TIM_PWM_Start(TIMER_, TIMER_CHANNEL_); + __HAL_TIM_SET_PRESCALER(TIMER, prescaler); + HAL_TIM_PWM_Start(TIMER, TIMER_CHANNEL); isSetup = true; } void PWMChannel::set(uint8_t percent) { - /*Sets the duty cycle as a percent between 5 and 10%. + /* Sets the duty cycle as a percent between 5 and 10%. * * Usage: * 0% corresponds to a duty cycle of 5% @@ -32,8 +32,8 @@ void PWMChannel::set(uint8_t percent) { if (percent > 100 || !isSetup) { return; } - uint32_t ticks = (percent * (MAX_SIGNAL - MIN_SIGNAL)) / 100 + MIN_SIGNAL; + uint32_t ticks = (percent * (maxSignal - minSignal)) / 100 + minSignal; - __HAL_TIM_SET_COMPARE(TIMER_, TIMER_CHANNEL_, ticks); + __HAL_TIM_SET_COMPARE(TIMER, TIMER_CHANNEL, ticks); }