Need help with IR Sensor

I’m trying to use an IR sensor similar to this one pololu.com/catalog/product/837 with an orangutan and pololu avr lib, but i don’t see a function to ouput a frequency, and i’m not sure if pwm would work. I was wondering if i’m missing something or is there a resource for a frequency out on an abitrary pin.

Hello,

We do not have a specific function for that in the library. Which Orangutan are you using? Your options for using PWM will depend on what PWM pins are available. To output an approximately 56 kHz signal to an arbitrary pin, you could use the delay_us function along with digital I/O functions in a loop. Do you know enough to implement that yourself, or do you need me to write an example?

I also wonder whether you could use the UART, configured for 56 kbaud, to send the signals - that would be an interesting way to effectively get an extra PWM out of your Orangutan!

-Paul

I’m using the sv-328 i definately want to save the uart, i was just hoping for an interrupt driven function i could just plug in. Looking through the docs on the sv-328 it doesn’t look like i have an extra pwm so i’ll just have to figure out how to use the interrupts.
Thanx.

On the SV-328, for PWM, I would try tapping into the buzzer output. You might hear a few clicks on the buzzer, but otherwise, as long as you don’t need to play music at the same time as you are sending IR, there should not be much of a conflict.

To do this with an interrupt would require it to be called at 112 kHz, or every 9 us. Unless you code it in assembly, there is a good chance your ISR will end up taking up all of your CPU anyway, so I really think that delays or the PWM output are the way to go.

-Paul

Hello.

I agree with Paul’s suggestion to try tapping into the buzzer. The following code generates a 56.2 kHz square wave on the buzzer pin:

TCCR1A = 0x23;  // set up timer 1 for phase-correct PWM output on OC1B
TCCR1B = 0x11;  // top = OCR1A, prescaler = 1 (20 MHz tick rate)
OCR1A = 178;  // TOP value for PWM (freq = 10 MHz / TOP)
OCR1B = 89;  // compare match (half of TOP for square wave)
DDRB |= 1 << PB2;  // make the buzzer pin an output

If you can handle not using the buzzer for sounds or music in your application, you can solder a wire from your sensor to the non-ground side of the buzzer and run the above code. The buzzer didn’t make any noise for me at 56 kHz when I tested it.

- Ben

Maybe I am missing something, but why are you wiring a 56kHz square wave signal to an IR sensor?

The sensor he linked to detects IR signals modulated at 56 kHz, so presumably he wants a way to PWM an IR LED at 56 kHz. It was poor wording on my part when I said above that he could connect the “sensor” to the buzzer pin since it’s really the transmitting LED that would get connected to that pin.

- Ben