Go Down

Topic: ATTiny85 tone() core? (Read 4365 times) previous topic - next topic

strykeroz


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
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Coding Badly

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.

strykeroz


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.
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Dr_Ugi


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

Dr_Ugi


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

Coding Badly


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

Dr_Ugi

Thank you - that's extremely helpful.

strykeroz


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
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Coding Badly

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.

strykeroz

That clears it up perfectly - thanks !

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

Go Up