DrAzzy:
^ is bitwise xor - it requires two operands.~ is bitwise not, which is I think what was meant.
I would use the timer in PWM mode, and turn on and off the output compare to get the data out, rather than using interrupts and CTC mode.
I have re-written my code somewhat and think I have a working prototype...
void setupIRLed() {
// TOCC7 i.e. PB2 will run on the OC1A output...
TOCPMSA1 = 0;
TOCPMSA0 = 0;
TOCPMSA1 |= (1 << TOCC7S0); // TOCC7S[1:0] = 01 = OC1A on PB2.
//FAST 8-bit PWM: WGM[13:10] = 0101 (mode 5) 13=0 WGM12=1 WGM11=0 WGM10=1
TCCR1C = 0;
TCCR1A = 0;
TCCR1A |= (1 << WGM10) | (1 << COM1A1); // Clear on compare. Set on Bottom.
TCCR1B = 0;
TCCR1B |= (1 << WGM12) | (1 << CS10); // No pre-scale...so 8MHz per tick.
TIMSK1 |= (1 << OCIE1A);
/* In 8-but FAST PWM mode, the OCR1A port is set (goes high) at BOTTOM (0).
* When it then reaches OCR1A, the bit is cleared.
* The timer continues to TOP (ICR1) value.
*
* As pin goes high at 0 for 105 counts, then low for 105 (till 210)...
* that is a period of 210 counts.
* 8MHz / 210 =~ 38KHz
*/
OCR1A = 105;
ICR1 = 210;
// Set timer to 0 to avoid the "miss".
TCNT1 = 0;
}
I am then using the following code to "turn on and off" the modulated PWM pin...
#define iron TOCPMCOE |= (1 << TOCC7OE) // Enable the output on TOCC7 (PB2).
#define iroff TOCPMCOE =0
Is this a reasonable approach?
I am unsure if the LED is under-powered or there is an issue with my code mind...
I can see it in my phone camera but it seems to have to get pretty close to a TSOP receiver to trigger it.
The schematic is here, I have used a 220 ohm on the transistor base and a 15ohm on the LED mind.
