try to changing pwm frequency on PIN_PD2 #465
Replies: 1 comment 4 replies
-
Changing the frequency by factors of 4 is very easy, since you can just change the TCA prescaler - we default it to 64 at most clock speeds., It can be turned down to 16, 8, 4, 2 or 1. That's also the only setting on TCA that you can change without taking over TCA0, and using analogWrite. (please refer to the examples included (they're listed in sketch -> examples -> DxCore) on taking over TCA for examples where you do take over analogWrite for full control and can set any frequency, and the document on TakingOverTCA0 - I have no examples beyond those. However, there is a reason we target 1 kHz. How is the motor being driven? If you are directly driving the gate of a power MOSFET to switch the load, 1kHz is the highest frequency you can assume will work for PWM. Above that, you need to run the numbers and make sure you are turning the FET on and off quickly enough. As F_PWM increases, the FET will spend a larger and larger portion of it's time switching, (when power dissipation in the FET is highest) and less either on (where power dissipation is very low) or off (where power dissipation is 0) the pin can't supply current sufficient to quickly switch the gate. In extreme cases, including some where I was asked why FETs rated for much higher loads were burning out, and questioning revealed that they were trying to eliminate audible components from a motor, and were trying to switch so fast that the FET never got to turn on or off, and was just running back and forth on the miller plateau, never reaching either end of it, stuck in a regime where significant current is flowing, but the Rds is ohms or tens of ohms instead of milliohms.. I review this problem in more detail, link a spreadsheet you can use to calculate safe pwm frequencies for any MOSFET when directly driven based on Rgate and the pin driver strength and the components of gate charge, which are what define the shape of that graph of Qgate vs Vgs - as you can see in the datasheet for your MOSFET, it starts with one slope (before the miller plateau, then goes horizontal, as current starts to flow, because there is also capacitance between the gate and the drain, and as the FET turns on, the drain voltage starts to fall, and being capacitively coupled to the gate, this effect works against your attempt to drive the gate voltage higher to turn the fet fully on. Reverse happens when turning off. And you can't solve the problem by using a beefier fet, because beefier fets have more gate capacitance, either - it can even make the problem worse. The solution when you need faster PWM than can be done directly driving the gate is to use what is called a gate driver - specialized (but not hard to source - many companies make near identical pin compatible ones). Whereas a microcontroller pin is going to supply 20-40mA, the gate drivers are designed to provide a very brief pulse of current, typically several AMPS, slamming the mosfet on and off on the order of 100x faster or more. (description assumed an n-channel fet, p-channel fets are the opposite way around but otherwise the same problem is present, except there are not readily available drivers that are easy to use for P-channel fets like there are for N-channel ones.) See the https://github.com/SpenceKonde/ProductInfo/blob/master/MOSFETs/Guide.md MOSFET guide that I wrote, which covers this is more detail. All I'd be doing answering further is saying the same things I say there. |
Beta Was this translation helpful? Give feedback.
-
thankyou so much for great core, im using avr128da32 for control motor, i designed my pcb with PIN_PD2 to provide PWM to control speed of motor. my motor make noise because the low frequency, i did read about taking over tca0 but i cant get it right can you give the example to change pwm frequency.
sorry im new on programming, so really helpful if you can give example to change pwm frequency on PIN_PD2. thankyou so much
Beta Was this translation helpful? Give feedback.
All reactions