Pages: [1]   Go Down
Author Topic: Arduino Due Tone example not working  (Read 1511 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wifi and Tone are not yet ported for the Due. Wifi Library is the next in my todo list for the coming week.

Sorry guys there are a lot of libraries out there... :-(


Two months have passed, that is Tone () works now?
I tried a very simple program, the compiler tells me: "error: 'tone' was Not Declared in this scope"

How to operate Tone () on the Due? Int is in 4 bytes on said date. Is that I can exceed 64,000 hertz?

Your help is appreciated smiley
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am new to the DUE, but I did get the sound to work OK for my purposes. (Make some sound on the speaker on my shield to let me know something is happening...)

Code:
//==============================================================================
//    SoundNoTimer - Quick and dirty tone function to try to output a frequency
//            to a speaker for some simple sounds.
//==============================================================================
void SoundNoTimer(uint8_t _pin, unsigned long duration,  unsigned int frequency)
{
  // Try to get something working on DUE...
  long toggle_count = 0;
  long lusDelayPerHalfCycle;
  boolean fHigh = false;
  // Set the pinMode as OUTPUT
  pinMode(_pin, OUTPUT);
  digitalWrite(_pin, LOW);
  toggle_count = 2 * frequency * duration / 1000;
  lusDelayPerHalfCycle = 1000000L/(frequency * 2);

  // if we are using an 8 bit timer, scan through prescalars to find the best fit
  while (toggle_count--) {
    // toggle the pin
    fHigh  = !fHigh;
    digitalWrite(_pin, fHigh? LOW : HIGH);
    // delay a half cycle
    delayMicroseconds(lusDelayPerHalfCycle);
  }   
  digitalWrite(_pin, LOW);
}
Note on other platforms, this code uses Port Masks and the like to set/clear the values as quickly as possible... 

Not saying this is great, but may get you limping along.
Kurt
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Kurt thank you, your solution will allow me to test until they find something better. When you go up in frequency with your trick, it becomes unclear.

I was hoping to convert the Arduino Duo frequency generator. smiley And I need to do a full scan between certain frequencies. I hoped, with integers coded on 4 bytes, have a Tone (), which amounts to 1 Ghz ... smiley This is not Christmas every day smiley.
Tone function () she will walk one day?
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
   That keeps you code pretty busy, you could try interrupts instead, here is a simple example of generating a sinewave, it would be easy to add other waveforms, see the second example for a simple synth based on the same code -

DDS Sinewave on Due
http://rcarduino.blogspot.com/2012/12/arduino-due-dds-part-1-sinewaves-and.html

Quick and dirty synth on Due
http://rcarduino.blogspot.com/2012/11/quick-and-dirty-synth-for-arduino-due.html

Duane B

rcarduino.blogspot.com
Logged


Offline Offline
Newbie
*
Karma: 1
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep - you are correct that it sits and hangs in the code.  But before I was using the Tone command and found myself doing things like:
Code:
tone(pin, 2000, 250);
delay(250);
So it did not buy me anything to use up the timer.  Also my code that uses this, often passes in multiple notes to play, which is easy to do when you are doing it in a hard loop.

Also a lot of the code I do is for robots.  Sometimes using the servo library, or my own version of it (ServoEx), which does timed moves...   The Servo library relies heavily on the timer interrupts timing and having other interrupts often leads to servos that jitter. 

But for other uses I would definitely look into using timers and interrupts.

Good luck
Kurt
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks
I tried tone (pin, frequency) and I thought tone (pin, frequency, delay) work better, but no: (

 tone(5, 2000, 250);
 delay(250);

test_frequence_001.ino: In function 'void loop()':
test_frequence_001:13: error: 'tone' was not declared in this scope

tone () works with you on Aduino due?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check this thread too:
http://forum.arduino.cc/index.php?topic=136500.0
Logged

Pages: [1]   Go Up
Jump to: