Search code examples
assemblyavravr-gcc

How to make a ir send 38 Khz carrier avr attiny2313v


I’ve got an old universal TV ir remote control (brand: 2D MAGIC UNICODE) bought in 2008 year with an avr atmel attiny 2313v inside and a 55 matrix key buttons. The clock is external with a xtal 4Mhz quartz. It was programmed with RC5 protocol and now I want to change in samsung 32 bit protocol rewriting all the code. I’ve mapped all the pcb matrix with a multimeter to find the pins and the IR transmitter led is connected to the PD0 pin,that isn't dedicated to waveform generation output. My idea is to coding with 16-bit Timer/Counter1 in CTC mode and interrupt method to obtain the 38 Khz pwm frequency carrier ir send (prescaler is 1) but, also reading the datasheet, I don’t understand if to send the codes on carrier I can choose an arbitrary pin (and so the PD0 pin goes well) or only OC1A and OC1B are dedicated to do this. I’ve made the programmer with a ftdi232rl usb soldering the wires to dedicated pins and using avrdude. Thanks advance.

Can I use delay function to make the carrier?


Solution

  • I think both ways are possible. If you use Timer1 in CTC mode with an interrupt, any pin can be changed in the interrupt handler. The best way to change the value of a pin is to write a 1 to the appropriate bit in the PINx register. In your case of pin PD0 it will be PIND |=1;

    OC1A and OC1B must be used only if the generation of the output waveform will be purely by hardware.

    The second way using the _delay_us() function is also possible. There is no need to do anything else during the IR code has been transmitted, so blocking the CPU in the delay function is not a problem. Here it will be possible to make small corrections that will correct the time spent in the code that generates the bit form of the sent IR command.