Pages: [1]   Go Down
Author Topic: Can you modulate the PWM output pin? e.g. IR blaster LED.  (Read 665 times)
0 Members and 1 Guest are viewing this topic.
Toronto, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Bill

Offline Offline
Edison Member
*
Karma: 56
Posts: 2186
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not do 38kHz "bursts" from an output pin?

<><>  http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
« Last Edit: November 13, 2012, 10:05:42 pm by Runaway Pancake » Logged

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged

Toronto, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 13, 2012, 10:39:07 pm by BlueBill » Logged

Bill

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: