Hello, I present here a challenge that I find myself with.
I am developing a circuit for the control of 2 led lamps (obviously connected through 2 mosfets). The Led, as is well known, has the disadvantage of flicking when it is dimmed, and it is due to the PWM frequency, that is why I wanted to raise the PWM frequency of timer 1 above 2 KHz, in my case I decided to do it at 4KHz. In turn, the number of steps to regulate each output from 0% to 100% is generally 255, but for lower intensities, the intensity jump becomes very visible, so I decided to increase the number of steps to 4096.
Everything is working very well and it is spectacular to see the result in large and bright lamps.
What we have discovered is that when the lamp is of high consumption, for example something less than 150-180W and the source is 200W (the brand does not matter and we have even tried with more powerful power supplies), the source itself generates a unpleasant constant 4KHz beep perfectly audible when the lamp is dimmed between approximately 30% and 80%. This is due to the fact that power supplies are not very friendly to interrupted consumptions, which is essentially what a PWM wave is.
The conclusion I have reached is that perhaps we should raise the working frequency of the PWMs and observe what happens in relation to the noise of the power supplies.
In this case, and to raise the frequency for example to 16KHz (somewhat less) we must sacrifice the number of regulation steps and lower it to 1024, which you will do in order to have no other choice, since it seems to me something important to be able to have the 4096 steps that I would have before.
The problem I find is that I do not understand very well how the registers work to configure the parameters of Timer 1.
I did the program with the help of this forum in another previous post and it worked great for me at 12bits 4KHz. I put the example code here below. Let's see if someone can help me and modify it so that it works at 10bits 16Khz.
Thank you in advance and I hope that all this I have told will help other people.
// 12-Bit 4KHz PWM on PIN9 and PIN10 using direct access to Timer1 in Arduino Leonardo
// Fade in and out 2x LED output
// Markos Ferro 2020/11/26
#define LEDValueWarm OCR1A
#define LEDValueCool OCR1B
const int PWMMax = 4095;
int value = 1;
int direction = 1;
void setup() {
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
TCCR1A = (1 << COM1A1) |(1 << COM1B1) | (1 << WGM11); // Enable Fast PWM on OC1A (Pin 9 warm) and in OC1B (Pin 10 cool)
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10); // Mode 14 Fast PWM/ (TOP = ICR1), pre-scale = 1
ICR1 = PWMMax; //Set the TOP value for 12-bit PWM
LEDValueCool = 0; //Set the PWM output to full off.
LEDValueWarm = 0; //Set the PWM output to full off.
}
void loop() {
//Fade the LED between 0 and PWMMax and then back to 0
value += direction;
if (value <=0){
direction = 1;
}
else if (value >= PWMMax){
direction = -1;
}
LEDValueWarm = value;
LEDValueCool = value;
delay(25);
}