Help me select an option to generate 25 kHz PWM July 29, 2022 05:18AM |
Registered: 2 years ago Posts: 11 |
Re: Help me select an option to generate 25 kHz PWM July 30, 2022 02:50AM |
Admin Registered: 14 years ago Posts: 7,207 |
/** * Fan Fast PWM * * Combinations of PWM Modes, prescale values and TOP resolutions are used internally * to produce a frequency as close as possible to the desired frequency. * * FAST_PWM_FAN_FREQUENCY * Set this to your desired frequency. * For AVR, if left undefined this defaults to F = F_CPU/(2*255*1) * i.e., F = 31.4kHz on 16MHz microcontrollers or F = 39.2kHz on 20MHz microcontrollers. * For non AVR, if left undefined this defaults to F = 1Khz. * This F value is only to protect the hardware from an absence of configuration * and not to complete it when users are not aware that the frequency must be specifically set to support the target board. * * NOTE: Setting very low frequencies (< 10 Hz) may result in unexpected timer behavior. * Setting very high frequencies can damage your hardware. * * USE_OCR2A_AS_TOP [undefined by default] * Boards that use TIMER2 for PWM have limitations resulting in only a few possible frequencies on TIMER2: * 16MHz MCUs: [62.5kHz, 31.4kHz (default), 7.8kHz, 3.92kHz, 1.95kHz, 977Hz, 488Hz, 244Hz, 60Hz, 122Hz, 30Hz] * 20MHz MCUs: [78.1kHz, 39.2kHz (default), 9.77kHz, 4.9kHz, 2.44kHz, 1.22kHz, 610Hz, 305Hz, 153Hz, 76Hz, 38Hz] * A greater range can be achieved by enabling USE_OCR2A_AS_TOP. But note that this option blocks the use of * PWM on pin OC2A. Only use this option if you don't need PWM on 0C2A. (Check your schematic.) * USE_OCR2A_AS_TOP sacrifices duty cycle control resolution to achieve this broader range of frequencies. */ //#define FAST_PWM_FAN // Increase the fan PWM frequency. Removes the PWM noise but increases heating in the FET/Arduino #if ENABLED(FAST_PWM_FAN) //#define FAST_PWM_FAN_FREQUENCY 31400 // Define here to override the defaults below //#define USE_OCR2A_AS_TOP #ifndef FAST_PWM_FAN_FREQUENCY #ifdef __AVR__ #define FAST_PWM_FAN_FREQUENCY ((F_CPU) / (2 * 255 * 1)) #else #define FAST_PWM_FAN_FREQUENCY 1000U #endif #endif #endif
Re: Help me select an option to generate 25 kHz PWM July 30, 2022 12:42PM |
Registered: 2 years ago Posts: 11 |
Quote
Dust
* Boards that use TIMER2 for PWM have limitations resulting in only a few possible frequencies on TIMER2
Re: Help me select an option to generate 25 kHz PWM August 06, 2022 02:39AM |
Registered: 2 years ago Posts: 11 |
Re: Help me select an option to generate 25 kHz PWM August 06, 2022 10:20AM |
Registered: 2 years ago Posts: 11 |
/** * (8-bit AVRs only) * * get_pwm_timer * Grabs timer information and registers of the provided pin * returns Timer struct containing this information * Used by set_pwm_frequency, set_pwm_duty * * set_pwm_frequency * Sets the frequency of the timer corresponding to the provided pin * as close as possible to the provided desired frequency. Internally * calculates the required waveform generation mode, prescaler and * resolution values required and sets the timer registers accordingly. * NOTE that the frequency is applied to all pins on the timer (Ex OC3A, OC3B and OC3I was able to find this bit of code in "temperature.h" which I think means it depends on which pins are defined for fans but I'm not sure how it'll handle multiple fans if that's the case* NOTE that there are limitations, particularly if using TIMER2. (see Configuration_adv.h -> FAST FAN PWM Settings) */ #if ENABLED(FAST_PWM_FAN) static void setPwmFrequency(const pin_t pin, int val); typedef struct Timer { volatile uint8_t* TCCRnQ[3]; // max 3 TCCR registers per timer volatile uint16_t* OCRnQ[3]; // max 3 OCR registers per timer volatile uint16_t* ICRn; // max 1 ICR register per timer uint8_t n; // the timer number [0->5] uint8_t q; // the timer output [0->2] (A->C) } Timer; static Timer get_pwm_timer(const pin_t pin); static void set_pwm_frequency(const pin_t pin, int f_desired); #endif static void set_current_temp_raw();
Re: Help me select an option to generate 25 kHz PWM August 06, 2022 01:07PM |
Registered: 14 years ago Posts: 1,797 |
Re: Help me select an option to generate 25 kHz PWM August 06, 2022 03:16PM |
Registered: 2 years ago Posts: 11 |
Quote
jamesdanielv
i would recommend in this case to use the defaults that marlin has set. but in case you want the 25khz, the manual for the avr chip has been included with the pages to look at.
be sure that prescaller only effects the timer you need
best of luck
Boards that use TIMER2 for PWM have limitations resulting in only a few possible frequencies on TIMER2: 16MHz MCUs: [62.5kHz, 31.4kHz (default), 7.8kHz, 3.92kHz, 1.95kHz, 977Hz, 488Hz, 244Hz, 60Hz, 122Hz, 30Hz]But as I understand it now it depends on the pin I define for the fan as it is a hardware PWM and Marlin will make changes to the corresponding Prescaler accordingly.
Quote
jamesdanielv
changing timer values can have unintended consequences, such as noise on analog to digital pins, and overall voltage stability of chip in general. for example output pin cross talk may or may not be an issue as well.