Very simple Tone sketch not working on Attiny85 works on arduino nano perfectly

Hey I need a very simple frequency generator for a project I'm working on. I just need 100Hz on a pin. Thought tone would be nice cause i can change freqency really fast without extra work.

I've tested this with my attiny85 running 1Mhz internal oscillator and no BOD with this
arduino-tiny-0100-0018.zip
from
https://code.google.com/archive/p/arduino-tiny/
on arduino 1.0.5

Im connected on the bottom right pin on attiny85 (PB0)

I've also tried arduino 1.6 with the MIT Attiny85 stuff http://highlowtech.org/?p=1695

void setup() {
  // put your setup code here, to run once:
    pinMode(0, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly: 
    tone(0, 100);
}

This works perfectly when I upload this exact same no changes sketch to a arduino nano.
On arduino I'm on D0/RX pin. Literally all I change is the board type.

To test my Attiny85 circuit I uploaded this sketch. It works perfectly at around 100Hz.

int freq_out = 0;

void setup() {
    pinMode(freq_out, OUTPUT);
 }

void loop() {
  digitalWrite(freq_out, HIGH);   
  delay(5);              
  digitalWrite(freq_out, LOW);    
  delay(5); 

}

I've got to be missing something really easy. Anyone have any ideas? Even though the last sketch works I'd rather use tone because eventually I'd like to look up a sensor value and adjust the freqency out between 75Hz and 200Hz without the delays and a lot of extra code.

Thanks in advance.

void setup() 
{
    tone(0, 100);
}

void loop() 
{
}

I'm not sure what you mean by this. Are you not able to change tone in loop? Or do you need to call it at least once in setup?

What does one do with source code? Compile it. Upload it. Test it.

Doing that accomplishes a list of things the net result of which is to get you to a complete solution in the fewest number of steps.

I thought the question was pretty valid. (ie: changing tone in loop()).

Also..posting code with NO context doesnt do anyone any good. (especially when there were direct questions asked)

xl97:
I thought the question was pretty valid. (ie: changing tone in loop()).

It is.

Also..posting code with NO context doesnt do anyone any good.

Your failure to see the good does not mean it does not exist.

(especially when there were direct questions asked)

Once @nosredna000 indicates the code in reply #1 works with his hardware I will be happy to answer his questions. That has always been the case.

No change. Could be outputting something (have no way to test, buzzer or scope) but for sure it is not outputting something between 50hz-200hz. manually pulsing it with delays gives expected results.

nosredna000:
manually pulsing it with delays gives expected results.

Excellent. Glad to know you have a solution.

xl97:
I thought the question was pretty valid. (ie: changing tone in loop()).

The standard tone works when called in quick succession because the timer is not stopped between calls nor is the count reset. Essentially the timer is reconfigured to be exactly the same as it was. This causes pops / ticks / pauses when when the frequency is changed.

I found the pops / ticks / pauses to be intolerable. tone in the Tiny Core stops the timer, resets the count, configures the timer, then starts it. While not completely eliminating the artifacts it does reduce them. If tone is called in quick succession, as in @nosredna000's example, the timer never has a chance to do the first pin toggle.

In other words, I traded quality for reliability. (That trade was not strictly necessary but to get both would have meant significantly more code.)

Your misunderstanding me. I cannot get Tone to output a frequency if I call it in setup or loop.. If I test the circuit and hardware by manually pulseing it with pin high/low delay I get the exact results that the math works out to. For instance on for delay(10) off for delay(10) gives 50 Hz on the nose

This (using delays) doesn't serve my purpose very well because the circuit needs to be working on other things and not halted like with delay. I'd like tone to work.

I'm not following you on what the solution should be.

Instead of Tone, you can use blink without delay:

void loop(){
currentMillis = millis();
if ((currentMillis- previousMillis) >= halfPeriod){  // maybe include checking a flag to decide if on or off
previousMillis = currentMillis + halfPeriod; // with unsigned long halfPeriod = 10;  declared earlier
PIND = PIND | 0b00000100; // toggle by writing to input register, D2 for example
}
// do whatever else is going on
}

nosredna000:
I'd like tone to work.

It does work. I have personally tested...

https://code.google.com/archive/p/arduino-tiny/

...with each pin on an ATtiny85 processor. There are thousands of people using that core. Of those thousands, you are the only one claiming tone does not work.

I'm not following you on what the solution should be.

You have been given a complete accurate description of why tone will not work in your original example. You have been given a complete accurate example that does work.

arduino-tiny-0100-0018.zip from Google Code Archive - Long-term storage for Google Code Project Hosting.
http://highlowtech.org/?p=1695

Which?

Im connected on the bottom right pin on attiny85 (PB0)

What?

Well tried tone again and again no dice. It is either outputing a frequency that is not what you set it to or the signal flat out isn't like digital on/off.

Went back and re-wrote everything like blink with no delay and that works just like my original basic example.

too bad tone wouldn't work for me. I thought it would be a easy square wave function generator.

Too bad you failed to answer two simple questions. Maybe if you had you would get help.

I'm not sure why your asking these questions both are answered in the first post. I used both

arduino-tiny-0100-0018.zip
from
Google Code Archive - Long-term storage for Google Code Project Hosting.
on arduino 1.0.5

and
I've also tried arduino 1.6 with the MIT Attiny85 stuff http://highlowtech.org/?p=1695

and how else can I tell you which pin I'm connected to?

bottom right pin PB0, 0 physical pin 5

The question was "What?" As in, what is connected to the pin?

a piece of equipment that is looking for a square wave 0-5v between 75Hz and 200Hz

I have used tone on an ATTiny and it worked. I wonder if you have a bad core. I haven't tried it lately but I had made several musical projects with an ATTiny85 and speaker using tone.

Try the core from atmel. The latest ide lets you manage different boards.

If you are still stuck, I'll try it again on an ATTiny85 with the core I have.

Hey Shawn, Are you fairly certain the frequency is right? I'm curious if you try the same tone frequency on a nano or uno and the one on a ATtiny85 delievers the same audible note?

Mind sharing a simple piece of code and I'll test here.

So far

void setup() {
  // put your setup code here, to run once:
    pinMode(0, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly: 
    tone(0, 100);
}

and

void setup() 
{
    tone(0, 100);
}

void loop() 
{
}


}

does not give the same results for me as the same code loaded on a nano.

I'm currently using this board type. The links for the two I've got loaded up (neither work) is in my first post. Where do you get the core from atmel??

Thanks for your help!

If the problem is that the frequency is wrong, it's probably a clock fuse problem. If your board is set to attiny85 8mhz internal, you need to burn the bootloader which just sets the fuses. Otherwise set your board to attiny85 1mhz internal.