www.micro-examples.com : PicoBat

Views
From www.micro-examples.com
(Difference between revisions)
Jump to: navigation, search
(PicoBat : a PIC-based simple and cheap ultrasonic detector)
 
(11 intermediate revisions by one user not shown)
Line 1: Line 1:
An ultrasonic bat detector with only 3 components !
+
[[File:PicoBat.jpg|thumb|PicoBat running on a bread board]]
 +
An ultrasonic [[wikipedia:Bat detector|bat detector]] with only 3 components !
  
 
==PicoBat : a PIC-based simple and cheap ultrasonic detector==
 
==PicoBat : a PIC-based simple and cheap ultrasonic detector==
Let me introduce PicoBat to you with this short video clip :
+
A short video clip is sometimes better than a long explanation :
 
{{#ev:youtube|EjEkXlET0CM}}
 
{{#ev:youtube|EjEkXlET0CM}}
  
The idea of this circuit is to hack PIC oscillator circuit, by replacing the crystal by a piezo sensor : the frequency of the oscillator will depend on presence ultrasonic waves.
+
The idea of this circuit is to hack the PIC oscillator circuit, by replacing the crystal by a piezo sensor : the frequency of the oscillator then depends on [[wikipedia:Ultrasound|ultrasounds]].
  
Oscillator frequency is then divided and pushed to a piezo speaker.
+
Oscillator frequency is then divided by 4 by the PIC, and pushed into a piezo speaker.
  
 
It shares the same idea as [[PicoDetector]], the metal detector.
 
It shares the same idea as [[PicoDetector]], the metal detector.
  
 
==Circuit Schematic==
 
==Circuit Schematic==
[[File:PicDetector-metal-detector-circuit-schematic.png]]
+
[[File:PicoBat-circuit-schematic.png]]
* Coil L1 replaces crystal in PIC oscillator circuit : try with the coils you have to find the best one ! if calibrate LED blinks on power up, it works.
+
* The ultrasonic piezo receiver replaces resistor in PIC oscillator circuit  
* D1 is a dual LED, replace with two classic LEDs if you don't have one.
+
* SP1 is any piezo speaker you have
  
 
==C Source code==
 
==C Source code==
Line 20: Line 21:
 
/*
 
/*
 
  *******************************************************************************
 
  *******************************************************************************
  * picoDetector : an ultra simple and cheap metal detector
+
  * picoBAT : an ultra simple ultrasonic bat detector
 
  *******************************************************************************
 
  *******************************************************************************
 
  *
 
  *
  * Author : Bruno Gavand, april 2009
+
  * Author : Bruno Gavand, February 2009
 
  * see more details on http://www.micro-examples.com/
 
  * see more details on http://www.micro-examples.com/
 
  *
 
  *
  * source code for mikroC PRO compiler V1.65
+
  * source code for mikro C compiler V8.2
 
  * feel free to use this code at your own risks
 
  * feel free to use this code at your own risks
 
  *
 
  *
  * target : PIC12, oscillator in HS mode, watchdog enabled
+
  * target : PIC12
 
  *
 
  *
 
  * PIC PIN Assignemnt :
 
  * PIC PIN Assignemnt :
 
  *
 
  *
  * GP0 : detect LED indicator
+
  * GP0 GP1 : piezo speaker
* GP1 : calibrate LED indicator
+
  * GP5 : ultrasonic transducer receiver
* GP2 : NC
+
* GP3 : NC
+
  * GP4, GP5 : inductor
+
 
  *
 
  *
 
  *******************************************************************************
 
  *******************************************************************************
 
  */
 
  */
  
#define MAXTRY 15      // number of watchdog restart to calibrate loop counter
 
 
unsigned char  ctr ;          // number of loops between two watchdog resets
 
unsigned char  previous ;      // previous value of ctr
 
unsigned char  calibr ;        // calibration value when oscillator runs free
 
unsigned char  restarts ;      // number of watchdog restarts
 
unsigned char  en ;            // enable flag, allows detection
 
 
/*
 
* main loop
 
*/
 
 
void    main()
 
void    main()
 
         {
 
         {
        unsigned char  i ;
 
       
 
 
 
         /*
 
         /*
 
         * configure GPIO as digital port
 
         * configure GPIO as digital port
Line 63: Line 47:
 
         CMCON0 = 7 ;
 
         CMCON0 = 7 ;
 
         ANSEL = 0 ;
 
         ANSEL = 0 ;
 +
 
         TRISIO = 0 ;
 
         TRISIO = 0 ;
         GPIO = 0 ;
+
         GPIO = 0b01 ;
  
         /*
+
         for(;;)
        * power up ?
+
        */
+
        if(STATUS.NOT_TO)
+
 
                 {
 
                 {
 
                 /*
 
                 /*
                 * yes, init variables
+
                 * toggles speaker outputs
 
                 */
 
                 */
                 restarts = 0 ;
+
                 GPIO ^= 0b11 ;
                calibr = 1 ;
+
 
                 }
 
                 }
 +
        }
  
        /*
+
</pre>
        * watchdog reset counter
+
        */
+
        if(restarts < 255) restarts++ ;
+
  
        /*
+
No, there is no mistake, full source code is above !
        * if counter differs too much from calibration value
+
        */
+
        if((previous ^ ctr) > calibr)
+
                {
+
                /*
+
                * turn detect LED on
+
                */
+
                GPIO.F0 = en ;
+
               
+
                /*
+
                * if not on power up
+
                */
+
                if(STATUS.NOT_TO == 0)
+
                        {
+
                        /*
+
                        * while in calibration mode
+
                        */
+
                        if(restarts < MAXTRY)
+
                                {
+
                                /*
+
                                * shift calibration value
+
                                * and wait a little bit
+
                                */
+
                                calibr <<= 1 ;
+
                                Delay_ms(5) ;
+
                                }
+
                        }
+
                else
+
                        {
+
                        /*
+
                        * turn detect LED off
+
                        */
+
                        GPIO.F0 = 0 ;
+
                        }
+
                }
+
  
        /*
 
        * save last counter
 
        */
 
        previous = ctr ;
 
 
        /*
 
        * is calibration over ?
 
        */
 
        if(restarts > MAXTRY)
 
                {
 
                /*
 
                * yes, turn calibrate LED off
 
                * and set enable flag
 
                */
 
                GPIO.F1 = 0 ;
 
                en = 1 ;
 
                }
 
        else
 
                {
 
                /*
 
                * no, turn calibrate LED on
 
                * and clear enable flag
 
                */
 
                GPIO.F1 = 1 ;
 
                en = 0 ;
 
                }
 
 
        /*
 
        * set watchdog prescaler
 
        */
 
        OPTION_REG = 0b11111001 ;
 
       
 
        /*
 
        * start counter, to be interrupted by watchdog
 
        */
 
        ctr = 0 ;
 
        for(;;)
 
              {
 
              ctr++ ;
 
              }
 
        }
 
</pre>
 
 
==Download project==
 
==Download project==
Download picoDetector_project.ZIP file for mikroC : [[File:PicoDetector-project.zip]]  
+
Download PicoBat-project.zip file for mikroC : [[File:PicoBat-project.zip]]  
  
 
Includes :
 
Includes :
  
 
* [[mikroC PRO]] project files for [[PIC12F683]], should work also with most of PIC  
 
* [[mikroC PRO]] project files for [[PIC12F683]], should work also with most of PIC  
* picoDetector C source code  
+
* picoBat C source code  
* picoDetector .HEX files
+
* picoBat .HEX files
 
[[Category:Projects]]
 
[[Category:Projects]]
 
[[Category:PIC12]]
 
[[Category:PIC12]]
 +
 +
==Discussion and comments==
 +
{{#w4grb_rate:}}
 +
<discussion />

Latest revision as of 22:55, 12 February 2012

PicoBat running on a bread board

An ultrasonic bat detector with only 3 components !

Contents

PicoBat : a PIC-based simple and cheap ultrasonic detector

A short video clip is sometimes better than a long explanation :


The idea of this circuit is to hack the PIC oscillator circuit, by replacing the crystal by a piezo sensor : the frequency of the oscillator then depends on ultrasounds.

Oscillator frequency is then divided by 4 by the PIC, and pushed into a piezo speaker.

It shares the same idea as PicoDetector, the metal detector.

Circuit Schematic

PicoBat-circuit-schematic.png

  • The ultrasonic piezo receiver replaces resistor in PIC oscillator circuit
  • SP1 is any piezo speaker you have

C Source code

/*
 *******************************************************************************
 * picoBAT : an ultra simple ultrasonic bat detector
 *******************************************************************************
 *
 * Author : Bruno Gavand, February 2009
 * see more details on http://www.micro-examples.com/
 *
 * source code for mikro C compiler V8.2
 * feel free to use this code at your own risks
 *
 * target : PIC12
 *
 * PIC PIN Assignemnt :
 *
 * GP0 GP1 : piezo speaker
 * GP5 : ultrasonic transducer receiver
 *
 *******************************************************************************
 */

void    main()
        {
        /*
         * configure GPIO as digital port
         */
        CMCON0 = 7 ;
        ANSEL = 0 ;

        TRISIO = 0 ;
        GPIO = 0b01 ;

        for(;;)
                {
                /*
                 * toggles speaker outputs
                 */
                GPIO ^= 0b11 ;
                }
        }

No, there is no mistake, full source code is above !

Download project

Download PicoBat-project.zip file for mikroC : File:PicoBat-project.zip

Includes :

  • mikroC PRO project files for PIC12F683, should work also with most of PIC
  • picoBat C source code
  • picoBat .HEX files

Discussion and comments

Current user rating: 75/100 (60 votes)

 You need to enable JavaScript to vote

You need JavaScript enabled for viewing comments

Navigation
Others
Donation
You can help :
with Paypal
Share
Personal tools
www.micro-examples.com Electronic circuits with micro-controllers, projects with source code examples