Using timers to generate 38KHZ - for IR
Prerequisites:Tiny core: https://code.google.com/p/arduino-tiny/
The core is moved to github, and there is a core for both IDE 1.0.x and 1.x.x
https://github.com/Coding-Badly/
Attiny84
// Using timer1 in CTC mode // 38 khz on PA5, running @ 8MHZ // ATMEL ATTINY84 / ARDUINO // // +-\/-+ // VCC 1| |14 GND // (D 0) PB0 2| |13 AREF (D 10) // (D 1) PB1 3| |12 PA1 (D 9) // PB3 4| |11 PA2 (D 8) // PWM INT0 (D 2) PB2 5| |10 PA3 (D 7) // PWM (D 3) PA7 6| |9 PA4 (D 6) // PWM (D 4) PA6 7| |8 PA5 (D 5) PWM void setup(){ OSCCAL = 0x9F; pinMode(5,OUTPUT); noInterrupts(); TCNT1 = 0; TCCR1A=0; TCCR1B=0; TCCR1B |=(1<<WGM12); //Start timer 1 in CTC mode Table 14.4 TCCR1A |=(1<<COM1B0); //Timer1 in toggle mode Table 14-1 TCCR1B |=(1<<CS10) ; //prescaler Table 14-5 interrupts(); OCR1A=104; //CTC Compare value } void loop(){ }
Attiny85
//Attiny85 , running @ 8MHZ // Using timer 0 // // +-\/-+ // Ain0 (D 5) PB5 1| |8 VCC // Ain3 (D 3) PB3 2| |7 PB2 (D 2) INT0 Ain1 // Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 // GND 4| |5 PB0 (D 0) pwm0 // +----+ void setup(){ DDRB |= (1<<PB0); //Set pin PB0 as output TCNT0 = 0; TCCR0A=0; TCCR0B=0; TCCR0A |=(1<<COM0A0); //Timer0 in toggle mode Table 11-2 TCCR0A |=(1<<WGM01); //Start timer 1 in CTC mode Table 11.5 TCCR0B |= (1 << CS00);// Prescaler table 11.6 OCR0A=104; //CTC Compare value } void loop(){ }
//Attiny85 , running @ 8MHZ //using timer 1 void setup() { pinMode(1, OUTPUT); TCNT1 = 0; TCCR1 = 0; GTCCR |= (1 << PSR1); //section 13.3.2 reset the prescaler TCCR1 |= (1 << CTC1); // section 12.3.1 CTC mode TCCR1 |= (1 << COM1A0); //togle pin PB1 table 12-4 TCCR1 |= (1 << CS10); //prescaler 1 table 12-5 OCR1C = 104; OCR1A = 104; } void loop() { }