Go Down

Topic: TONE() interferences at 1MHz clock (8MHz/DIV8) (Read 587 times) previous topic - next topic

Datman

Apr 13, 2015, 05:48 pm Last Edit: Apr 14, 2015, 12:34 am by Datman
Hi all
I've made a device that in some situations have to produce a "beep" on a piezo buzzer.
Buzzer is connected to I/O 4 (pin 6 of an ATMEGA328P, PD4/T0).
At a first time I was using the classic Arduino XTAL clock at 16MHz with no problems. When all was working, I began optimizing. I wanted to lower energy consumption, then I worked to lower clock frequency. To do that, I modified boards.txt adding a "Arduino uno 1MHz (ATmega328)" entry:

uno1MHz.name=Arduino uno 1MHz (ATmega328)
uno1MHz.upload.protocol=arduino
uno1MHz.upload.maximum_size=32256
uno1MHz.upload.speed=9600
uno1MHz.bootloader.low_fuses=0x62
uno1MHz.bootloader.high_fuses=0xd9
uno1MHz.bootloader.extended_fuses=0xfd
uno1MHz.bootloader.path=optiboot
uno1MHz.bootloader.file=optiboot_atmega328.hex
uno1MHz.bootloader.unlock_bits=0x3F
uno1MHz.bootloader.lock_bits=0x0F
uno1MHz.build.mcu=atmega328p
uno1MHz.build.f_cpu=1000000L
uno1MHz.build.core=arduino
uno1MHz.build.variant=standard

Writing the bootloader I've set the fuses, then I loaded the code.

Now it's clocked by the internal RC oscillator divided by 8.
All seemed OK, except for delayMicroseconds(100). I solved that using a delay(.12) that gives a 100uS delay (we know that RC clock have a large tolerance).

There is a little problem: now the 1 second "beep" is affected by a periodic noise, a "cri-cri-cri-cri" about every 400mS for a 1kHz tone.  What does it come from? Interrupts?... Why it doesn't happen with a 16MHz clock? How works tone()?

Thanks for your help.
Gianluca

Edit: it depends on the tone frequency.
It is the same on I/O 6 or I/O 12.
The noise doesn't occour every time with the same delay relative to the tone start: it has its own timing.

Test code:

int a=12;
void setup()
{
  pinMode (a, OUTPUT);
}
void loop()
{
  tone(a, 1000);
  delay (2000);
  noTone(a);
  delay (1000);
  }
Hi,I'm Gianluca from Roma.I play&work with electronics since I was16(1984).
After 25yrs of maintenance on cameras&video mixers,since 2013myJob is HDTVstudios design.
Since Jan2015 IPlayWith Arduino:bit.ly/2F3LPWP
Thanks 4 a Karma if U like my answer

Go Up