Go Down

Topic: Please Help, I want to generate PWM of frequency with 40khz (Read 1 time) previous topic - next topic

chetan06soni

I want to generate PWM of frequency 40Khz with 60% duty cycle and there should be another signal of same frequency, but this other signal should be 180 degrees from the previous one.
please help, i have to complete my project.

CrossRoads

Code: [Select]

/* sketch to output 40KHz signal, 60/40 waveform
 25uS period, *.6 = 15uS, *.4 = 10uS
 run on regular Arduino
 */

void setup(){
  pinMode (2, OUTPUT);
  pinMode (3, OUTPUT);
  digitalWrite (2, LOW); // set initial states
  digitalWrite (3, HIGH);
}
void loop(){

  while (1){ // reduce jitter from main & loop code
    delayMicroseconds(10);
    PIND = PIND | 0b00001100; // toggle output by writng to input register
    delayMicroseconds(15);
    PIND = PIND | 0b00001100;
  }
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

chetan06soni

Thank You Sir, I will test the code.
Thanks for your help.

jeet55

you can use a not gate to invert the output by 180 degrees

Go Up