Pages: 1 2 [3]   Go Down
Author Topic: ATTiny85 tone() core?  (Read 3109 times)
0 Members and 1 Guest are viewing this topic.
Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1120
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't understand how tone works on PB3 if PWM doesn't, but maybe that's a cunning interrupt-based version.
That's right Ugi, tone() doesn't utilise hardware PWM so it can be used on your other pins.

Cheers, Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

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

That's right Ugi, tone() doesn't utilise hardware PWM so it can be used on your other pins.

The version in Tiny Core sort of does.  If the tone pin is an output pin for the tone timer, direct hardware output is used.  Otherwise, an interrupt service routine is used.  You get the best of both worlds.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1120
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the tone pin is an output pin for the tone timer, direct hardware output is used.  Otherwise, an interrupt service routine is used.  You get the best of both worlds.
Thanks for the clarification, and that's a nice detail touch too.
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

London
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Ugi was not declared in this scope
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's right Ugi, tone() doesn't utilise hardware PWM so it can be used on your other pins.

The version in Tiny Core sort of does.  If the tone pin is an output pin for the tone timer, direct hardware output is used.  Otherwise, an interrupt service routine is used.  You get the best of both worlds.

That's the class way to do it!

Thanks all.

Ugi
Logged

London
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Ugi was not declared in this scope
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The version in Tiny Core sort of does.  If the tone pin is an output pin for the tone timer, direct hardware output is used.  Otherwise, an interrupt service routine is used.  You get the best of both worlds.
Come to think of it, which pins are the hardware outputs for for the tone timer?  While I'm switching pins around, I may as well use hardware PWM for this if I can, 'cos there's plenty to do under SW already & I don't really want to go up to 8MHz if I can avoid it.

Thanks

Ugi
Logged

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


By default, for the ATtiny85 processor, timer 1 is used for millis.  Timer 0 is used for everything else (tone).  That can be reversed with a compile-time switch.

Open the datasheet...
http://www.atmel.com/devices/attiny85.aspx?tab=documents

Navigate to the 1. Pin Configurations section.  Pins marked with OC (oh-see) are Output Compare (PWM) pins.  The number after OC is the timer.  The letter after is the channel.

Find all pins marked with OC0 (oh-see-zero): PB1 and PB0.  PB1 and PB0 are potentially "tone output pins".

The problem with PB1 (OC0B) is that it overlaps with an output from the other timer (OC1A).  Which output is used is determined by another compile-time switch.  By default, "phase correct PWM" is favored so OC0B is used.

So, by default, PB1 and PB0 are the "tone output pins".
Logged

London
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Ugi was not declared in this scope
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you - that's extremely helpful.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1120
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you - that's extremely helpful.
It sure is.  Thankyou.

Can you just clear up for me the role of PB3 with PWM?  It's marked as OC1B with a line over it, in the same way that PB0 is OC1A with a line above it.  Is it that the hardware is capable but we can't drive it with hardware PWM using the Arduino core resulting in what we saw in earlier tests when we tried to analogWrite to it?

Thanks, Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

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

Can you just clear up for me the role of PB3 with PWM?  It's marked as OC1B with a line over it, in the same way that PB0 is OC1A with a line above it.

The line over means "inverted".  I have no idea when an inverted output would be used or how exactly it works.

From a practical perspective, it means "not Arduino compatbile".

Quote
Is it that the hardware is capable but we can't drive it with hardware PWM using the Arduino core resulting in what we saw in earlier tests when we tried to analogWrite to it?

I'm not certain about "earlier tests" but the Tiny Core does not make any use of inverted output pins.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1120
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That clears it up perfectly - thanks !

Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

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