Voltage output using Tone()

Hello,

I normally can use analogwrite() to give a voltage output 0-5V, but I need to record on a campbell scientific 3000 datalogger, which samples much faster than what I am used to. Instead of an average PWM voltage, the datalogger records the voltage of each and every high and low in the pulse, so essentially it just reads 0 or 5V and nothing in between. What the datalogger CAN do is read the distance between those pulses if at 50% duty cycle. So, I am wondering if there is a way to use Tone() to output a 50% duty cycle PWM? Below is a sample of my code.

int zerov = 35; //Minimum freq of Uno Hz + 13100 
int onev = 13135;
int twov = 26235;
int threev = 39335;
int fourv = 52435;
int fivev = 65535; // Max Freq of Uno Hz

int melody[] = {
  zerov, onev, twov, threev, fourv, fivev
};

int noteDurations[] = {
  5,5,5,5,5
};

void setup() {

}

void loop() {

  // iterate over the notes of the melody:
  for (int thisNote = 1; thisNote < 6; thisNote++) {
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(9, melody[thisNote], noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
}
}

Right now, I am getting nothing out of the Uno, but when I do analogWrite from 0-255, I can get 0-5V fine, but only on my multimeter, not the datalogger.

Any ideas on using tone to output voltage at 50% duty cycle?

Thank you.

You need a low-pass filter between the analog output and the Campbell. A resistor and capacitor will do.

I was using a capacitor, but it was bulky and annoying to solder. So I figured it out anyway! Code below!

int zerov = 35; //+ 13100
int onev = 100;
int twov = 200;
int threev = 300;
int fourv = 400;
int fivev = 500;

int melody[] = {
  zerov, onev, twov, threev, fourv, fivev
};

void setup() {
}

void loop() {
  for (int thisNote = 0; thisNote < 6; thisNote++) {
    tone(7, melody[thisNote]);
    delay(5000);
    noTone(8);
  }
}

and CR basic code for anyone interested

Public BattV
Units BattV = Volts
Public Freq
Units Freq = HZ



DataTable (Power,1,9999) 'Set table size to # of records, or -1 to autoallocate.
  DataInterval (0,10,Sec,10)
  Average (1,BattV,FP2,False)
  Average(1,Freq,IEEE4,False)
EndTable

BeginProg
  Scan (1,Sec,0,0)
    'VoltSe (BattV,1,mV5000,28,1,5000,250,.001,0)
    TimerIO (Freq,11111110,00000002,100,mSec)
    If Freq<100 Then
      BattV = 0.0154 * Freq - 0.5385
    Else
      BattV = Freq / 100
    EndIf
    CallTable Power
  NextScan
EndProg

That would be FM (Frequency Modulation) and not PWM at all.

Well done! I may use that myself as I have one of those Campbell units too.

(Karma added.)