Skip to main content
Bumped by Community user
Bumped by Community user
added 31 characters in body
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

code Code to obtain PWM output

I tried a code to obtain 100KHZ PWM output with a 41.66% duty cycle by reading an analog value atfrom A0, which is compared with a reference 5V value for obtaining PWM value.

Can some onesomeone help me with the code? Any help is very much appreciated.

hereHere is my code.

  int Pwmpin=9;//Pwm Output Pin
  int Fchange= A0;//Frequency change through Potentiometer
   
void setup()
  {
  pinMode(Pwmpin, OUTPUT);//Pwm pin as Output
  Serial.begin(9600);
  TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode
  TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8
  }

  void loop(){
  float freq=0;
  float count=10000,countt=0,Pinput=0;
 
  while(1){
    ICR1=count;//variable Frequency
    countt=16*count;
    freq= int(16000000/countt);
    OCR1A=int(count/2);
    Serial.print("Pwm Freq =");
    Serial.println(freq);
    count=10000;
    Pinput=analogRead(A0);//Read input value
    Serial.print("adc value is:");
    Serial.println(Pinput);
    Pinput=(Pinput/0.0113);
    Serial.print("pwm value is:");
    Serial.println(Pinput);
    count=count+Pinput;
    if(count>=100000)
  {
      count=10000;
    }
    delay(1000);
  }
 }

code to obtain PWM output

I tried a code to obtain 100KHZ PWM output with 41.66% duty cycle by reading an analog value at A0 which is compared with a reference 5V value for obtaining PWM value.

Can some one help me with the code? Any help is very much appreciated.

here is my code.

  int Pwmpin=9;//Pwm Output Pin
  int Fchange= A0;//Frequency change through Potentiometer
  void setup()
  {
  pinMode(Pwmpin, OUTPUT);//Pwm pin as Output
  Serial.begin(9600);
  TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode
  TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8
  }

  void loop(){
  float freq=0;
  float count=10000,countt=0,Pinput=0;
 
 while(1){
 ICR1=count;//variable Frequency
 countt=16*count;
 freq= int(16000000/countt);
 OCR1A=int(count/2);
 Serial.print("Pwm Freq =");
 Serial.println(freq);
 count=10000;
 Pinput=analogRead(A0);//Read input value
 Serial.print("adc value is:");
 Serial.println(Pinput);
 Pinput=(Pinput/0.0113);
 Serial.print("pwm value is:");
 Serial.println(Pinput);
 count=count+Pinput;
 if(count>=100000)
  {
    count=10000;
 }
    delay(1000);
  }
 }

Code to obtain PWM output

I tried code to obtain 100KHZ PWM output with a 41.66% duty cycle by reading an analog value from A0, which is compared with a reference 5V value for obtaining PWM value.

Can someone help me with the code? Any help is very much appreciated.

Here is my code.

int Pwmpin=9;//Pwm Output Pin
int Fchange= A0;//Frequency change through Potentiometer
 
void setup() {
  pinMode(Pwmpin, OUTPUT);//Pwm pin as Output
  Serial.begin(9600);
  TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode
  TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8
}

void loop(){
  float freq=0;
  float count=10000,countt=0,Pinput=0;
  while(1){
    ICR1=count;//variable Frequency
    countt=16*count;
    freq= int(16000000/countt);
    OCR1A=int(count/2);
    Serial.print("Pwm Freq =");
    Serial.println(freq);
    count=10000;
    Pinput=analogRead(A0);//Read input value
    Serial.print("adc value is:");
    Serial.println(Pinput);
    Pinput=(Pinput/0.0113);
    Serial.print("pwm value is:");
    Serial.println(Pinput);
    count=count+Pinput;
    if(count>=100000) {
      count=10000;
    }
    delay(1000);
  }
}
added 181 characters in body
Source Link

I tried a code to obtain 100KHZ PWM output with 41.66% duty cycle by reading an analog value at A0 which is compared with a reference 5V value for obtaining PWM value.

Can some one help me with the code? Any help is very much appreciated.

here is my code.

int Pwmpin=9;//Pwm Output Pin int Fchange= A0;//Frequency change through Potentiometer void setup() { pinMode(Pwmpin, OUTPUT);//Pwm pin as Output Serial.begin(9600); TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8 }

void loop(){ float freq=0; float count=10000,countt=0,Pinput=0;

while(1){ ICR1=count;//variable Frequency countt=16*count; freq= int(16000000/countt); OCR1A=int(count/2); Serial.print("Pwm Freq ="); Serial.println(freq); count=10000; Pinput=analogRead(A0);//Read input value Serial.print("adc value is:"); Serial.println(Pinput); Pinput=(Pinput/0.0113); Serial.print("pwm value is:"); Serial.println(Pinput); count=count+Pinput; if(count>=100000) { count=10000; } delay(1000); } }

  int Pwmpin=9;//Pwm Output Pin
  int Fchange= A0;//Frequency change through Potentiometer
  void setup()
  {
  pinMode(Pwmpin, OUTPUT);//Pwm pin as Output
  Serial.begin(9600);
  TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode
  TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8
  }

  void loop(){
  float freq=0;
  float count=10000,countt=0,Pinput=0;

 while(1){
 ICR1=count;//variable Frequency
 countt=16*count;
 freq= int(16000000/countt);
 OCR1A=int(count/2);
 Serial.print("Pwm Freq =");
 Serial.println(freq);
 count=10000;
 Pinput=analogRead(A0);//Read input value
 Serial.print("adc value is:");
 Serial.println(Pinput);
 Pinput=(Pinput/0.0113);
 Serial.print("pwm value is:");
 Serial.println(Pinput);
 count=count+Pinput;
 if(count>=100000)
 {
    count=10000;
 }
    delay(1000);
  }
 }

I tried a code to obtain 100KHZ PWM output with 41.66% duty cycle by reading an analog value at A0 which is compared with a reference 5V value for obtaining PWM value.

Can some one help me with the code? Any help is very much appreciated.

here is my code.

int Pwmpin=9;//Pwm Output Pin int Fchange= A0;//Frequency change through Potentiometer void setup() { pinMode(Pwmpin, OUTPUT);//Pwm pin as Output Serial.begin(9600); TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8 }

void loop(){ float freq=0; float count=10000,countt=0,Pinput=0;

while(1){ ICR1=count;//variable Frequency countt=16*count; freq= int(16000000/countt); OCR1A=int(count/2); Serial.print("Pwm Freq ="); Serial.println(freq); count=10000; Pinput=analogRead(A0);//Read input value Serial.print("adc value is:"); Serial.println(Pinput); Pinput=(Pinput/0.0113); Serial.print("pwm value is:"); Serial.println(Pinput); count=count+Pinput; if(count>=100000) { count=10000; } delay(1000); } }

I tried a code to obtain 100KHZ PWM output with 41.66% duty cycle by reading an analog value at A0 which is compared with a reference 5V value for obtaining PWM value.

Can some one help me with the code? Any help is very much appreciated.

here is my code.

  int Pwmpin=9;//Pwm Output Pin
  int Fchange= A0;//Frequency change through Potentiometer
  void setup()
  {
  pinMode(Pwmpin, OUTPUT);//Pwm pin as Output
  Serial.begin(9600);
  TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode
  TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8
  }

  void loop(){
  float freq=0;
  float count=10000,countt=0,Pinput=0;

 while(1){
 ICR1=count;//variable Frequency
 countt=16*count;
 freq= int(16000000/countt);
 OCR1A=int(count/2);
 Serial.print("Pwm Freq =");
 Serial.println(freq);
 count=10000;
 Pinput=analogRead(A0);//Read input value
 Serial.print("adc value is:");
 Serial.println(Pinput);
 Pinput=(Pinput/0.0113);
 Serial.print("pwm value is:");
 Serial.println(Pinput);
 count=count+Pinput;
 if(count>=100000)
 {
    count=10000;
 }
    delay(1000);
  }
 }
Source Link

code to obtain PWM output

I tried a code to obtain 100KHZ PWM output with 41.66% duty cycle by reading an analog value at A0 which is compared with a reference 5V value for obtaining PWM value.

Can some one help me with the code? Any help is very much appreciated.

here is my code.

int Pwmpin=9;//Pwm Output Pin int Fchange= A0;//Frequency change through Potentiometer void setup() { pinMode(Pwmpin, OUTPUT);//Pwm pin as Output Serial.begin(9600); TCCR1A=_BV(COM1A1)|_BV(COM1B1);//Non-inverted Mode TCCR1B=_BV(WGM13)|_BV(CS11);//Prescalar 8 }

void loop(){ float freq=0; float count=10000,countt=0,Pinput=0;

while(1){ ICR1=count;//variable Frequency countt=16*count; freq= int(16000000/countt); OCR1A=int(count/2); Serial.print("Pwm Freq ="); Serial.println(freq); count=10000; Pinput=analogRead(A0);//Read input value Serial.print("adc value is:"); Serial.println(Pinput); Pinput=(Pinput/0.0113); Serial.print("pwm value is:"); Serial.println(Pinput); count=count+Pinput; if(count>=100000) { count=10000; } delay(1000); } }