To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 7784
7783  |  7785
Subject: 
Sonar and overflow
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Mon, 1 May 2000 09:20:41 GMT
Viewed: 
1015 times
  
Hi

I've tried to use my Polaroid Sonar not only for distances up to 2.7 meters. So
I want to check the overflow flag. But my code doesn't work. Can anybody give
me some advises?

Here is my code:

long sonar_sample() {
        int start_time;
        int help;
        overflow_counter=0L;
        poke(0x1023, 1);                                /* clear tic3 flag */

        start_time=peekword(0x100e);        /* capture start time */
        bit_set(0x1008, 0x20);                        /* trigger pulse */
        bit_clear(0x1024,0b10000000);                 /* TOI cleared => TOF
read by software */
        while (!(peek(0x1000) & 0x1)) {        /* wait until receive echo */
                if (peek(0x1025)&0b10000000)
                {
                        overflow_counter=overflow_counter+1L;
                        bit_clear(0x1025,0b10000000);
                }
                if (overflow_counter>=4L)
                {
                        /* if too much time has elapsed, abort */
                        bit_clear(0x1008, 0x20);
                        return -1L;
                }
                defer();                    /* let others run while waiting */
        }
        bit_clear(0x1008, 0x20);                /* clear pulse trigger */
        help =peekword(0x1014)-start_time;
        return overflow_counter*65535L +(long)help; /* tic3 has time of echo */
}



Thanks

Martin



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR