Arduino pulse generator

Hello everyone,
I need help for creating software for Arduino Uno that can generate a number of square wave pulses that can be adjusted with potentiometer at frequency also adjustable with potentiometer. Could you guys help me out?

What have you tried so far ?

What range of frequencies are required ?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Have you googled arduino pulse generator

Tom… :slight_smile:

Thanks for the link.

I think Tone function would be ok for testing. Frequency range 35Hz to 60KHz is very good for my project.

I have googled Arduino Pulse Generator…

The best solution I have found so far was this bit of code:

void myTone(byte pin, uint16_t frequency, uint16_t duration)
{ // input parameters: Arduino pin number, frequency in Hz, duration in milliseconds
  unsigned long startTime=millis();
  unsigned long halfPeriod= 1000000L/frequency/2;
  pinMode(pin,OUTPUT);
  while (millis()-startTime< duration)
  {
    digitalWrite(pin,HIGH);
    delayMicroseconds(halfPeriod);
    digitalWrite(pin,LOW);
    delayMicroseconds(halfPeriod);
  }
  pinMode(pin,INPUT);
}

void setup() {
}

void loop() {
  myTone(8,1000, 2000); // tone on pin-8 with 1000 Hz for 2000 milliseconds
  delay(1000);

With map function it will read the value of a potentiometer and adjust frequency. Pulses don’t have to be continuos, delay of 1000 is ok.

How to make it read potentiometer value for frequency, read potentiometer value for pulses, generate and count number of pulses, delay and start over again?