Go Down

Topic: Can you modulate the PWM output pin? e.g. IR blaster LED. (Read 1 time) previous topic - next topic

BlueBill

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?
Bill

Runaway Pancake

#1
Nov 14, 2012, 04:04 am Last Edit: Nov 14, 2012, 04:05 am by Runaway Pancake Reason: 1
Why not do 38kHz "bursts" from an output pin?

<><>  http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Nick Gammon

I have an example here:

http://www.gammon.com.au/forum/?id=11504


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

BlueBill

#3
Nov 14, 2012, 04:37 am Last Edit: Nov 14, 2012, 04:39 am by BlueBill Reason: 1
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?
Quote
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.
Bill

Nick Gammon

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).

Go Up