PWM High-Frequency Generation

Solving Approach:

How do you plan to solve it?

 

 

Code

/*Paste your code here*/
#define potpin A0
void setup() {
  pinMode(9, OUTPUT);
  
  // Set Fast PWM on Timer1, change prescaler
  TCCR1A = _BV(COM1A1) | _BV(WGM11); // non-inverting mode, Fast PWM
  TCCR1B = _BV(WGM12) | _BV(CS11);  // prescaler = 8, PWM freq = 7.8kHz


}

void loop(){
  int potval = analogRead(potpin);
  int led = map(potval, 0, 1023, 0, 255);
  OCR1A = led; // Duty cycle
  delay(10);
}

 

Output

Video

Add video of output (know more)

 

 

 

 

Photo of Output

Add a photo of your hardware showing the output.

 

 

 

 

Upvote
Downvote

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!