Pages: [1]   Go Down
Author Topic: Tone Library and Digital Potentiometer - Weird results  (Read 1096 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino Rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm attempting to use the tone library and a digital potentiometer to programmatically change the volume of my tones.
I have not even hooked up the digital potentiometer yet. When I call the subroutine to enable volume change, I shouldn't get any volume change at all because I haven't hooked up the chip yet. I expect to get a tone in each ear and a corresponding delay for a total repeating duration of about 4 seconds. This works correctly in the left ear. However, in the right ear, I get a rising, then falling pitch for the same duration as the left ear. This may have something to do with the limitations of the Atmega 328. I'd be grateful if someone could explain why what I'm doing does not give expected results, and whether there is a workaround that will work with the digital potentiometer I've chosen.
Code:
/*********************************************************
Sketch: Tone_Test_With_Digital_Potentiometer
Author: Chris Sparnicht - http://low.li
Date: 2011.01.31
License: Creative Commons 2.5 Attrib. & Share Alike
Description: A binaural tone test for arduino.
Note: Make sure you have dual wheel potentiometer to reduce
the volume of the audio with your headset. If you don't,
you might damage your ear drums, your arduino or your headset.

*********************************************************/
/*********************************************************
Include the arduino tone library (you'll have to download
this from arduino.cc's playground, since it's not standard.
*********************************************************/
#include <Tone.h>
//Variables for tone generator
float binauralBeat[] = { 14.4, 11.1, 6.0, 2.2 };
Tone rightEar;
Tone leftEar;
float centralTone = 200; //We're starting at this tone and spreading the binaural beat from there.
int volumeRight = 3;
int volumeLeft = 11;

/*********************************************************
Setup defines pins and tones.
*********************************************************/
void setup()  {
  Serial.begin(9600);
  rightEar.begin(9);
  leftEar.begin(10);
  pinMode(volumeRight, OUTPUT);
  pinMode(volumeLeft, OUTPUT);
}

/*********************************************************
Main function - play the tones continuously in a loop
*********************************************************/
void loop()
{
  for (int i = 0; i < 4; i++){
  rightEar.play(centralTone - (binauralBeat[i]/2));
  leftEar.play(centralTone + (binauralBeat[i]/2));
  // Serial.print("Right Ear: ");
  Serial.print(centralTone - (binauralBeat[i]/2));
  Serial.print(" | ");
  // Serial.print(" | Left Ear: ");
  Serial.println(centralTone + (binauralBeat[i]/2));
//   delay(3000);
  crescendoDecrescendo();
  rightEar.stop();
  leftEar.stop();
  delay(1000);
  }
}

void crescendoDecrescendo(){
  for (int j = 0; j < 256; j++){
    analogWrite(volumeRight, j);
    analogWrite(volumeLeft, j);
    delay(7);
  }
  for (int j = 255; j > 0; j--){
    analogWrite(volumeRight, j);
    analogWrite(volumeLeft, j);
    delay(7);
  }
}
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31462
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I shouldn't get any volume change at all because I haven't hooked up the chip yet.
Yes but you are using software timers, the same that the Tone Library uses. The only way round this I can think of is to write your own digital pot interface code so that it doesn't need the internal timers.
Logged

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I know this is a little late for a reply, but there is a solution, as long as you only use 2 tones.

The first two tones created will use timers 2 and 1.  This means that Timer 0 is still configured such that you can use pins 5 & 6 as PWM outputs.

Change your Volume pins to 5 & 6 and you should be good to go.


b
Logged


Pages: [1]   Go Up
Jump to: