From: Justin R. <ju...@ra...> - 2008-03-11 16:00:18
|
I am using the Ping))) sensor from parallax. I posed the data sheet on it before. http://parallax.com/Portals/0/Downloads/docs/prod/acc/28015-PING-v1.5.pdf The second page has the timing and pulse information. The ISR that handles the ultrasonic is much smaller. Here is the whole thing: #define Enable_Capture DDRD&=~(1<<4); TIMSK|=(1<<5) //enable capture interrupt on timer1 #define Disable_Capture DDRD|=(1<<4); TIMSK&=~(1<<5) //set DDRD as output #define Capture_Rise TCCR1B|=(1<<6) //capture rising edge (0v->5v) #define Capture_Fall TCCR1B&=~(1<<6) //capture falling edge (5v->0v) ISR (TIMER1_CAPT_vect){ if (!rise_or_fall){ Capture_Fall; pulse_start=ICR1; rise_or_fall=1;//the next time will be a falling edge }else{ Capture_Rise; pulse_end=ICR1; if (pulse_end>=pulse_start){ pulse_time=(pulse_end-pulse_start);//time of pulse }else{ //max is 5000 so if it overflowed we need to remove 50000 to //make it as if it did not overflow pulse_time=((pulse_end+2500)-(pulse_start-2500)); } rise_or_fall=0; interrupt_done=0;//leave while loop since we are done } } The sensor is on IC1 (portd pin 4). Here is the disassembled output: 000000ca <__vector_11>: ca: 1f 92 push r1 cc: 0f 92 push r0 ce: 0f b6 in r0, 0x3f ; 63 d0: 0f 92 push r0 d2: 11 24 eor r1, r1 d4: 2f 93 push r18 d6: 3f 93 push r19 d8: 8f 93 push r24 da: 9f 93 push r25 dc: 80 91 00 00 lds r24, 0x0000 e0: 88 23 and r24, r24 e2: 01 f4 brne .+0 ; 0xe4 <__vector_11+0x1a> e4: 82 e0 ldi r24, 0x02 ; 2 e6: 80 93 00 00 sts 0x0000, r24 ea: 8e b5 in r24, 0x2e ; 46 ec: 8f 7b andi r24, 0xBF ; 191 ee: 8e bd out 0x2e, r24 ; 46 f0: 86 b5 in r24, 0x26 ; 38 f2: 97 b5 in r25, 0x27 ; 39 f4: 90 93 00 00 sts 0x0000, r25 f8: 80 93 00 00 sts 0x0000, r24 fc: 81 e0 ldi r24, 0x01 ; 1 fe: 80 93 00 00 sts 0x0000, r24 102: 00 c0 rjmp .+0 ; 0x104 <__vector_11+0x3a> 104: 8e b5 in r24, 0x2e ; 46 106: 80 64 ori r24, 0x40 ; 64 108: 8e bd out 0x2e, r24 ; 46 10a: 86 b5 in r24, 0x26 ; 38 10c: 97 b5 in r25, 0x27 ; 39 10e: 90 93 00 00 sts 0x0000, r25 112: 80 93 00 00 sts 0x0000, r24 116: 20 91 00 00 lds r18, 0x0000 11a: 30 91 00 00 lds r19, 0x0000 11e: 80 91 00 00 lds r24, 0x0000 122: 90 91 00 00 lds r25, 0x0000 126: 28 17 cp r18, r24 128: 39 07 cpc r19, r25 12a: 00 f0 brcs .+0 ; 0x12c <__vector_11+0x62> 12c: 80 91 00 00 lds r24, 0x0000 130: 90 91 00 00 lds r25, 0x0000 134: 20 91 00 00 lds r18, 0x0000 138: 30 91 00 00 lds r19, 0x0000 13c: 00 c0 rjmp .+0 ; 0x13e <__vector_11+0x74> 13e: 80 91 00 00 lds r24, 0x0000 142: 90 91 00 00 lds r25, 0x0000 146: 20 91 00 00 lds r18, 0x0000 14a: 30 91 00 00 lds r19, 0x0000 14e: 88 57 subi r24, 0x78 ; 120 150: 9c 4e sbci r25, 0xEC ; 236 152: 82 1b sub r24, r18 154: 93 0b sbc r25, r19 156: 90 93 00 00 sts 0x0000, r25 15a: 80 93 00 00 sts 0x0000, r24 15e: 10 92 00 00 sts 0x0000, r1 162: 10 92 00 00 sts 0x0000, r1 166: 9f 91 pop r25 168: 8f 91 pop r24 16a: 3f 91 pop r19 16c: 2f 91 pop r18 16e: 0f 90 pop r0 170: 0f be out 0x3f, r0 ; 63 172: 0f 90 pop r0 174: 1f 90 pop r1 176: 18 95 reti Thanks Justin -- View this message in context: http://www.nabble.com/Robostix-timer1-capture-and-servos-tp15942835p15976991.html Sent from the Gumstix mailing list archive at Nabble.com. |