Help please...i can´t decide how to generate my frequency...

Hello people and thanks for helpme…
I am argentinian…
sorry for my english…

In my project i need generate 2 simultaneous sweep frecuencies…

Frec 1: sweep from 1KHz to 30 KHz.
Frec 2: sweep from 10KHz to 20KHz.

I made a sketch with “delayMicroseconds” function and i get a beautifull sweep frecuency, but when i need add the second frecuency sweep to the sketch is when the problem appears…
I was reading and think that the second sweep can be make with “interrupts” or both sweeps can be make with “interrupts”…but i can´t make it work…

i need a basic sketch for start and then going modifying them for get the final sketch
can anyone help me with that code?..thanks so much.

This is the sketch for the Frec1: I need add the Frec 2 for this sketch…

int salida = 13;
int sentido = 1;
float timef = 7;
float multi = 1.01;
float divis = 0.01;

void setup() {
pinMode (salida , OUTPUT);
}

void loop () {

if (sentido == 1) {

if (timef <= 489) {
digitalWrite (salida , HIGH);
delayMicroseconds (timef);
digitalWrite (salida , LOW);
delayMicroseconds (timef);

timef = timef * multi;
}

else {
sentido = sentido + 1;
}

}

if (sentido == 2) {

if (timef >= 7) {
digitalWrite (salida , HIGH);
delayMicroseconds (timef);
digitalWrite (salida , LOW);
delayMicroseconds (timef);

timef = timef - (timef * divis);
}

else {
sentido = sentido - 1;
}
}
}

/*

7 uS = 31 KHZ
489 uS = 1 KHZ

*/

Look at the BlinkWithoutDelay example, it explains how to do things without blocking the flow using delay()

The demo several things at a time is an extended example of BWoD.

...R

The third-party Tone library (https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation) can play different tones on different pins.

#include <Tone.h>
Tone tone1, tone2;

void setup() {
  tone1.begin(2);
  tone2.begin(3); 
}

// Sweep F1 from 1 kHz to 30 kHz
// Sweep F2 from 10 kHz to 20 kHz
void loop() {
for (unsigned F2=10000; F2<=20000, F2++) {
    unsigned F1 = map(F2, 10000, 20000, 1000, 30000);
    tone1(F1);
    tone2(F2);
    delay(5);  // Larger delay for slower sweep
    }
}

thanks so much... i will try it with this info...

:slight_smile: :slight_smile: