Go Down

Topic: Attiny85 tone issue (Read 13296 times) previous topic - next topic

DoctorOctoroc


I'm trying to use PIN 0 and PIN1 as PWM outputs to drive an LED, as well as use the TONE function to output a frequency on pin 3. PWM does not appear to be working though. The sketch works fine (with changed pins) on a DCBoArduino. Is this an issue of expecting too much from the timer in such a small chip or am I not doing something right in my code?

I'm just learning this stuff myself, but if I'm not mistaken, the ATtiny45 and 85 only support PWN on pin 0 and 1. Try switching one of the PINs with an LED with the piezo/speaker output PIN. The LED's should work on other output pins. Again, don't quote me on that, just recalling some information I stumbled upon during my own research of the MC.

On a side note, I managed to work out all the kinks in my issue. As per CodingBadly's suggestion, I simply cut down the amount of data being sent to the ATtiny85 (in half to be exact). Now I just have to re-code the sound with less data, but it did successfully write to the MC so that's a start!

Lazy Glen

I think the problem was in the chair, not the computer.

I played with some other code and found that the color mixing works differently than I thought. My project is working now. I just wish I could get an 8 pin processor that did 3 PWM channels.

The TONE output is a simple square wave rather than a PWM signal. But now that I think of it, that's really all the the PWM signal is right?

LazyGlen

Coding Badly

I just wish I could get an 8 pin processor that did 3 PWM channels.


And generate a tone?

Quote
The TONE output is a simple square wave rather than a PWM signal. But now that I think of it, that's really all the the PWM signal is right?


Sort of.  PWM is a fixed frequency with a varying high (or low) time.  Tone is a varying frequency with a fixed high (and low) time.

Lazy Glen

Quote

And generate a tone?


Yes. I'd like to be able to use 3 PWM pins to control a single RGB LED, while using a 4th pin to generate a constant frequency, I've been using tone since it is simple.

In one of the other threads there was some talk of the ATTINY85 being able to do PWM on pin PB3, but you appear to firmly discount this. Since I think I'm using your core, I'm inclined to take your word for it. :)
http://arduino.cc/forum/index.php/topic,82951.15.html

Coding Badly

Yes. I'd like to be able to use 3 PWM pins to control a single RGB LED, while using a 4th pin to generate a constant frequency, I've been using tone since it is simple.


As far as I know, there just aren't enough timers / PWM outputs available in 8 pin packages.

However, depending on what else the processor is doing, you may get good results with "soft PWM".


Quote
In one of the other threads there was some talk of the ATTINY85 being able to do PWM on pin PB3, but you appear to firmly discount this


@karl_b is correct that PWM is available on PB3.  What he fails to mention is that it is the inverted output of PB4.  In other words, when PB3 is at 10%, PB4 is at 90%.  While very useful for motor control it won't help you.  (unless you just happen to want one LED dimmer as another is brighter)

smeezekitty

Implementing tone in software should be pretty trivial.
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Coding Badly


It is.  But, in my experience, the quality is not very good.  Any interrupt (like the timer 0 /millis interrupt) causes ticks and pops.  The problem gets especially bad when the processor is running at 1 MHz.

smeezekitty



It is.  But, in my experience, the quality is not very good.  Any interrupt (like the timer 0 /millis interrupt) causes ticks and pops.  The problem gets especially bad when the processor is running at 1 MHz.


The quality required depends on what the OP needs.
It is probably also possible to tie into the timer interrupt to generate it in software if it is fast enough.
In any case, I am sure part of it will need to be done in software because the limited amount of timers in the Attiny series.
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Maya

I was using the old library and had limited functionalities with tone().  I upgraded to this very new one here:  http://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0017.zip  but nothing has changed.   I edited the boards file and selected the right isp.    According to the readme file, there should be a programmers.txt file in the package, but it seems to be missing.

Has anyone successfully used this library before?

Thanks,
Maya

Erni

Quote
Has anyone successfully used this library before?


Oh yes

Quote
but nothing has changed


What exacly are you trying to do ?

Maya

Thanks it worked.  The problem was mismanaging the boards.txt file *bad formatting* and other library conflict.    Now tone() works with attiny84 at 8Mhz!   Thanks.

mastrand9

Quick thanks! To Coding Badly for the ATtiny core resource, plus info available here and elsewhere.
I'm a n00b with arduino, having punted picaxe projects for various reasons.

Now working with an adafruit Trinket ATtiny85 at 8MHz. Great device for my current project. Needed tone output and surfed to this thread. Instead of the aforementioned Arduino-Tiny install, i kept the adafruit USB bootloader and pointed to the Tiny core in boards.txt, placing the new core folder within associated sketch directory.

Trinket and tone working great.

Coding Badly


You (and @Maya) are welcome.  I'm glad it works for you.

mastrand9

Yes it's been a year, but my earlier success using Coding Badly's excellent core was short-lived.

I'm back working on project with Adafruit Trinket and tone(), using the same sketch that worked well last summer... but I've moved all of my work from a WinXp laptop to a new mac mini. The move necessitated a fresh instance of arduino, and I have used the Adafruit version in order to simplify setup for the ATtiny85 used on the 3v and 5v Trinkets I'm working with. The basic install works ok (3v Trinket is "Blink"ing at me now), but I cannot get tone() operational using the old sketch (same output pin, etc.)

I have followed the tiny core install instructions... what am I missing?

Coding Badly

Quote
...I cannot get tone() operational...


In order for me to be able to help I will need more explanation than "cannot get it operational".  For example, what sound output device are you using?  You have it connected to which pin?  Which board do you have selected?

Go Up