PROGRAM

const byte OUTPUT_PIN = 3;  // Timer 2 "B" output: OC2B

const byte n = 65;  // for example, 8.89 kHz

void setup()
 {
  pinMode (OUTPUT_PIN, OUTPUT);

  TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
  TCCR2B = bit (WGM22) | bit (CS21);         // fast PWM, prescaler of 8
  OCR2A =  n;                                // from table 
  OCR2B = ((n + 1) / 2) - 1;                 // 50% duty cycle
  }  // end of setup

void loop() { }

This page can be quickly reached from the link: http://www.gammon.com.au/timers

PWM Phase shifting program
 

Creating a variable frequency PWM output on Arduino UNO:

Arduino PWM cheat sheet: 

 

https://i2.wp.com/lh5.ggpht.com/--iP5HriHo70/Tt9AaevwgCI/AAAAAAAADg8/POSmoR0T8_g/clip_image005_thumb%25255B4%25255D.jpg?resize=622%2C246clip_image002

Comments

Popular posts from this blog

ARDUINO WITH I2C LCD DISPLAY USING PCF8574A

SEND SMS USING ARDUINO AND GSM