Advertisement
ossipee

arduino pwm

Jun 9th, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. {
  2.  // configure hardware timer2 to generate a fast PWM on OC2B (Arduino digital pin 3)
  3.  // set pin high on overflow, clear on compare match with OCR2B
  4.  TCCR2A = 0x23;
  5.  TCCR2B = 0x0C;  // select timer2 clock as 16 MHz I/O clock / 64 = 250 kHz
  6.  OCR2A = 249;  // top/overflow value is 249 => produces a 1000 Hz PWM
  7.  pinMode(3, OUTPUT);  // enable the PWM output (you now have a PWM signal on digital pin 3)
  8.  OCR2B = 125;  // set the PWM to 50% duty cycle
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement