i tried another code with timer 0 and trying to adjust OCR0A&B values to change the freq of the pulses and i am using proteus simulator the frequency is not changed whatever i do and const at 62KHz
#define dute_cycle 40
void setup() {
// Set pins 5 and 6 as output
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
// Configure Timer0 for Fast PWM mode
TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << WGM01) | (1 << WGM00);
TCCR0B = (1 << CS00); // No prescaler
// Set TOP value for desired frequency (30 kHz)
// Formula: TOP = (F_CPU / (N * desired frequency)) - 1
// For Arduino Nano (16 MHz), N = 1
OCR0A = 105; // TOP value for pin 5 (16 MHz / (1 * 30 kHz) - 1)
OCR0B = 105; // TOP value for pin 6 (16 MHz / (1 * 30 kHz) - 1)
}
void loop() {
// Adjust duty cycle if needed
// Example: 50% duty cycle for both pins
analogWrite(5, (dute_cycle * 255) / 100);
analogWrite(6, 128);
}
Do you have any idea what is happening?