-
-
Notifications
You must be signed in to change notification settings - Fork 19.5k
Add stm32f1 FAST_PWM feature #19952
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
Add stm32f1 FAST_PWM feature #19952
Conversation
Marlin/src/HAL/STM32F1/fast_pwm.cpp
Outdated
//protect used timers | ||
if(timer == get_timer_dev(STEP_TIMER_NUM)) return; | ||
if(timer == get_timer_dev(PULSE_TIMER_NUM)) return; | ||
if(timer == get_timer_dev(TEMP_TIMER_NUM)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PULSE timer doesn't really exist, it is just the STEP_TIMER on this platform.
There are more timers than this which could be interfered with:
- Servo Timer
- Tone Timer
- Software Serial Timer
- Timers connected to SPI pins
The SPI bit might seem weird, but I believe on STM32F1 chips pins are not actually disconnected from the timers even if you are using their other functions. This means that running the timer connected to SPI interferes with SPI, even if you are running it for other purposes.
Detecting all the possible timer conflicts is hard, which is why there have been so many mistakes made in this area.
Using your feature won't be any less safe than "normal" PWM on these pins, so perhaps is little to be gained from these partial checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Servo Timer
- Tone Timer
- Software Serial Timer
- Timers connected to SPI pins
Am I right, that all timers, allocated by Marlin are listed in timers.h? Or there any implicit usage? (except libraries, but it will be good to know what timers exactly they allocates)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some are implicit. I think that dealing with timers is a little more mature in HAL/STM32. Maple (HAL/STM32F1) doesn't always give a good way to override the default behavior.
Tone is the hardest to deal with in Maple. It default to 4 or 8 (depending on the chip), but will use the timer connected to a pin if available. This means it is entirely up to the board layout whether enabling SPEAKER will interfere with some other timer.
Could you look at Some Which board are you using for your testing? |
MKS Robin Nano V1.2 with TFT35 (no tone) and BLTouch |
You can use |
At a glance, I think this looks ok. Maybe there are bugs, but that doesn't even worry me very much for a brand new feature. My larger concern is with adding any new features to the STM32F1 HAL. I would love to see this added to the STM32 HAL instead. This could then be a good incentive for people to help migrate boards from STM32F1 to STM32. |
It's in Lines 1325 to 1333 in 1247f73
You'll want to use/check |
And it was just added. Maybe this morning? |
For someone who is "new here" I am impressed that you added this feature and got it working! I am not aware of any good explanatory resources. If you encounter questions while adapting the implementation, please post them here. This might be even easier in HAL/STM32. One caution is that not all STM32 timers use the same base clock, even on the same chip. Make sure you use the framework functions to set rates, and don't divide from the CPU clock yourself. Once you make it work for your STM32F1 board, we can help you test it on a larger variety of hardware. |
I have problem with enabling it (creality v4.2.2 board), when i disable soft pwm and enable it (it's on PA0) it's just DC output on pin, always enabled, even for 0% fan is spinning at max speed. |
@zbyrek many fans don’t respond well to PWM. You can try adjusting the frequency (somewhere in Configuration_adv.h). For most of my fans they behave best with soft PWM. |
Unfortunately that's not it, i measured frequency and with that option on it's just DC, also i can see it when i connect engraving laser (that's the reason why i need it in the first place), with soft pwm it's just 7.8Hz which is definetly too low for laser engraving (if i want control power and not just hard ON/OFF), however thanks for reply. |
I haven’t actually measured it on a board, but it looks like it probably has a conflict on timer 2 between the fan PWM and the timer used for Marlin’s temperature ISR. |
It's probably better for you to open an issue and record details there, rather than in this closed PR. |
Right. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@rajhlinux: This Issue Queue is for Marlin bug reports and development-related issues, and we prefer not to handle user-support questions here. (As noted on this page.) For best results getting help with configuration and troubleshooting, please use the following resources:
|
Description
Implement stm32f1 FAST_PWM feature
Benefits
Stm32f1 FAST_PWM feature
Configurations
Configuration.h
Any with enabled #define FAST_PWM_FAN
Configuration_adv.h
Tested frequencies from 1 Hz to 60kHz
#define FAST_PWM_FAN_FREQUENCY 31400