Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte LED = 3; // Timer 2 "B" output: OC2B
- const int divider = 2;
- const long frequency = 150000L; // Hz (eg:150000=150khz)
- void setup()
- {
- Serial.begin(9600);
- pinMode (LED, OUTPUT);
- TCCR2A = _BV (WGM20) | _BV (WGM21) | _BV (COM2B1); // fast PWM, clear OC2B on compare
- TCCR2B = _BV (WGM22) | _BV (CS21); // fast PWM, prescaler of 8
- OCR2A = ((F_CPU / 8) / frequency) - 1; // zero relative
- OCR2B = ((OCR2A + 1) / divider) - 1; // 50% duty cycle
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement