Go Down

Topic: IR transmissions. (Read 1 time) previous topic - next topic

CaptainTuna

Hello guys.

I am trying to have two atmega328p chips communicate to each other via IR. I used to do this with my picaxe chips some time ago but i noticed that with arduino things look a little more complex.

Got two "problems":

1) The frequency. I need to get my IR light modulated at 38KHz but i've read in the reference that with analog.write command the frequency is fixed and it's much lower. Is there a way i can do that with the arduino or do i have to buy an external chip?

2) Serial communcation. I've attached a led (the IR transmission LED) to the TX pin and i noticed it lights up when i write serial.begin in void setup(). I'd like to keep the LED off when not in use.
Is there a way i can avoid having the led on at all times? I want my project to send a signal when the user presses a button. Should i use the serial.begin ONLY when the user presses that button (instead of putting it in the setup void function) and have it disabled with serial.end when the button is released? I just hope the serial.begin command doesn't take too much time to set itself because i'd like the signal to be sent exactly when the user presses the button.

Thank you!

Groove

Quote
I need to get my IR light modulated at 38KHz

38kHz is a period of a shade over 26us.
As long as you don't do it for too long and don't want to do anything else at the same time, then some "delayMicroseconds" between you "digitalWrite"s will sort you out.
You'll have to experiment to get the delay just right.
Per Arduino ad Astra

CaptainTuna

actually i do want to do something else at the same time. To transmit data i also need to send the serial data to the LED while i also modulate it with the PWM.

Groove

OK, you'll need a 555 then.
Per Arduino ad Astra

Grumpy_Mike

#4
Feb 11, 2010, 03:05 pm Last Edit: Feb 11, 2010, 03:09 pm by Grumpy_Mike Reason: 1
Quote
i also modulate it with the PWM.


With all modulation, the information you modulate has to be at a much lower frequency than the carrier or modulation frequency.
The simplest way to modulate an IR LED is to change the PWM frequency to 38KHz and write a 50% value to it.

However, to modulate PWM on this you need to work out what frequency of PWM you want. Most modulated IR receivers will only operate a a certain baud rate so you need to look this up and see if it is compatible with what you want. You can then bit bang the PWM by writing alternately 0% and 50% to the modulation either from a timing loop or from an interrupt service routine.

Edit.
If you use a 555 to provide the modulation you still might have to modify the basic PWM frequency, I believe it defaults to 400Hz and that might be too fast for your receiver.

CaptainTuna

#5
Feb 11, 2010, 03:17 pm Last Edit: Feb 11, 2010, 03:17 pm by CaptainTuna Reason: 1
Maybe i found a simpler way to do this:
http://www.arduino.cc/playground/Code/Timer1

it gives you the command pwm(pin, duty, period) so i guess it would work great for me. Just one thing: if i set the duty to 50% the period is 26us right (as Groove said)?

I also checked out this page http://www.arduino.cc/playground/Main/TimerPWMCheatsheet which talks about editing some timer values and at one point it says:

Quote
If you change TCCR0B, it affects millis() and delay(). They will count time faster or slower than normal if you change the TCCR0B settings. Below is the adjustment factor to maintain consistent behavior of these functions:
so i guess this means that if i use the previous library, which uses timer 1, i shouldn't have problems with it.

Grumpy_Mike

Quote
Just one thing: if i set the duty to 50% the period is 26us right (as Groove said)?


The period is independent of the duty cycle. So any percent will give you the same period.

Quote
so i guess this means that if i use the previous library, which uses timer 1, i shouldn't have problems with it.

I don't know as I haven't used that library, it depends on how they implement it. Simply changing the timer prescaler  will give you problems but if it is done in another way it could not.
I would check that they still give the right delay after you change it.

CaptainTuna

Yeah sorry about the period question i was a little confused! Thanks for the answers.

Go Up