Skip to content

Commit

Permalink
Create macro to calculate max duty
Browse files Browse the repository at this point in the history
  • Loading branch information
perpernorbi committed Aug 24, 2018
1 parent e64d954 commit 3585594
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sming/SmingCore/HardwarePWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "HardwarePWM.h"

#define PERIOD_TO_MAX_DUTY(x) (x * 25)

HardwarePWM::HardwarePWM(uint8* pins, uint8 no_of_pins)
{
channel_count = no_of_pins;
Expand All @@ -34,9 +36,10 @@ HardwarePWM::HardwarePWM(uint8* pins, uint8 no_of_pins)
pwm_duty_init[i] = 0; // Start with zero output
channels[i] = pins[i];
}
pwm_init(1000, pwm_duty_init, no_of_pins, io_info);
const int initial_period = 1000;
pwm_init(initial_period, pwm_duty_init, no_of_pins, io_info);
pwm_start();
maxduty = 22222; // for period of 1000
maxduty = PERIOD_TO_MAX_DUTY(initial_period); // for period of 1000
}
}

Expand Down Expand Up @@ -129,7 +132,7 @@ uint32 HardwarePWM::getPeriod()
*/
void HardwarePWM::setPeriod(uint32 period)
{
maxduty = (period * 1000) / 45;
maxduty = PERIOD_TO_MAX_DUTY(period);
pwm_set_period(period);
pwm_start();
}

0 comments on commit 3585594

Please sign in to comment.