Maxbotic Ultrasonic sensor how to control?

Digital Fiber, Photoelectric, Laser Range, Optical, Temperature, Rotary Encoder, Ultrasonic, Gas, Gyro, Accelerometer, FlexiBend, Flexiforce, Compass......

Re: Maxbotic Ultrasonic sensor how to control?

Postby Light » Tue Mar 09, 2010 5:11 am

thank you luqman and ober.
are you sure that the file u told me about should be named delay.txt and not delay.h or delay.c ?
and this file should be saved in the same file that i saved he project in; and not the Include file located on the software main file ?
btw do u have any idea what are the following distance values(100,80,60,40,20), and how they were calculated ? :

CODE: SELECT_ALL_CODE
          if(distance>100)
      {
      PORTC=0B00000001;
      }
      else if(distance>80)
      {
      PORTC=0B00000010;
      }
      else if(distance>60)
      {
      PORTC=0B00000100;
      }
      else if(distance>40)
      {
      PORTC=0B00001000;
      }
      else if(distance>20)
      {
      PORTC=0B00010000;
      }
}


also any idea about the formula :
distance=value*1.75616; // calculate inch value per inch = 147us with 20Mhz internal clock.
what is 1.75616 ?
Light
Novice
 
Posts: 19
Joined: Wed Dec 02, 2009 2:57 am

Re: Maxbotic Ultrasonic sensor how to control?

Postby Light » Wed Mar 10, 2010 3:33 am

and by the way i copied the previous code u gave me...still wouldn't work without deleting the #include "delay.h" and #include "delay.c"
thats when i try it in HI-TECH C compiler

but when i put the code in MikroC compiler...the code wouldn't work either when i keep the delay lines or delete them...although i've copied all of the libraries used in MPLAB to the mikroC PRO library

i need some serious help here...
Light
Novice
 
Posts: 19
Joined: Wed Dec 02, 2009 2:57 am

Re: Maxbotic Ultrasonic sensor how to control?

Postby luqman hakim » Wed Mar 10, 2010 6:49 am

sorry.. i forgot.. its delay.h
luqman hakim
Newbie
 
Posts: 11
Joined: Wed Jul 01, 2009 3:49 pm

Re: Maxbotic Ultrasonic sensor how to control?

Postby Light » Fri Mar 12, 2010 6:55 am

i knew it was delay.h from the beginning but still wont work :cry:

are you sure that i just have to put the delay.h file beside the project file in one folder ?
do i have to add header file in the MPLAB it self ?
what about delay.c ??? is it another file that i have to add ??

please help me...i had enough of this stupid problem !
this is my ym if u r free to communicate: eng.light@yahoo

thank you
Light
Novice
 
Posts: 19
Joined: Wed Dec 02, 2009 2:57 am

Re: Maxbotic Ultrasonic sensor how to control?

Postby luqman hakim » Fri Mar 12, 2010 9:28 am

CODE: SELECT_ALL_CODE
/*

Servo PIC

Designed by Shane Tolmie, Andrew Dixon and Shane Buckham Jan 99.
Common header file for servo control for the Airborne Control Systems (ACS) flight stabilisation system.

Compiled with Hitech-C v7.82

Usage: #include in all ".c" files in project along with "pic.h"

*/

//warning about #if statements: if any of the arguments are spelled wrong or
//unrecognised by the compiler, it will not generate a warning, but not include code

#ifndef ALWAYS_H
#define ALWAYS_H

#define us_to_ticks(x)   (x*(PIC_CLK/4)/(TMR1_PRESCALE))      //converting microseconds to tmr1 clock ticks
#define ticks_to_us(x)   ((x*4/PIC_CLK)*(TMR1_PRESCALE))      //converting tmr1 clock ticks to microseconds

#define hibyte(x) ((unsigned char)(x>>8))
#define lobyte(x) ((unsigned char)(x&0xff))


/*
given variable of any type (char, uchar, int, uint, long) it modifies
   the unsigned char residing at that memory location
   for ints, byte1 is msb, byte0 is lsb
   for longs   byte3 is msb, byte0 is lsb
   
   ie: sample C code
   
   unsigned int myint=0x4321;
   long mylong=0x87654321;
   
   //for myint    byte1(myint)=0x43; (msb) and byte0(myint)=0x21; (lsb)
   //for mylong   byte3(mylong)=0x87; (msb), byte2(mylong)=0x65;
                        byte2(mylong)=0x43; and byte0(mylong)=0x21; (lsb)

   note:   to avoid fixup overflow errors add bankX if the target variable
            resides in banks 1, 2 or 3
*/

//#define byte0(x)      (unsigned char)(*(((unsigned char *)&x)+0))
//#define byte1(x)      (unsigned char)(*(((unsigned char *)&x)+1))
//#define byte2(x)      (unsigned char)(*(((unsigned char *)&x)+2))
//#define byte3(x)      (unsigned char)(*(((unsigned char *)&x)+3))

#define byte0_atbank1(x)      (unsigned char)(*(((bank1 unsigned char *)&x)+0))
#define byte1_atbank1(x)      (unsigned char)(*(((bank1 unsigned char *)&x)+1))
#define byte2_atbank1(x)      (unsigned char)(*(((bank1 unsigned char *)&x)+2))
#define byte3_atbank1(x)      (unsigned char)(*(((bank1 unsigned char *)&x)+3))

#define byte0_atbank2(x)      (unsigned char)(*(((bank2 unsigned char *)&x)+0))
#define byte1_atbank2(x)      (unsigned char)(*(((bank2 unsigned char *)&x)+1))
#define byte2_atbank2(x)      (unsigned char)(*(((bank2 unsigned char *)&x)+2))
#define byte3_atbank2(x)      (unsigned char)(*(((bank2 unsigned char *)&x)+3))

#define byte0_atbank3(x)      (unsigned char)(*(((bank3 unsigned char *)&x)+0))
#define byte1_atbank3(x)      (unsigned char)(*(((bank3 unsigned char *)&x)+1))
#define byte2_atbank3(x)      (unsigned char)(*(((bank3 unsigned char *)&x)+2))
#define byte3_atbank3(x)      (unsigned char)(*(((bank3 unsigned char *)&x)+3))

/*
given variable of any type (char, uchar, int, uint, long) it modifies
   the int residing at that memory location
   ie: sample C code
   
   unsigned char array[4];
   unsigned int test;
   
   uint_atbyteaddr(&array[0])=0x4321;         //now array[0->3]={0x21,0x43,0,0};
   uint_atbyteaddr(&array[0+2])=0x8765;      //now array[0->3]={0x21,0x43,0x65,0x87};
   test=uint_atbyteaddr(&array[0+2])            //now test=0x8765
   
   note: do NOT use &(array[0]+1) to reference the int stored at array[1] as it will
            reference the int after array[0] in pointer arithmetic.  This will
            result with the int at array[2]
            instead use &array[0+1] to reference the int at array[1]
        
   note:   to avoid fixup overflow errors add bankX if the target variable
            resides in banks 1, 2 or 3
*/

#define   uint_atbyteaddr(x)               (unsigned int)(*(((unsigned int *)x)))
#define   uint_atbank1byteaddr(x)         (unsigned int)(*(((bank1 unsigned int *)x)))
#define   uint_atbank2byteaddr(x)         (unsigned int)(*(((bank2 unsigned int *)x)))
#define   uint_atbank3byteaddr(x)         (unsigned int)(*(((bank3 unsigned int *)x)))

#define THE_BEER_IS_PLENTIFUL_AND_THE_PARTY_SWINGING TRUE

/*
these two structures allow access to 2 byte word, high and low bytes of variable
declaration:   union wordtype x;
usage:   x.word=0xABCD; x.byte.high=0xAB; x.byte.low=0xCD;
            x.part.bit15=1; (msb), x.part.bit0=1; (lsb)
declaration:   union chartype x;
usage:   x.byte=0xAB;
            x.part.bit7=1; (msb), x.part.bit0=1; (lsb)
*/

struct sixteen_bits
{
   unsigned char bit0   :1;
   unsigned char bit1   :1;
   unsigned char bit2   :1;
   unsigned char bit3   :1;
   unsigned char bit4   :1;
   unsigned char bit5   :1;
   unsigned char bit6   :1;
   unsigned char bit7   :1;
   unsigned char bit8   :1;
   unsigned char bit9   :1;
   unsigned char bit10   :1;
   unsigned char bit11   :1;
   unsigned char bit12   :1;
   unsigned char bit13   :1;
   unsigned char bit14   :1;
   unsigned char bit15   :1;
};

struct eight_bits
{
   unsigned char bit0   :1;
   unsigned char bit1   :1;
   unsigned char bit2   :1;
   unsigned char bit3   :1;
   unsigned char bit4   :1;
   unsigned char bit5   :1;
   unsigned char bit6   :1;
   unsigned char bit7   :1;
};

struct two_bytes
{
   unsigned char low;
   unsigned char high;
};

union wordtype
{
   unsigned int word;
   struct two_bytes byte;
   struct sixteen_bits part;
};

union chartype
{
   unsigned char byte;
   struct eight_bits part;
};

//defines
#define INPUT 1      //port directions
#define OUTPUT 0
#define TRUE 1
#define FALSE 0
#define   HIGH 1
#define   LOW 0
#define   hi 1
#define   lo 0

#define b asm("nop")      //convenient point for breakpoint (debugging)
#define l while(1)         //loop for ever (debugging)

//see AM576.  If interrupt occurs just when gie gets set to zero, it won't be cleared

#define   gie_on      GIE=1
#define gie_off      while(GIE==1) GIE=0

#endif




light...
copy n paste in text file.. then save in your project folder
save this file as always.h
luqman hakim
Newbie
 
Posts: 11
Joined: Wed Jul 01, 2009 3:49 pm

Re: Maxbotic Ultrasonic sensor how to control?

Postby Light » Fri Mar 12, 2010 7:25 pm

Luqman i am very very thankful for your help...the code was successfully compiled in HI-TECH after i've updated MPLAB (from v7.4 to v8.36) :)
i've used the files you sent to my e-mail...and it worked successfully.
one last question...and i dont want to wast your time...so answer me if u know it :) dont bother to take time finding out :D .... what if i want to make the code work in MikroC IDE ??? what are the changes and the files i need to do and create ?

thank you very much my friend :)
Light
Novice
 
Posts: 19
Joined: Wed Dec 02, 2009 2:57 am

Re: Maxbotic Ultrasonic sensor how to control?

Postby luqman hakim » Fri Mar 12, 2010 8:08 pm

sorry light.. i`m newbie for microC and MPLAB IDE.. so i don`t know how to change term from MicroC to MPLAB IDE...
maybe this link can help u.. http://www.mikroe.com/en/
luqman hakim
Newbie
 
Posts: 11
Joined: Wed Jul 01, 2009 3:49 pm

Re: Maxbotic Ultrasonic sensor how to control?

Postby Light » Fri Mar 12, 2010 9:20 pm

nevermind...u've been more than helpful ;)
tq
Light
Novice
 
Posts: 19
Joined: Wed Dec 02, 2009 2:57 am

Re: Maxbotic Ultrasonic sensor how to control?

Postby ober » Sun Mar 14, 2010 9:35 pm

Light, so you can measure the distance now?
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Maxbotic Ultrasonic sensor how to control?

Postby Light » Fri Mar 19, 2010 1:34 am

ober WROTE:Light, so you can measure the distance now?


yes :)

but i want to change the output type...instead of triggering ports when the distance changes....i want only ONE pin to give me variable voltage depending on the distance of the object....for example:

when distance > 100 .... RC2 = 1V
when distance > 80.......RC2 = 2V
when distance > 50.......RC3 = 3.5V

it doesn't have to be linear output...because in the end i want the user to fell the difference...that an obstacle became closer.

can you help me with this part ?
Light
Novice
 
Posts: 19
Joined: Wed Dec 02, 2009 2:57 am

PreviousNext

Return to Sensor

Who is online

Users browsing this forum: No registered users and 7 guests