I'm making optical barrier using
TSOP34836 and IR led. At the moment, I'm using attiny 25(/45/85) to generate 36kHz pulses and light an IR LED (I'll paste code below). At the moment LED is on for 50% time and off for another 50%.
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED PORTB1 //connect LED to this pin PB1=DIP pin 5
void setup(void) {
CLKPR = 0x80; //set the Clock Prescaler Change Enable bit
CLKPR = 0x00; //set the Clock Prescaler to divide by one (8Mhz assuming factory default fuses)
DDRB |= _BV(LED); //set the LED pin as an output
setupTimer1(); //set timer1 up to call myISR every 10ms
}
void loop(void) {
}
void setupTimer1() {
TCCR1 = _BV(CTC1); //clear timer1 when it matches the value in OCR1C
TIMSK |= _BV(OCIE1A); //enable interrupt when OCR1A matches the timer value
sei(); //enable global interrupts
OCR1A = 221; //set the match value for interrupt
OCR1C = 221; //and the same match value to clear the timer
PLLCSR &= ~(1<<2); // Setup synchronous clock
TCCR1 |= _BV(CS10); //set prescaler to divide by 1024 (this starts the timer). Use excel to count value
}
ISR(TIMER1_COMPA_vect) { //handles the Timer1 Compare Match A interrupt
PINB |= _BV(LED);
}
It works OK, but my power regulator
L7805 is getting very hot even using 5mm 1.2V 0.1A Led (I've connected it via TIP122 transistor with 33 Ohm resistor). And want to connect 1W IR star LED, which will require even more power.
Now I think is it possible to reduce duty cycle? I've tried some code (pasted above), but it works very unstable. LED showing that signal is received, blinks for very short periods, etc. I can't understand is it some problem with my code (maybe I generate not exactly 36kHz...?) or TSOP34836 is just not intended to receive such signal?
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED PORTB1 //connect LED to this pin PB1=DIP pin 5
void setup(void) {
CLKPR = 0x80; //set the Clock Prescaler Change Enable bit
CLKPR = 0x00; //set the Clock Prescaler to divide by one (8Mhz assuming factory default fuses)
DDRB |= _BV(LED); //set the LED pin as an output
PORTB = 0; // turn off led
setupTimer1(); //set timer1 up to call myISR every 10ms
}
void loop(void) {
}
void setupTimer1() {
TCCR1 = _BV(CTC1); //clear timer1 when it matches the value in OCR1C
TIMSK |= _BV(OCIE1A); //enable interrupt when OCR1A matches the timer value
sei(); //enable global interrupts
OCR1A = 180; //set the match value for interrupt
OCR1C = 180; //and the same match value to clear the timer
// Setup synchronous clock
PLLCSR &= ~(1<<2);
//---
TCCR1 |= _BV(CS11); //set prescaler to divide by xxxx (this starts the timer). Use excel to count value
}
ISR(TIMER1_COMPA_vect) { //handles the Timer1 Compare Match A interrupt
if(PINB){
OCR1A = 180;
OCR1C = 180;
PORTB = 0;
}else{
OCR1A = 41;
OCR1C = 41;
PORTB = _BV(LED);
}
}
Or maybe its normal that L7805 is getting very hot and I just have to leave it as is?
PS. In attachment there as excel document to count the value of timer and prescaler.