Return-Path: robot-board@oberon.com Received: by media.mit.edu (5.57/DA1.0.4.amt) id AA17064; Thu, 24 Feb 94 14:52:33 -0500 Received: from ([127.0.0.1]) by oberon.com (4.1/SMI-4.1_Armado.MX) id AA20188; Thu, 24 Feb 94 14:43:48 EST Date: Thu, 24 Feb 94 14:43:48 EST Message-Id: <9402241941.AA22699@Stump.AI.SRI.COM> Errors-To: gkulosa@oberon.com Reply-To: konolige@ai.sri.com Originator: robot-board@oberon.com Sender: gkulosa@oberon.com Precedence: bulk From: Kurt Konolige To: Multiple recipients of list Subject: ultrasonics X-Listprocessor-Version: 6.0b -- ListProcessor by Anastasios Kotsikonas Finally got the Polaroid sonar ranging board working with the 6270 rev 2.21 board. I've included some .asm code and notes at the end of this message. --kk ======================= Notes on the Polaroid sonar ranging module February 24, 1994 Power supply: Use a 5V-6V supply with good isolation and a 440uf electrolytic across the supply pins. Using the motor battery (12V) with a 5V regulator, I also found it necessary to put 100uf and .1uf caps across the input of the regulator to reduce supply noise to the HC11. Pinouts: BINH and INIT are connected to pins 1 and 9 of the second motor controller chip. The chip (U15+16) is removed, and small pins soldered to the control lines, which are then inserted into the appropriate socket holes. Of course motor ports 2 and 3 are unusable. ECHO input is connected to pin A0, bit 0 of the digital input header. Other inputs are left floating. Code: Sonar polling is turned on with sonar_on(0), and off with sonar_off(0). A system interrupt routine turn on INIT for ON_PERIOD ticks, then turns it off for OFF_PERIOD ticks. Defaults are 30ms and 80ms, respectively. BINH is set high one tick after INIT goes high, so the board can read to approximately 6". Input capture on rising edges to PA0 is enabled by sonar_on, and the difference in times between the echo and init is reported in the variable sonar_time. The units are 2us, to keep it positive (largest range is about 32ms). Conversion is approximately 1.8ms per foot distance to target. No interrupts are needed. ======================== * icb file: "sonar-rev21-test.asm" * * Test the sonar board * Uses motor 2 control line for INIT, motor 3 for BINH * #include <6811regs.asm> * program equates SONAR_OUTPUT EQU $7000 /* Using motor control lines for output */ SONAR_BYTE EQU $0E /* Using upper half of motor byte */ SONAR_INIT EQU %01000000 /* INIT is motor 2 on line */ SONAR_INIT_MASK EQU %00111111 /* INIT is motor 2 on line */ SONAR_BINH EQU %10000000 /* BINH is motor 3 on line */ SONAR_INPUT EQU PORTA SONAR_ECHO EQU %00000001 /* ECHO is A0 line */ ON_PERIOD EQU 30 /* listen for 30ms */ OFF_PERIOD EQU 80 /* rest for 80ms */ CAPTURE_MASK EQU %11111110 /* TFLG1 mask */ CAPTURE_BIT EQU 1 /* TFLG1 and TCTL2 bit */ CAPTURE_REG EQU TIC3 ORG MAIN_START * variables /* C variables */ variable_sonar_time sonar_time FDB 0 /* counter time from beginning of INIT */ variable_sonar_enable FCB 0 sonar_enable FCB 0 /* internal variable */ sonar_count FCB 0 sonar_start_time FDB 0 subroutine_initialize_module: #include * X now has base pointer to interrupt vectors ($FF00 or $BF00) * get current vector; poke such that when we finish, we go there LDD TOC4INT,X ; SystemInt on TOC4 STD interrupt_code_exit+1 * install ourself as new vector LDD #interrupt_code_start STD TOC4INT,X * fall through to sonar_off subroutine /************************************************************************/ subroutine_sonar_off: CLR variable_sonar_enable+1 LDAA SONAR_BYTE ANDA #SONAR_INIT_MASK STAA SONAR_BYTE LDX #BASE BCLR TFLG1-BASE,X CAPTURE_MASK * clear capture bit BCLR TCTL2-BASE,X CAPTURE_BIT * set to normal input mode RTS /************************************************************************/ /************************************************************************/ subroutine_sonar_on: LDAA #1 /* load 1 into D */ STAA sonar_enable /* enable servo */ CLR sonar_count /* start cycle */ LDX #BASE BSET TCTL2-BASE,X CAPTURE_BIT * set to captur input mode RTS interrupt_code_start: LDAB sonar_enable /* check if sonar is on */ BEQ interrupt_code_exit LDAA sonar_count /* check if at beginning of cycle */ BEQ reset_count DECA STAA sonar_count BRA interrupt_code_exit reset_count LDX #BASE CMPB #1 BEQ set_init /* we're at the beginning of cycle */ CMPB #2 BEQ set_binh /* suppress the inhibit... */ LDAA SONAR_BYTE /* turn off INIT line and rest */ ANDA #SONAR_INIT_MASK STAA SONAR_BYTE /* turn it off for posterity */ STAA SONAR_OUTPUT /* turn it off now */ LDAA #OFF_PERIOD /* time to rest */ STAA sonar_count LDAA #1 /* set for init next time */ STAA sonar_enable BRCLR TFLG1-BASE,X CAPTURE_BIT interrupt_code_exit BCLR TFLG1-BASE,X CAPTURE_MASK /* clear the bit */ LDD CAPTURE_REG SUBD sonar_start_time LSRD /* always positive, in us */ STD sonar_time BRA interrupt_code_exit set_init LDAA SONAR_BYTE /* turn on INIT line */ ORAA #SONAR_INIT STAA SONAR_BYTE STAA SONAR_OUTPUT /* turn it on now */ LDD TCNT STD sonar_start_time LDAA #2 /* set for rest next time */ STAA sonar_enable BRA interrupt_code_exit set_binh LDAA SONAR_BYTE /* turn on BINH line */ ORAA #SONAR_BINH STAA SONAR_BYTE STAA SONAR_OUTPUT /* turn it on now */ LDAA #ON_PERIOD STAA sonar_count LDAA #3 STAA sonar_enable interrupt_code_exit: JMP $0000 ; this value poked in by init routine Return-Path: robot-board@oberon.com Received: by media.mit.edu (5.57/DA1.0.4.amt) id AA18268; Wed, 2 Feb 94 00:54:42 -0500 Received: from ([127.0.0.1]) by oberon.com (4.1/SMI-4.1_Armado.MX) id AA19383; Wed, 2 Feb 94 00:48:44 EST Date: Wed, 2 Feb 94 00:48:44 EST Message-Id: <9402020548.AA12284@pepper.Eng.Sun.COM> Errors-To: gkulosa@oberon.com Reply-To: Chuck.McManis@FirstPerson.COM Originator: robot-board@oberon.com Sender: gkulosa@oberon.com Precedence: bulk From: Chuck.McManis@FirstPerson.COM (Chuck McManis) To: Multiple recipients of list Subject: Ultrasonic resolved. X-Listprocessor-Version: 6.0b -- ListProcessor by Anastasios Kotsikonas Now this is really strange, when I disconnect *all* of the lines, except init and echo, it works. If I connect BINH, BLNK to ground per the data sheet it doesn't work. If I leave BINH and BLNK disconnected (ie floating in space) it *does* work. Very strange indeed. Several people have written me as to where I got the transducer and what I paid for it, the answer is: Circuit Cellar Kits 4 Park St. Suite 12 Vernon, CT 06066 Phone: (203) 875-2751 FAX : (203) 872-2204 The kit you want is T101 Sonar Ranging Kit, price $79.00 plus shipping which I guessed was $5. Using this thing is pretty simple, but you cannot power it from the miniboard's 5v lines (due to the face that it draws 2A when it is sending a pulse, which is brief, but is enough to reset the minboard :-)) I've got it hooked up to a bench supply but I'll probably move it over to the DC-DC converter bus. At the end of this I've included the C code I used to test it. Note that the constant (21) to convert from loop units into inches was empirical. Also this particular snippet of code uses gcc on a SPARC station as the cross compiler, hence the inline assembler. Should be easy to convert for icc11. --Chuck ------------------------------ cut here /* * sonar,c * * Code to use sonar to detect distant objects. Written for GCC68 * by Chuck McManis Feb - 1 - 1994, no rights reserved. */ /* SCCSID: %W% %I% %E% */ #define WANT_PUTCHAR #define WANT_PRINTDEC #define WANT_PUTS #define WANT_MSLEEP #define WANT_BUTTON #include /* * This inline assember defines a function printdist() which takes a * distance in 10s of milleinches (fixed point) and prints it out * with an appropriately placed decimal point. */ int printdist(); asm(" * * printdist() function * _printdist EQU * TSX PSHY LDD 2,X LDY #5 LDX #10 pds1 IDIV ; Loop 1 converts an unsigned int into 5 digits PSHB ; LDD #10 XGDX DEY BNE pds1 LDAB #3 ; print the first 3 of those digits (inc leading 0s) pds2 PULA ADDA #'0' BSR putbyte DECB BNE pds2 LDAA #'.' ; Fixed decimal point BSR putbyte LDAB #2 ; Fractional part pds3 PULA ADDA #'0' BSR putbyte DECB BNE pds3 LDAA #'\"' BSR putbyte ; putbyte is defined in minilib.h PULY RTS "); /* * Very simple ping function. This function will tell the sonar module * to take a reading and return the result. * * Note that the INIT line of the module is connected to pin 1 (bit 0) * and the ECHO line is connected to pin 8, (bit 7) in the main() function * we define INIT to be an output by setting DDRD. */ int ping() { int res; unsigned char *portc = ((unsigned char *)(0x1003)); res = 0; *portc = 0x1; /* take init high */ /* wait for echo */ while (((*portc & 0x80) == 0) && (res < 2000)) res++; *portc = 0x0; return (res); } int main() { int i; unsigned char *ddrc = ((unsigned char *)(0x1007)); unsigned char *portc = ((unsigned char *)(0x1003)); *ddrc = 0x0f; /* half input and half output */ *portc = 0x0; while (1) { /* for user selectable samples */ /* while(! button()) ; */ /* for one sample every second. */ msleep(1000); i = ping(); puts("Ping! "); i = i * 21; printdist(i); puts("\r"); } }