IR Beacon
February 15, 2010 3 Comments
This is a stand-alone IR Beacon useful for your robot to find its way around.
It can be configured to emit a different byte, so that you can have several of them meaning different points for the robot.
The following source code (programmed using AVR Studio) would make it send a consecutive byte every half a second, but you obviously can configure it to send the same byte every time, with whatever frequency you want.
/* The IR signal uses pulse distance encoding. * Each pulse (1T) is 21 cycles of a 38KHz carrier burst (about 560µs long). * A logic "1" is a 1T pulse followed by a 3T space and takes 2.25ms to transmit. * A logic "0" is a 1T pulse followed by a 1T space and takes 1.125ms. * * The AGC burst consists of a 4.5ms burst followed by 4.5ms space (8T pulse + 8T space). * * * Example output: * _____ _____ _____ * +-----Start-----+---------Byte1---------+---------Byte1---------+----------Byte2----------+--------Byte2--------+-------Byte3-------+-----------Byte3-----------+---Stop---+ * | | LSB MSB | LSB MSB | LSB MSB | LSB MSB | LSB MSB | LSB MSB | | * | | |_ _ _ _ _ _ _ _ | | _ _ _ _ _ _ _ _| | _ _ _ _ _ _ _ _ | | * | AGC Space | 1 0 1 1 0 0 1 0|1 0 1 1 0 0 1 0 |0 0 0 1 1 1 1 1 | 0 0 0 1 1 1 1 1|0 1 0 0 1 0 0 0| 0 1 0 0 1 0 0 0 |0 Space | * +------+--------+---+-+---+---+-+-+---+-+-+---+-+-+---+---+-+---+-+-+-+---+---+---+---+---+---+---+---+-+-+-+-+-+-+---+-+-+---+-+-+-+---+-+---+---+-+---+---+---+-+--------+ * * ######## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # * ___########________#___#_#___#___#_#_#___#_#_#___#_#_#___#___#_#___#_#_#_#___#___#___#___#___#___#___#___#_#_#_#_#_#_#___#_#_#___#_#_#_#___#_#___#___#_#___#___#___#_____________ * */ #include <avr/io.h> #include <util/delay.h> #define IR_BIT 3 #define LED_BIT 4 #define PORT PORTB // Infrared signal parameters #define CARRIER_FREQ 38000 // IR carrier frequency #define CYCLES_PER_PULSE 21 // width of 1T IR carrier pulse #define US_PER_SECOND 1e6 // microseconds per second for freq. period conversion // Carrier frequency adjustment. Will need to be adjusted depending on // actual uC/temperature/voltage/clock settings. #define CARRIER_ADJ -0.8 // in microseconds to adjust 38KHz signal period. const long DELAY = (US_PER_SECOND / (CARRIER_FREQ * 2)) + CARRIER_ADJ; void on(){ PORT = PORT | (1 << IR_BIT) | (1 << LED_BIT); } void off(){ PORT = 0; } /* * Generate a 1T carrier frequency IR pulse * * Parameters: state is output level of IR pulse: HIGH or LOW */ void onePulse( uint8_t state){ for( uint8_t i = 0; i < CYCLES_PER_PULSE; i++){ // 50% duty cycle carrier if(state) on(); _delay_us(DELAY); off(); _delay_us(DELAY); } } /* * Encode a single data byte into IR pulses * * Parameters: byte is the data to encode */ void sendByte( uint8_t byte) { //START for( uint8_t i = 0; i < 8; i++) onePulse(1); for( uint8_t i = 0; i < 8; i++) onePulse(0); // BYTE data for( uint8_t i = 0; i < 8; i++) { // "1" = 1T on + 3T off; "0" = 1T on + 1T off onePulse(1); for( uint8_t i = 0; i < ((byte & 0x01) ? 3 : 1); i++) onePulse(0); byte >>= 1; // get the next most significant bit } // END onePulse(1); } int main(void){ DDRB = (1 << IR_BIT) | (1 << LED_BIT); while(1){ for(int i=0; i<255; i++){ sendByte(i); _delay_ms(500); } } return 1; }
Pingback: ATtiny Hacks: Infrared guidance and navigation « FOOTBALL, SEX & ALCOHOL
Pingback: ATtiny Hacks: Infrared guidance and navigation - Hack a Day
Pingback: IR Remote (Syma s026) dedicated board – V2 « Robotics / Electronics / Physical Computing