Aruna
Pwm.cpp
Go to the documentation of this file.
1 //
2 // Created by noeel on 18-10-20.
3 //
4 
5 #include <cmath>
6 #include "aruna/driver/Pwm.h"
7 
8 using namespace aruna::driver;
9 using namespace aruna;
10 
11 uint16_t Pwm::get_duty() const {
12  return duty;
13 }
14 
15 uint32_t Pwm::get_frequency() const {
16  return frequency_hz;
17 }
18 
19 float Pwm::get_duty_per() const {
20  return duty / 65535 * 100;
21 }
22 
23 err_t Pwm::set_duty(float duty_percentage) {
24  uint16_t duty = round(duty_percentage / 100 * 65535);
25  return set_duty(duty);
26 }
27 
28 err_t Pwm::set_frequency(uint32_t frequency_hz) {
29  err_t err = _set_frequency(frequency_hz);
30  if (err == err_t::OK) {
31  this->frequency_hz = frequency_hz;
32  }
33  return err;
34 }
35 
36 err_t Pwm::set_duty(uint16_t duty) {
37  err_t err = _set_duty(duty);
38  if (err == err_t::OK) {
39  this->duty = duty;
40  }
41  return err;
42 }
43 
44 err_t Pwm::_set(movement::axis_mask_t axisMask, int16_t speed) {
45 // TODO allow for min and max duty_cycle
46 // TODO multi directional pwm
47 // TODO startup_error is not set to OK. Set to standard to OK, remove all together or standalize.
48  return set_duty((uint16_t)speed);
49 }
Definition: comm.cpp:14
err_t set_duty(float duty_percentage)
Set the duty cycle on time in percentage.
Definition: Pwm.cpp:23
err_t set_frequency(uint32_t frequency_hz)
Set frequency of PWM in hertz.
Definition: Pwm.cpp:28
err_t _set(movement::axis_mask_t axisMask, int16_t speed) override
Implementation of axis movement, this function is called from set(...).
Definition: Pwm.cpp:44
uint16_t get_duty() const
Get the duty cycle on time (16bit)
Definition: Pwm.cpp:11
uint32_t get_frequency() const
Get the frequency used in hertz.
Definition: Pwm.cpp:15
float get_duty_per() const
Get the duty cycle on time in percentage.
Definition: Pwm.cpp:19