Go Down

Topic: which crucial reason why Tone() does not work on the Due? (Read 1 time) previous topic - next topic

tito-t

hi,
what is the actual crucial reason why Tone() does not work on the Due?
On the other hand:
- does Tone work on the Zero?
- does Tone work on Teensys?

westfw

the SAM3x has complicated timers (two kinds of timers!) used for PWM, and the code is complex (probably over-complex), making it difficult to figure out how to use the timers for something else.

It actually looks like TC1 is essentially unused on Due (the PWM pins that COULD be driven are either not present, or are connected to the PWM controller or DAC (which are used in preference.)

tito-t

It actually looks like TC1 is essentially unused on Due (the PWM pins that COULD be driven are either not present, or are connected to the PWM controller or DAC (which are used in preference.)
does that mean it might be possible to kind of overwrite or abuse 1 of the DAC pins then for Tone()?

and how is this about the Zero or Teensys?

oqibidipo


tito-t

so IIUC, it's a constructional defect of the Due which cannot be fixed by an improved Tone() lib?

MorganS

Not really. The SAM3X chip has a lot of features such as a built-in real-time-clock and direct-access memory which aren't used on the Due. Some of those are design decisions that are frozen in the hardware and some of those are just because nobody has written the software for it yet.

The Due did not have asynchronous Serial for the first few years of its life until one of the contributors here wrote the code for it. I suspect that tone() is in the same category. The hardware can do it but nobody has published the code.
"The problem is in the code you didn't post."

tito-t

Not really. The SAM3X chip has a lot of features such as a built-in real-time-clock and direct-access memory which aren't used on the Due. Some of those are design decisions that are frozen in the hardware and some of those are just because nobody has written the software for it yet....The hardware can do it but nobody has published the code.
But as the Due is an original Arduino product, just like Uno, Mega, Yun, Zero:
Can't we expect then to have the general Arduino libs working for either Arduino board?
If technically possible, why do the Arduino.cc people release a board and then keep the libs for it unfinished and broken?

MorganS

Because there's no Arduino people except volunteers who publish stuff for others to use. If you want to write a tone() function for the Due, your name can be included in the contributors list.
"The problem is in the code you didn't post."

tito-t

Because there's no Arduino people except volunteers who publish stuff for others to use. If you want to write a tone() function for the Due, your name can be included in the contributors list.
really?
Massimo Banzi and the Arduino.cc company don't have CS employees who write the API libs code for their products?
If so, then that's really poor.

Naguissa

I don't think it's so difficult to fix.

If it uses TC1 (TC3, TC4 or TC5) they have no output pins. But then you should simply change the library to use other timer: TC0 (TC0-TC2) or TC2 (TC6-TC8).

Note: Due has 3 triple channel timers. Unfortunately, TCx can refer to physical timer or 'subtimers'.

You can see explanations here: https://translate.google.es/translate?hl=es&sl=auto&tl=en&u=https%3A%2F%2Fwww.foroelectro.net%2Felectronica-digital-microcontroladores-f8%2Ftimers-en-arduino-due-sam-t195.html

Seems that you cannot see CODE blocks with google Translate, and they contains interesting info and code, so you'll need to check it in spanish: https://www.foroelectro.net/electronica-digital-microcontroladores-f8/timers-en-arduino-due-sam-t195.html


I dont's know Due timers more deeply than exposed, but don't hesitate to ask if you have any translation problem.
ForoElectro.net

tito-t

I don't think it's so difficult to fix.

If it uses TC1 (TC3, TC4 or TC5) they have no output pins. But then you should simply change the library to use other timer: TC0 (TC0-TC2) or TC2 (TC6-TC8).

Note: Due has 3 triple channel timers. Unfortunately, TCx can refer to physical timer or 'subtimers'.

You can see explanations here: https://translate.google.es/translate?hl=es&sl=auto&tl=en&u=https%3A%2F%2Fwww.foroelectro.net%2Felectronica-digital-microcontroladores-f8%2Ftimers-en-arduino-due-sam-t195.html

Seems that you cannot see CODE blocks with google Translate, and they contains interesting info and code, so you'll need to check it in spanish: https://www.foroelectro.net/electronica-digital-microcontroladores-f8/timers-en-arduino-due-sam-t195.html


I dont's know Due timers more deeply than exposed, but don't hesitate to ask if you have any translation problem.

I personally can't do it because timers and "real" C++ library code (apart from the simplified Arduino API code) are far beyond my skills, and actually I don't have urgent need currently for tone() on the Due (but perhaps some day in the future).
But  as you stated that  it's not so difficult to fix, I (and probably many other users additionally) would appreciate very much if you did this fix!

Naguissa

I personally can't do it because timers and "real" C++ library code (apart from the simplified Arduino API code) are far beyond my skills, and actually I don't have urgent need currently for tone() on the Due (but perhaps some day in the future).
But  as you stated that  it's not so difficult to fix, I (and probably many other users additionally) would appreciate very much if you did this fix!
I've looked at it, but it's way too complicated and I have no time right now to do it. I can provide some sort of assistence if anyone wants to do so.

Steps to do:
  • If you don't have it, create a github account
  • Create a fork of: https://github.com/arduino/ArduinoCore-sam
  • Rename the file /blob/master/cores/arduino/Tone.cpp.disabled removing the ".disabled" suffix (git mv blob/master/cores/arduino/Tone.cpp.disabled blob/master/cores/arduino/Tone.cpp
  • Modify that file, blob/master/cores/arduino/Tone.cpp - You can do it at your arduino folder to test it and then copy the changes to the repository.
  • Commit, push
  • Create a Pull request to original repository.

Cheers!
ForoElectro.net

tito-t

now wait ...
I've looked at it, but it's way too complicated and I have no time right now to do it.
now you state that it's even way too complicated for yourself??

I already stated that writing C++ libs is far beyond my skills, so I can't do this task, there must be more advanced programmers to do that. But as already MorganS and westfw suggested it's not supposed to be that trivial eventually (and if it actually was, it probably already had been done since a long long time ago).
So I'm still curious if one will take pity on that thing....


Naguissa

now wait ...
now you state that it's even way too complicated for yourself??

I already stated that writing C++ libs is far beyond my skills, so I can't do this task, there must be more advanced programmers to do that. But as already MorganS and westfw suggested it's not supposed to be that trivial eventually (and if it actually was, it probably already had been done since a long long time ago).
So I'm still curious if one will take pity on that thing....


now you state that it's even way too complicated for yourself??

Not really, simply that it's not as easy as change few constants/defines.

But now I'm maintaining: https://github.com/Naguissa?tab=repositories

uTimerLib and uSevenSegmentLib (and fgew more to come) are meant to one BIG project I have in mind.

And, also, work, family and some personal things.... Simply, I have no time.
ForoElectro.net

Go Up