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 / 8133
8132  |  8134
Subject: 
sonar and overflow
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Mon, 16 Oct 2000 21:43:07 GMT
Viewed: 
1002 times
  
Hi

I've got a HB with an Exp-Board and the 6500 Polaroid Sonar Ranging Module.

I want to measure distances greater than about 2.7m. So I tried to count the
overflow flag at 0x1025 bit 7. But my counter runs to fast, that means it count
more than the overflow that occured (every 31.25ms), so my results arn't very
usefull!

Can anybody heelp my?

Thanx

Martin


Here is my code:
int overflow_counter;
int a=10;


void sonar_init()
{
        bit_set(0x1009, 0x30);                               /* DDRD */
        bit_set(0x1021, 1);                                  /* at TCTL2 */
        bit_clear(0x1021, 2);                                /* set TIC3 for
rising edge */
        bit_clear(0x1024,0x80);                              /* clear TOI, no
Timer Overflow Interrupt */
}

int sonar_overflow()
{
        int start_time;
        overflow_counter=1;
        poke(0x1023, 1);                                     /* clear TIC3 flag
*/
        start_time= peekword(0x100e);                        /* capture start
time */
        bit_set(0x1008, 0x20);                               /* trigger pulse
*/
        while (!(peek(0x1000) & 0x1))                        /* wait until
receive echo */
        {
                if (peek(0x1025) & 0x80)                     /* check Timer
Overflow Flag (TOF)*/
                {
                        overflow_counter +=1;                /* increase
overflow-counter */
                        bit_clear(0x1025,0x80);              /* clear Timer
Overflow Flag (TOF) */
                }
                if (overflow_counter >= 20*a)                    /* if too much
time has elapsed, abort */
                {
                        bit_clear(0x1008, 0x20);
                        return -1;
                }
                defer();                                     /* let others run
while waiting */
        }
        bit_clear(0x1008, 0x20);                             /* clear pulse
trigger */
        return (peekword(0x1014) - start_time)/(2^a)+overflow_counter*2^(15-a);
    /* TIC3 has time of echo */
}
void main()
{
        sonar_init();
        while (1)
        {
                int result;
                result= sonar_overflow();
                if (result != -1) printf("%d     %d\n",
result,overflow_counter);
                else printf("*******   %d\n",overflow_counter);
                msleep(160L);
        }
}



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