Free Energy Research
Pulse Exact Frequencies - Printable Version

+- Free Energy Research (https://www.mooker.com)
+-- Forum: Other Discussions (https://www.mooker.com/forum-17.html)
+--- Forum: Useful Arduino Codes (https://www.mooker.com/forum-26.html)
+--- Thread: Pulse Exact Frequencies (/thread-12.html)



Pulse Exact Frequencies - Jim Mac - 08-16-2023

I just wanted to post this in case it helps others..

Using arduino and H-bridge to flip polarities, it can be difficult to pulse DC square waves at exact controllable frequencies without complex timers, etc.  And counting delay microseconds is hit or miss..

I figured out a way to use the "Tone Function" to control frequency of pulses.  Just have to change the Hz value in the code and it's dead on..  I been playing with a resonance circuit and the frequency on the scope is exact..  Be aware- it will only work up to 31 Khz tho..


!!!!!!!!!!!!!!!!!!!!!!!!!!  CODE !!!!!!!!!!!!!!!!!!!!!!!

int r1 = 6;
int r2 = 7;
int receiver = 8;

void setup(){

  pinMode(r1, OUTPUT);
  pinMode(r2, OUTPUT);
  pinMode(receiver, INPUT);
  tone(5, 1000);

}

void loop() {

if (receiver == HIGH)
  {
  digitalWrite(r1, LOW);
  digitalWrite(r2, HIGH);
  }
else
{
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);
 
}


}

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Now on the arduino, put a jumper from D5 to D8.  And connect your H bridge PWM inputs to pins 6 and 7.  Thats it....
To change frequency-  find this code "tone(5, 1000);"  and change 1000 to whatever hertz you want up to 31000 Hz.

Maybe someone will find this useful!