ATTiny45 how do I apply 20Mhz crystal?

Hey,

I am gonna keep this short because I already wrote a topic but firefox decided to crash....

I'm using an ATTiny45 to send IR signals but they don't work.
My receiver doesnt receive ANYTHING from the attiny45.
The ATTiny45 also send the IRCodes way to slow, it takes about 2 second before the code is done sending.
So I think my ATTiny45 need to run at 20Mhz but how do I get it to 20Mhz?
I know I've to use a 20Mhz crystal, but what more and how do i apply it?

is this the right crystal:
http://www.ebay.com/itm/10pcs-20-000MHZ-20-MHZ-20M-HZ-DIP-Crystal-Oscillator-HC-49S-New-/360545402524#shId

(And I probably need to change F_CPU to 20 Mhz right?)

Thanks, Tim

The IR signal is a modulated signal. It's not just on/off, it has to transmit a square wave of around 36kHz.

The problem is in the software, it's not sending the correct signal.

1Mhz is plenty to transmit the IR signal and a Tiny45 can run at 16MHz with no crystal if you set the fuse bits correctly.

So it is the IRLibrary I use that doesnt work?
Do you maybe know one that (might) work?

-Tim

timboiscool:
So it is the IRLibrary I use that doesnt work?
Do you maybe know one that (might) work?

There might be a mismatch between your library and F_CPU.

fungus:

timboiscool:
So it is the IRLibrary I use that doesnt work?
Do you maybe know one that (might) work?

There might be a mismatch between your library and F_CPU.

Thanks for the help it does send signals now but it doesnt send the signal i defined
0xFFE817 , 68 length

Instead of that it send:
0xFFFFFF , 100 length

Could this also have something to do with the F_CPU or is this just a programming error in library?

-tim

timboiscool:
Could this also have something to do with the F_CPU

Yes.

eg. Your F_CPU might not match the chip’s clock speed.

timboiscool:
or is this just a programming error in library?

I assume other people are using the library so that’s the last thing to point your finger at.

How do you program the Attiny45 ? do you know that by default the fuses are set for "internal rc clock 8Mhz" and "Divide clock by 8" resulting in a clock speed of only 1MHz ?

saposoft:
How do you program the Attiny45 ? do you know that by default the fuses are set for “internal rc clock 8Mhz” and “Divide clock by 8” resulting in a clock speed of only 1MHz ?

Well I’ve arleady tried to change that but now one of my ATtiny45 is not responding anymore.
But what I did try was to select in boards the ATTiny45 (Internal 8Mhz) and then burn the bootloader. Which did definatly change something.
But how do I remove the divide clock by 8? (I’ll also search google :stuck_out_tongue: )

-tim

timboiscool:
But what I did try was to select in boards the ATTiny45 (Internal 8Mhz) and then burn the bootloader. Which did definatly change something.
But how do I remove the divide clock by 8? (I’ll also search google :stuck_out_tongue: )

You already did, that’s why it’s running at 8MHz, not 1MHz.

PS: Try reading the datasheet. That’s what it’s for.

I’m sorry for keeping posting but it still isn’t working.
This is exactly what I do:

I got the ATTinyTX library installed and the correct ATTiny boards for the arduino IDE.

  1. I setup my arduino to program my attiny45 and then upload the ArduinoISP to my arduino uno. ( I did change delay(40) to delay(20) )
  2. I choose from boards: ATTiny45 (Internal 8MhZ) and click burn bootloader.
  3. I write my sketch and include the ATTinyTX library to it.
  4. I upload the sketch to the ATTiny45.
  5. I test my sketch.

Problem:
My ATTiny45 does send IR Signals but not the right one, It sends five signals with this as data: 4294967295 with length: 100.

This is my sketch:

#include <IRTinyTX.h>

#define F_CPU 8000000 //<--I also tested it without this.
IRsend irs;
int btn_pin = 0;
boolean lastState;
long hexs[] = { 0xE1A2E817, -234209089, -509417449, -1045820938, 16730295 };
long hexlen[] = { 68, 68, 68, 68, 68 };

void setup(){
  pinMode(btn_pin, INPUT);
}

void loop(){
  if(digitalRead(btn_pin) == HIGH && lastState != HIGH)
  {
    for(int i=0;i<5;i = i + 1)
    {
      irs.sendNEC(hexs[i], hexlen[i]);
    }
  }

  lastState = digitalRead(btn_pin);
  delay(250);
}

Thanks, -Tim

Snippet from boards.txt:

attiny45-8.name=ATtiny45 (internal 8 MHz clock)
attiny45-8.bootloader.low_fuses=0xe2
attiny45-8.bootloader.high_fuses=0xdf
attiny45-8.bootloader.extended_fuses=0xff
attiny45-8.upload.maximum_size=4096
attiny45-8.build.mcu=attiny45
attiny45-8.build.f_cpu=8000000L
attiny45-8.build.core=arduino:arduino
attiny45-8.build.variant=tiny8

This thread can be closed.
I'll make a new one because the title doesnt fit the situation anymore.

-Tim.