Go Down

Topic: ATtiny and tone() (Read 14795 times) previous topic - next topic

silly_cone

well glad I could be of assistance.  :-)

I'm glad there's a rational explanation; I was starting to feel l like I was going a little crazy.  :P

silly_cone

Alright, back to this again...

Anyone have any insight into why analogWrite would stop working on PB4 when tone() function is used in the sketch?

analogWrite still works on PB0 and PB1, but if I use the tone() command anywhere, even if its ended by a call to noTone(), analogWrite on PB4 is still dead.

Coding Badly


Which tone?  You have used at least three variations.


DrAzzy

Alright, back to this again...

Anyone have any insight into why analogWrite would stop working on PB4 when tone() function is used in the sketch?

analogWrite still works on PB0 and PB1, but if I use the tone() command anywhere, even if its ended by a call to noTone(), analogWrite on PB4 is still dead.
Which core is it? Is it my core?

If it's my core, please make an issue here: https://github.com/SpenceKonde/ATTinyCore/issues - my guess from the problem description is that it's an x5 series, but please confirm that. I also *love* code that reproduces problems, even really simple ones.
ATTinyCore and megaTinyCore for all ATtiny, DxCore for DA/DB-series! github.com/SpenceKonde
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

silly_cone

That's right, its an ATTiny85. 


This code results in proper output signal on PB4:

Code: [Select]
void setup() {
  pinMode(4, OUTPUT);
}

void loop() {

  //tone(2, 5000);
  delay(1);
  //noTone(2);
  delay(1);
 
  for (int i=150; i>85; i--){
    analogWrite(4, i);
  }
  delay(2000);
  digitalWrite(4, LOW);
  delay(2000);
}


This code results in nothing from PB4. but interestingly, it produces a ~25 ohm connection to ground that isn't present otherwise.

Code: [Select]
void setup() {
  pinMode(4, OUTPUT);
}

void loop() {

  tone(2, 5000);
  delay(1);
  noTone(2);
  delay(1);
 
  for (int i=150; i>85; i--){
    analogWrite(4, i);
  }
  delay(2000);
  digitalWrite(4, LOW);
  delay(2000);
}

silly_cone

And yes, I'm using your core.  

silly_cone

Update:  Fixed; I was able to get around the problem using the TimerFreeTone library.

DrAzzy

This is a bug in my core. noTone() does not properly restore the state of TCCR1* registers.
ATTinyCore and megaTinyCore for all ATtiny, DxCore for DA/DB-series! github.com/SpenceKonde
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

DrAzzy

Issue with calling tone() repeatedly with the same parameters in a tight loop fixed for ATTinyCore 1.2.0
ATTinyCore and megaTinyCore for all ATtiny, DxCore for DA/DB-series! github.com/SpenceKonde
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

hpschawla

check this webpage out = TinyTone() = http://www.technoblogy.com/show?KVO
It helped my finish my ATTiny85 project!

Go Up