Pages: 1 2 3 [4]   Go Down
Author Topic: Attiny85 tone issue  (Read 9139 times)
0 Members and 1 Guest are viewing this topic.
Philadelphia
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

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

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

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. smiley
http://arduino.cc/forum/index.php/topic,82951.15.html
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Washington
Offline Offline
God Member
*****
Karma: 30
Posts: 779
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Implementing tone in software should be pretty trivial.
Logged

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!

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Washington
Offline Offline
God Member
*****
Karma: 30
Posts: 779
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

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!

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

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
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1029
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Has anyone successfully used this library before?

Oh yes

Quote
but nothing has changed

What exacly are you trying to do ?
Logged

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

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
Old dog, new tricks. Oregon USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Pages: 1 2 3 [4]   Go Up
Jump to: