Hi, I am trying to implement very basic MPPT algorithm so I will measure input power and output power of a buck converter and adjust the duty cycle of my PWM for MOSFET according to that. Problem is 1kHz is not enough for me I want to increase the switching frequency of my PWM output. But I heard that playing with timers and default settings may disturb the other algorithms or sensor readings. Is it true ? and if yes hat should I do?
You can simply modify the prescale ratio of a timer while maintaining the analogWrite() values. Changing the TOP value instead also affects (reduces or extends) the duty cycle range.
Don't touch Timer0 because it's used for system timing.
The Nano Every is the same foot print as the 328 Nano but has many additional useful features as it uses the Atmega 4809 as the processor.
MegaCoreX is the best platform to use with the Nano Every, and it contains a function
analogWriteFrequency( ) which will work for 1(default), 4, 8, 16, or 32 KHz.
What you need to know can be found at
Instructions on how to load the core through the board manager is here
Only timer0 is used by the core arduino functions (for maintaining the millis() and micros() times (including delay() and similar.).) Timer0 controls pwm on pins 5 and 6, I think. You should be able to change the other 4 pwm pin frequencies by manipulating the other two timers, without bothering any of the core functions.
That is true. But watch out for other libraries that use other timers. It is not always easy to spot what hardware resources are used, especial third party ones. They often have poor documentation.
So if you have no other library loaded fell free to use either timer 1 or timer 2. But if later down the line with your project you might have to change the timer you used for the PWM speed. Or edit and change the other library.
If you don't want to maipulate registers yourself, you can try out my FastPwmPin library. I made it when I needed high frequency PWM. It supports various popular Atmel processors, including the ATmega328.
(See the readme for details such as used timers, supported pins, etc.)
Okay so, I am doing a very basic circuit to be honest but I will use INA226 (a power sensor) which communicate with I2C so SDA SCL pins (A4, A5) I also need to have a PWM output to drive a logic mosfet (I am planning to drive it directly from the D9 pin since it is a low power mosfet) around 20 kHz (there is no specific requirement). I am afraid that playing with timer1 might (I have no idea) create problems with INA226.
Okay so, I am doing a very basic circuit to be honest but I will use INA226 (a power sensor) which communicate with I2C so SDA SCL pins (A4, A5) I also need to have a PWM output to drive a logic mosfet (I am planning to drive it directly from the D9 pin since it is a low power mosfet) around 20 kHz (there is no specific requirement). I am afraid that playing with timer1 might (I have no idea) create problems with INA226.
I will construct a buck converter with low side mosfet (logic level mosfet so it won't need high gate current therefore Arduino should be enough to turn it on/off and it will be simpler)
While tweaking the timers to have high frequency pwm is there any negative effect of using 20 kHz instead of 10kHz? Should I go lower if possible or it won't make a difference ?
While tweaking the timers to have high frequency pwm is there any negative effect of using 20 kHz instead of 10kHz? Should I go lower if possible or it won't make a difference ?