Pages: [1]   Go Down
Author Topic: Help with ATTINY85 clock and PWM  (Read 1033 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,  I am trying to recreate the sketch from this thread: http://arduino.cc/forum/index.php?topic=74123.0  on the ATTiny85.

I am programming the 85 with arduino as ISP using the tiny cores found here: http://code.google.com/p/arduino-tiny/

I have had basic digital IO stuff working fine with these cores for some time now.


So I ported the sketch from the thread mentioned above, changing the registers to relevant ones on the 85.  I'm using pin0 as the output.  The problem I have is that I get a high pitched squeel very loud over the output.  I tried using timer1 instead on timer0 - same problem.  I have also tried an RC low-pass, doesn't reduce the squeel much.

Here is my sketch:

Code:
void setup() {
  TCCR0B = (TCCR0B & 0xf8) | 1;

  analogWrite(0,1);
  pinMode(0,OUTPUT);
}

void putb(byte b)
{
  static long m;
  long t;
  while((t=micros())-m < 250);
  m=t;
 
  OCR0A=b;

}

void loop() {
  long v;
  for(long t=0;;t++)putb(

   t*((t>>12|t>>8)&63&t>>4)   // by viznut
 
  );
 
}


Any ideas where I'm going wrong?  I'm sure this little chip is capable of making the exact same noises as the atmega328 in this way..

Thanks
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 30
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you taken into account potential timing differences cause by whatever clock source your using on the tiny85?
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

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

I have tried it at 1MHz, 8MHz and with an external 16MHz crystal.  Same problem at all speeds.  I have had problems getting ext 16MHz to work with the attiny core actually, and did think that must be the problem for a while, but if you run this sketch on an atmega at 8MHz, it still sounds ok..

Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 30
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think Coding Badly, the guy who created the attiny cores (at least the one I am using) said that he swapped the functionality of Timer 0 and Timer 1...  Not sure how that would effect the PWM.  Do you know which tiny core and version you are using?

P.S.  How do you know you were using the external crystal?  Did you test that?
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

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

Well, I'm pretty sure it didn't work actually... I selected the board ATtiny85 @ 16mHz with external crystal   and connected a 16mhz crystal with 2 22uF caps and it made no difference..  When I removed the crystal, nothing changed. 


As far as the timers go, I just don't see what more I need to do but use the appropriate timer for the pin and set the clock.... should hear something more than I do..
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 30
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I'm pretty sure it didn't work actually... I selected the board ATtiny85 @ 16mHz with external crystal   and connected a 16mhz crystal with 2 22uF caps and it made no difference..  When I removed the crystal, nothing changed. 


As far as the timers go, I just don't see what more I need to do but use the appropriate timer for the pin and set the clock.... should hear something more than I do..

Did you burn a new bootloader after you did that, but before you downloaded the sketch?
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

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

No I didn't... I was under the impression that the tiny doesn't use a bootloader in this case as it's programmed over SPI?
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 30
Posts: 887
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The tiny is programmed over ISP, but the burn bootloader process configures the fuses, which is nescessary to use different clock options.
Logged

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

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

ahhhhhhhh  ok, nice one.  I didn't know that.  I'll try that tonight.

I'm making a very basic simulator of the ATtiny85 in MaxMSP as a reference for all the timing related register settings.  It's a great way to get your head around the complexity of it.  If I ever finish it I'll post it up!

Cheers wanderson.
Logged

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

Ok so I burnt the bootloader for 16MHz internal, re-uploaded and I now have awesome noises.

One other thing that caught me out - I still had a cap between reset and gnd from the aduino as isp and it was causing the chip to reset everytime the cap discharged.

Thankyou for your help!!
Logged

Pages: [1]   Go Up
Jump to: