X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Ftests%2Fstatic_beacon%2Fstatic_beacon.c;h=ef6e1aa63b1de2a39c16aa7ed7ed76281c20e0b2;hp=9f9c8d61ed43a897acb7ffd99899aa0b09d9d161;hb=82d59983ef31ce70582b602600b4ee221f5bed03;hpb=aa0ebd8b43a0e48d791864ae3268e78d980a70e9 diff --git a/projects/microb2010/tests/static_beacon/static_beacon.c b/projects/microb2010/tests/static_beacon/static_beacon.c index 9f9c8d6..ef6e1aa 100755 --- a/projects/microb2010/tests/static_beacon/static_beacon.c +++ b/projects/microb2010/tests/static_beacon/static_beacon.c @@ -24,6 +24,7 @@ #include #include +#include #include @@ -40,11 +41,12 @@ //#define NO_MODULATION #define WAIT_LASER -//#define MODUL_455KHZ +#define MODUL_455KHZ //#define MODUL_56KHZ -#define MODUL_38KHZ +//#define MODUL_38KHZ //#define SPEED_40RPS -#define SPEED_10RPS +#define SPEED_20RPS +//#define SPEED_10RPS /* beacon identifier: must be odd, 3 bits */ #define BEACON_ID 0x1 @@ -56,7 +58,7 @@ #define FRAME_DATA_SHIFT 3 #if (defined MODUL_455KHZ) -#define N_PERIODS 10 +#define N_PERIODS 15 #define N_CYCLES_0 17 #define N_CYCLES_1 17 #elif (defined MODUL_56KHZ) @@ -107,7 +109,7 @@ /* FRAME must be odd */ /* #define FRAME 0x0B /\* in little endian 1-1-0-1 *\/ */ /* #define FRAME_LEN 4 */ -#define FRAME 0xAA5B /* in little endian */ +#define FRAME 0x4A5B /* in little endian */ #define FRAME_LEN 16 /* pin returns !0 when nothing, and 0 when laser is on photodiode */ @@ -121,6 +123,11 @@ #define MAX_INTER_TIME ((uint16_t)(8000*2)) /* t=8ms dist=10cm */ #define IR_DELAY ((uint16_t)(8000*2)) #define INTER_LASER_TIME 30 /* in ms */ +#elif (defined SPEED_20RPS) +#define MIN_INTER_TIME ((uint16_t)(40*16)) /* t~=80us dist=350cm */ +#define MAX_INTER_TIME ((uint16_t)(2000*16)) /* t=2ms dist=? >10cm */ +#define IR_DELAY ((uint16_t)(2000*16)) +#define INTER_LASER_TIME 10 /* in ms */ #elif (defined SPEED_40RPS) #define MIN_INTER_TIME ((uint16_t)(40*16)) /* t~=40us dist=350cm */ #define MAX_INTER_TIME ((uint16_t)(2000*16)) /* t=2ms dist=10cm */ @@ -130,6 +137,7 @@ #error "speed not defined" #endif +extern prog_uint16_t framedist_table[]; /* basic functions to transmit on IR */ static inline void xmit_0(void) @@ -216,33 +224,20 @@ static uint16_t do_cksum(uint16_t val) static uint32_t get_frame(uint16_t laserdiff) { uint32_t frame = 0; - double a, d; - uint16_t frame_dist; + uint16_t frame_dist = 256; + uint16_t step, val; - frame |= ((uint32_t)BEACON_ID << BEACON_ID_SHIFT); + /* for calibration, return the time */ + if (0) + return laserdiff; - /* process angle from laserdiff time */ -#ifdef SPEED_10RPS - /* timer = 2Mhz */ - a = ((double)laserdiff / (2000000./10.)) * 2. * M_PI; -#else - /* timer = 16Mhz */ - a = ((double)laserdiff / (16000000./40.)) * 2. * M_PI; -#endif - /* get distance from angle */ - d = LASER_DIST / sin(a/2); - - /* scale it between 0 and 511 */ - if (d <= MIN_DIST) - return 0; - if (d >= MAX_DIST) - return 0; - d -= MIN_DIST; - d /= (MAX_DIST-MIN_DIST); - d *= 512; - frame_dist = (uint16_t)d; - if (frame_dist >= 512) /* should not happen... */ - return 0; + for (step = 128; step != 0; step /= 2) { + val = pgm_read_word(&framedist_table[frame_dist]); + if (laserdiff > val) + frame_dist -= step; + else + frame_dist += step; + } frame |= ((uint32_t)(frame_dist & FRAME_DATA_MASK) << FRAME_DATA_SHIFT); @@ -259,7 +254,7 @@ static inline int8_t wait_laser(uint16_t *when, uint16_t *laserdiff) uint16_t time1, time2; uint16_t diff; -#ifdef SPEED_40RPS +#if (defined SPEED_40RPS) || (defined SPEED_20RPS) /* set timer to 16Mhz, we will use ICP */ TCCR1A = 0; TCCR1B = _BV(CS10); @@ -369,6 +364,23 @@ int main(void) while (1); #endif +#if 0 + /* test freq ~ 400khz */ + ICR1 = 38; + OCR1A = 19; + TCCR1B = _BV(WGM13) | _BV(WGM12); + TCNT1 = 37; + TCCR1A = _BV(COM1A1) | _BV(WGM11); + TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); + + /* motor PWM 50%, 8khz */ + DDRB |= 0x08; + OCR2 = 50; + TCCR2 = _BV(WGM21) | _BV(WGM20) | _BV(COM21) | _BV(CS21) ; + + while (1); +#endif + /* configure timer 0, prescaler = 64 */ TCCR0 = _BV(CS01) | _BV(CS00);