Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AVR set_pwm_duty unset default frequency #23463

Merged
merged 33 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
15b243c
Fix AVR set_pwm_duty unset default frequency
descipher Jan 6, 2022
e363120
Set MOTOR_CURRENT_PWM_FREQUENCY default as 31400
descipher Jan 6, 2022
0ab6dcb
Merge 'bugfix-2.0.x' into bf2_weird_pwm_PR_23463
thinkyhead Jan 7, 2022
df4f122
defer to pinsformat.js
thinkyhead Jan 7, 2022
359415d
delete red highlighted trailing spaces
thinkyhead Jan 7, 2022
fe1f75d
clarify
thinkyhead Jan 7, 2022
eaef837
trust pins to retain freq after init ?
thinkyhead Jan 7, 2022
8cd296f
track init as a debug option
thinkyhead Jan 7, 2022
ffd9750
arg tweak, keep wrapper ?
thinkyhead Jan 7, 2022
dbd37f2
set_pwm_frequency with all HAL_CAN_SET_PWM_FREQ
thinkyhead Jan 7, 2022
8e10265
Add HAS_LCD_BRIGHTNESS Needs PWM condition check
descipher Jan 7, 2022
1953124
Corrected include and frequency init tracking
descipher Jan 7, 2022
ea74cdc
Cleanup condition check state
descipher Jan 8, 2022
8b334fd
Update fast_pwm.cpp
thinkyhead Jan 9, 2022
741078e
would other platforms ever use it?
thinkyhead Jan 9, 2022
e18008f
tweak wgm
thinkyhead Jan 9, 2022
aaa15d6
Init AVR timers 2,3,4,5 in HAL
descipher Jan 10, 2022
5b5b23b
Merge branch 'ultimate.pwm.fix' of https://github.com/descipher/Marli…
descipher Jan 10, 2022
4b01add
Add AT90 pins
descipher Jan 10, 2022
c1e1b75
kHz => KHz
thinkyhead Jan 10, 2022
e177429
unsigned PWM frequency
thinkyhead Jan 10, 2022
7ffc23a
32 bits may be better
thinkyhead Jan 10, 2022
092666e
fix formatting
thinkyhead Jan 10, 2022
1755e78
suppress warning
thinkyhead Jan 10, 2022
14795aa
Add more pins
descipher Jan 10, 2022
f95f606
unsigned enums
thinkyhead Jan 11, 2022
54501eb
move macros, tweak get_pwm_timer
thinkyhead Jan 11, 2022
78cb32f
tweak var names and maths
thinkyhead Jan 11, 2022
5aeac05
Merge branch 'bugfix-2.0.x' into pr/23463
thinkyhead Jan 11, 2022
90ba936
Timer check default return as non-PWM and not protected.
descipher Jan 11, 2022
0871ea3
return timer structs more directly
thinkyhead Jan 11, 2022
0f5fbe7
fallback to WGM2_PWM_PC
thinkyhead Jan 11, 2022
6a5eaec
style tweaks
thinkyhead Jan 11, 2022
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 Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ inline void HAL_adc_init() {
* NOTE that the frequency is applied to all pins on the timer (Ex OC3A, OC3B and OC3B)
* NOTE that there are limitations, particularly if using TIMER2. (see Configuration_adv.h -> FAST FAN PWM Settings)
*/
void set_pwm_frequency(const pin_t pin, int f_desired);
void set_pwm_frequency(const pin_t pin, const int f_desired);

/**
* set_pwm_duty
Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/HAL/AVR/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "../../inc/MarlinConfigPre.h"
#include "HAL.h"

#if NEEDS_HARDWARE_PWM // Specific meta-flag for features that mandate PWM

//#define DEBUG_PWM_INIT

#if ENABLED(DEBUG_PWM_INIT)
Expand Down Expand Up @@ -155,7 +157,7 @@ Timer get_pwm_timer(const pin_t pin) {
return timer;
}

void set_pwm_frequency(const pin_t pin, int f_desired) {
void set_pwm_frequency(const pin_t pin, const int f_desired) {
Timer timer = get_pwm_timer(pin);
if (timer.n == 0) return; // Don't proceed if protected timer or not recognized

Expand Down Expand Up @@ -235,6 +237,8 @@ void set_pwm_frequency(const pin_t pin, int f_desired) {
_SET_ICRn(timer.ICRn, res); // Set ICRn value (TOP) = res
}

#endif // NEEDS_HARDWARE_PWM

void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
#if NEEDS_HARDWARE_PWM

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/LPC1768/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void flashFirmware(const int16_t);
* All Hardware PWM pins run at the same frequency and all
* Software PWM pins run at the same frequency
*/
void set_pwm_frequency(const pin_t pin, int f_desired);
void set_pwm_frequency(const pin_t pin, const int f_desired);

/**
* set_pwm_duty
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/LPC1768/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255

#if NEEDS_HARDWARE_PWM // Specific meta-flag for features that mandate PWM

void set_pwm_frequency(const pin_t pin, int f_desired) {
void set_pwm_frequency(const pin_t pin, const int f_desired) {
LPC176x::pwm_set_frequency(pin, f_desired);
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ extern volatile uint32_t systick_uptime_millis;
* Set the frequency of the timer corresponding to the provided pin
* All Timer PWM pins run at the same frequency
*/
void set_pwm_frequency(const pin_t pin, int f_desired);
void set_pwm_frequency(const pin_t pin, const int f_desired);

/**
* set_pwm_duty
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
if (previousMode != TIMER_OUTPUT_COMPARE_PWM1) HT->resume();
}

void set_pwm_frequency(const pin_t pin, int f_desired) {
void set_pwm_frequency(const pin_t pin, const int f_desired) {
if (!PWM_PIN(pin)) return; // Don't proceed if no hardware timer
const PinName pin_name = digitalPinToPinName(pin);
TIM_TypeDef * const Instance = (TIM_TypeDef *)pinmap_peripheral(pin_name, PinMap_PWM); // Get HAL timer instance
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void flashFirmware(const int16_t);
* Set the frequency of the timer corresponding to the provided pin
* All Timer PWM pins run at the same frequency
*/
void set_pwm_frequency(const pin_t pin, int f_desired);
void set_pwm_frequency(const pin_t pin, const int f_desired);

/**
* set_pwm_duty
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
timer_set_mode(timer, channel, TIMER_PWM); // PWM Output Mode
}

void set_pwm_frequency(const pin_t pin, int f_desired) {
void set_pwm_frequency(const pin_t pin, const int f_desired) {
if (!PWM_PIN(pin)) return; // Don't proceed if no hardware timer

timer_dev *timer; UNUSED(timer);
Expand Down
5 changes: 0 additions & 5 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,6 @@
#define CUTTER_UNIT_IS(V) (_CUTTER_POWER(CUTTER_POWER_UNIT) == _CUTTER_POWER(V))
#endif

// Add features that need hardware PWM here
#if ANY(FAST_PWM_FAN, SPINDLE_LASER_USE_PWM, MOTOR_CURRENT_PWM_FEATURE)
#define NEEDS_HARDWARE_PWM 1
#endif

#if !defined(__AVR__) || !defined(USBCON)
// Define constants and variables for buffering serial data.
// Use only 0 or powers of 2 greater than 1
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,11 @@
#define HAS_MOTOR_CURRENT_PWM 1
#endif

// Add features that need hardware PWM here
#if ANY(FAST_PWM_FAN, SPINDLE_LASER_USE_PWM, MOTOR_CURRENT_PWM_FEATURE, HAS_MOTOR_CURRENT_PWM)
#define NEEDS_HARDWARE_PWM 1
#endif

thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
#if ANY(HAS_Z_MS_PINS, HAS_Z2_MS_PINS, HAS_Z3_MS_PINS, HAS_Z4_MS_PINS)
#define HAS_SOME_Z_MS_PINS 1
#endif
Expand Down