Skip to content

Commit 3fdd0e7

Browse files
authored
Merge pull request #250 from HyperloopUPV-H8/features/getfrequency
add get frequency function
2 parents ffabebd + f2bb22b commit 3fdd0e7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

Inc/HALAL/Services/PWM/PWM/PWM.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class PWM {
1818
TimerPeripheral* peripheral;
1919
uint32_t channel;
2020
float duty_cycle;
21+
uint32_t frequency;
2122

2223
PWM() = default;
2324

@@ -28,6 +29,7 @@ class PWM {
2829
void turn_off();
2930
void set_duty_cycle(float duty_cycle);
3031
void set_frequency(uint32_t frequency);
32+
uint32_t get_frequency();
3133

3234
friend class DualPWM;
3335
friend class PhasedPWM;

Src/HALAL/Services/PWM/PWM/PWM.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ void PWM::set_duty_cycle(float duty_cycle) {
4949
}
5050

5151
void PWM::set_frequency(uint32_t frequency) {
52+
this->frequency = frequency;
5253
TIM_TypeDef& timer = *peripheral->handle->Instance;
5354
timer.ARR = (HAL_RCC_GetPCLK1Freq()*2 / (timer.PSC+1)) / frequency;
5455
set_duty_cycle(duty_cycle);
5556
}
57+
58+
uint32_t PWM::get_frequency() {
59+
return frequency;
60+
}

0 commit comments

Comments
 (0)