Can you modulate the PWM output pin? e.g. IR blaster LED.

Some microcontrollers have a gated PWM output, others you can disable or tristate the PWM output pin.
example, you set the PWM module (carrier) for 38kHz and toggle out the output pin for the data (control pulses).
Are any of these features available on the ATmega328P?

Why not do 38kHz “bursts” from an output pin?


I have an example here:

Scroll down to "Modulating a 38 KHz carrier with a 500 Hz signal".

Thank you. So it still requires two GPIO pins? Are you generating the 38kHz signal with PWM (timer 1) and the 500 Hz with Timer 2?

generates a 38 KHz signal and then turns that carrier on and off with a 500 Hz signal (generated by Timer 2) with a variable duty cycle controlled by a potentiometer. The 500 Hz duty cycle is output on pin 3 which causes a pin change interrupt which is used to turn pin 9 on and off.

I used the second pin to generate the interrupt because I was trying to capture the PWM duty cycle. If you didn't care about that (or if a bit of imprecision didn't matter to you) you could generate an interrupt (without using a pin) and do the calculations in the ISR. In other words, only commit a single output pin to it. I was also trying to make it simple. As you can see from the code, there is only one line that is not inside an ISR (apart from setup).