Skip to content

Commit

Permalink
fitting to style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
cehune committed Jul 9, 2023
1 parent a759af6 commit 88e94ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
18 changes: 9 additions & 9 deletions Drivers/MotorChannel/Inc/ZP_D_PWMChannel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
30 changes: 15 additions & 15 deletions Drivers/MotorChannel/Src/ZP_D_PWMChannel.cpp
Original file line number Diff line number Diff line change
@@ -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%
Expand All @@ -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);
}

0 comments on commit 88e94ba

Please sign in to comment.