Setup Pin to Send InfraRed Signal

Custom built or hacked Electronic boards and sensors
1 postPage 1 of 1
1 postPage 1 of 1

Setup Pin to Send InfraRed Signal

Post by ericsonduarte » Fri Oct 26, 2012 12:24 pm

Post by ericsonduarte
Fri Oct 26, 2012 12:24 pm

By default, for arduino duemilanove we have:
Pins 5 and 6: controlled by timer0
Pins 9 and 10: controlled by timer1
Pins 11 and 3: controlled by timer2

#define IR_USE_TIMER1 // tx = pin 9
// defines for timer1 (8 bits)
#if defined(IR_USE_TIMER1)
#define TIMER_ENABLE_PWM (TCCR1A |= _BV(COM1A1))
#define TIMER_DISABLE_PWM (TCCR1A &= ~(_BV(COM1A1)))
#define TIMER_ENABLE_INTR (TIMSK1 = _BV(OCIE1A))
#define TIMER_DISABLE_INTR (TIMSK1 = 0)
#define TIMER_INTR_NAME TIMER1_COMPA_vect
#define TIMER_CONFIG_KHZ(val) ({ \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR1A = _BV(WGM11); \
TCCR1B = _BV(WGM13) | _BV(CS10); \
ICR1 = pwmval; \
OCR1A = pwmval / 3; \
})
#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
#define TIMER_PWM_PIN 9 //Arduino Duemilanove, Diecimila, LilyPad, etc
#endif


#define IR_USE_TIMER1 // tx = pin 9
#if defined(IR_USE_TIMER2)
#define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1))
#define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1)))
#define TIMER_ENABLE_INTR (TIMSK2 = _BV(OCIE2A))
#define TIMER_DISABLE_INTR (TIMSK2 = 0)
#define TIMER_INTR_NAME TIMER2_COMPA_vect
#define TIMER_CONFIG_KHZ(val) ({ \
const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR2A = _BV(WGM20); \
TCCR2B = _BV(WGM22) | _BV(CS20); \
OCR2A = pwmval; \
OCR2B = pwmval / 3; \
})
#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
#define TIMER_PWM_PIN 3 //Arduino Duemilanove, Diecimila, LilyPad, etc
#endif

How to setup timer 0, for use pin 5 and 6? How to setup timer1 to use pin 10 and timer2 to use pin 11
?

Best Regards
By default, for arduino duemilanove we have:
Pins 5 and 6: controlled by timer0
Pins 9 and 10: controlled by timer1
Pins 11 and 3: controlled by timer2

#define IR_USE_TIMER1 // tx = pin 9
// defines for timer1 (8 bits)
#if defined(IR_USE_TIMER1)
#define TIMER_ENABLE_PWM (TCCR1A |= _BV(COM1A1))
#define TIMER_DISABLE_PWM (TCCR1A &= ~(_BV(COM1A1)))
#define TIMER_ENABLE_INTR (TIMSK1 = _BV(OCIE1A))
#define TIMER_DISABLE_INTR (TIMSK1 = 0)
#define TIMER_INTR_NAME TIMER1_COMPA_vect
#define TIMER_CONFIG_KHZ(val) ({ \
const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR1A = _BV(WGM11); \
TCCR1B = _BV(WGM13) | _BV(CS10); \
ICR1 = pwmval; \
OCR1A = pwmval / 3; \
})
#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
#define TIMER_PWM_PIN 9 //Arduino Duemilanove, Diecimila, LilyPad, etc
#endif


#define IR_USE_TIMER1 // tx = pin 9
#if defined(IR_USE_TIMER2)
#define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1))
#define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1)))
#define TIMER_ENABLE_INTR (TIMSK2 = _BV(OCIE2A))
#define TIMER_DISABLE_INTR (TIMSK2 = 0)
#define TIMER_INTR_NAME TIMER2_COMPA_vect
#define TIMER_CONFIG_KHZ(val) ({ \
const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR2A = _BV(WGM20); \
TCCR2B = _BV(WGM22) | _BV(CS20); \
OCR2A = pwmval; \
OCR2B = pwmval / 3; \
})
#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
#define TIMER_PWM_PIN 3 //Arduino Duemilanove, Diecimila, LilyPad, etc
#endif

How to setup timer 0, for use pin 5 and 6? How to setup timer1 to use pin 10 and timer2 to use pin 11
?

Best Regards
ericsonduarte offline
Newbie
Newbie
Posts: 1
Joined: Fri Oct 26, 2012 12:14 pm

1 postPage 1 of 1
1 postPage 1 of 1