This code below:
void setup() {
#if defined(__AVR_ATmega168__)
// 62.5KHz PWM for the ATMega168 -> only on Arduino pins 9 and 10
// set prescaler to 1
// (sbi means "set bit register", cbi means "clear bit register")
cbi(TCCR1B, CS12);
cbi(TCCR1B, CS11);
sbi(TCCR1B, CS10);
// set fast PWM
cbi(TCCR1B, WGM13);
sbi(TCCR1B, WGM12);
// with fast PWM, the frequency is (CLK/256*prescaler) = 16MHz/256 = 62.5KHz
// with slow PWM, it is half that speed (31KHz)
#else
// 22KHz for the ATMega8 (this is a low frequency)
TCCR2 = ((TCCR2 & ~0x07) | 0x01); //<ERROR POINTS HERE!
TCCR1B = ((TCCR1B & ~0x07) | 0x01);
#endif
}
when verify, generates an error:
In function 'void setup()':
pwm-control-1:185: error: 'TCCR2' was not declared in this scope
TCCR2 = ((TCCR2 & ~0x07) | 0x01);
^
exit status 1
'TCCR2' was not declared in this scope
So far i know this code generates pwm at pin 9 or 10, and designed for ATmega168 or ATmega8. The code came with a .pde extension and I opened it on 'Arduino: 1.8.3' and saved as an .ino file.
Can any one please tell me how to convert this code to work with 'ATmega328P-PU' and for the latest Arduino IDE. And also if there anything else to consider running with this code
I'm not an expert in pwm and timer/controls in micros... just started to learn..
Note: I've only shown the necessary part of the code