Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/Core/BSP/BSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void BSPInit(void);
// Called to reset the hardware watchdog unit
void resetWatchdog();
// Accepts a output level of 0.. to use to control the tip output PWM
void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM);
void setTipPWM(const uint16_t pulse, const bool shouldUseFastModePWM);
// Returns the Handle temp in C, X10
uint16_t getHandleTemperature(uint8_t sample);
// Returns the Tip temperature ADC reading in raw units
Expand Down
2 changes: 1 addition & 1 deletion source/Core/BSP/Fnirsi/BSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void switchToFastPWM(void) {
TIM4->PSC = 3999; // 8kHz -> 125uS per tick
}

void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
void setTipPWM(const uint16_t pulse, const bool shouldUseFastModePWM) {
PWMSafetyTimer = 20; // This is decremented in the handler for PWM so that the tip pwm is
// disabled if the PID task is not scheduled often enough.

Expand Down
2 changes: 1 addition & 1 deletion source/Core/BSP/MHP30/BSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
}
return sum * 4 / divisor;
}
void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
void setTipPWM(const uint16_t pulse, const bool shouldUseFastModePWM) {
// We can just set the timer directly
if (htim3.Instance->PSC > 20) {
htim3.Instance->CCR1 = 0;
Expand Down
2 changes: 1 addition & 1 deletion source/Core/BSP/Miniware/BSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void switchToSlowPWM(void) {
htimADC.Instance->PSC = 2690 * 2;
}

void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
void setTipPWM(const uint16_t pulse, const bool shouldUseFastModePWM) {
PWMSafetyTimer = 20; // This is decremented in the handler for PWM so that the tip pwm is
// disabled if the PID task is not scheduled often enough.
fastPWM = shouldUseFastModePWM;
Expand Down
2 changes: 1 addition & 1 deletion source/Core/BSP/Pinecil/IRQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void switchToSlowPWM(void) {
TIMER_CH0CV(TIMER1) = powerPWM + holdoffTicks / 2;
TIMER_PSC(TIMER1) = 36000;
}
void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
void setTipPWM(const uint16_t pulse, const bool shouldUseFastModePWM) {
PWMSafetyTimer = 10; // This is decremented in the handler for PWM so that the tip pwm is
// disabled if the PID task is not scheduled often enough.
pendingPWM = pulse;
Expand Down
2 changes: 1 addition & 1 deletion source/Core/BSP/Pinecilv2/IRQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void switchToSlowPWM(void) {
BL_WR_REG(TIMER_BASE, TIMER_TCDR, tmpVal);
}

void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
void setTipPWM(const uint16_t pulse, const bool shouldUseFastModePWM) {
PWMSafetyTimer = 10;
// This is decremented in the handler for PWM so that the tip pwm is
// disabled if the PID task is not scheduled often enough.
Expand Down
2 changes: 1 addition & 1 deletion source/Core/BSP/Sequre/BSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void switchToFastPWM(void) {
htim2.Instance->PSC = 1500;
}

void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) {
void setTipPWM(const uint16_t pulse, const bool shouldUseFastModePWM) {
PWMSafetyTimer = 20; // This is decremented in the handler for PWM so that the tip pwm is
// disabled if the PID task is not scheduled often enough.
pendingPWM = pulse;
Expand Down
2 changes: 1 addition & 1 deletion source/Core/Inc/power.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ extern expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory;

uint32_t availableW10(uint8_t sample);
void setTipX10Watts(int32_t mw);
uint8_t X10WattsToPWM(int32_t milliWatts, uint8_t sample = 0);
uint16_t X10WattsToPWM(int32_t milliWatts, uint8_t sample = 0);
#endif /* POWER_HPP_ */
8 changes: 4 additions & 4 deletions source/Core/Src/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include <Settings.h>
#include <power.hpp>

static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample);
static int32_t PWMToX10Watts(uint16_t pwm, uint8_t sample);
const int fastPWMChangeoverPoint = 128;
const int fastPWMChangeoverTolerance = 16;

expMovingAverage<uint32_t, wattHistoryFilter> x10WattHistory = {0};

bool shouldBeUsingFastPWMMode(const uint8_t pwmTicks) {
bool shouldBeUsingFastPWMMode(const uint16_t pwmTicks) {
// Determine if we should use slow or fast PWM mode
// Crossover between modes set around the midpoint of the PWM control point
static bool lastPWMWasFast = true;
Expand Down Expand Up @@ -56,7 +56,7 @@ uint32_t availableW10(uint8_t sample) {
// availableMilliWattsX10 is now an accurate representation
return availableWattsX10;
}
uint8_t X10WattsToPWM(int32_t x10Watts, uint8_t sample) {
uint16_t X10WattsToPWM(int32_t x10Watts, uint8_t sample) {
// Scale input x10Watts to the pwm range available
if (x10Watts <= 0) {
// keep the battery voltage updating the filter
Expand All @@ -74,7 +74,7 @@ uint8_t X10WattsToPWM(int32_t x10Watts, uint8_t sample) {
return pwm;
}

static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample) {
static int32_t PWMToX10Watts(uint16_t pwm, uint8_t sample) {
uint32_t maxMW = availableW10(sample); // Get the milliwatts for the max pwm period
// Then convert pwm into percentage of powerPWM to get the percentage of the max mw
return (((uint32_t)pwm) * maxMW) / powerPWM;
Expand Down