Traumflug / Teacup_Firmware

Firmware for RepRap and other 3D printers
http://forums.reprap.org/read.php?147
GNU General Public License v2.0
310 stars 198 forks source link

Heater max_value field is not applied to software pwm #303

Closed phord closed 5 years ago

phord commented 5 years ago

If a heater is driven by hardware pwm, the max_value field is able to limit the current sent to that heater by limiting the max pwm value used. If software pwm is used, the max_value field is ignored. This could even be dangerous since software pwm may be chosen without the user's awareness; e.g. if the pin chosen doesn't support pwm, uses Timer0 or if a bug in the header has it configured wrong.

Wurstnase commented 5 years ago

It works with software pwm a little bit different. Please check:

Instead of limit the value, softpwm will smoothly factorize the values. E.g. having a max value of 128 and sending 255, the result is 128. Sending 127 the result is ~64.

phord commented 5 years ago

You're right, of course. I did just notice that. Sorry about the noise.

phord commented 5 years ago

It feels like the hardware pwm should also be scaled in a common location rather than down in the chip-specific code (e.g. heater-avr.c).

Also, why does the soft-pwm scale differently than the hardware pwm? Shouldn't they both scale the same?

Wurstnase commented 5 years ago

I'm not 100% sure how it works with hardware pwm.

When I'm programming the soft pwm code I found the special behaviour with the max value and don't think to implement the same on hardware side. But this scaled view could be probably better.