Bat detector

pasks

New Member
Can anyone help me translate a very small piece of code written for the 12F683 (on which the 08M is based, I believe). I'm just starting out on all this electronics stuff, so if anyone can help, I'd be very grateful.

See http://www.micro-examples.com/public/microex-navig/doc/077-picobat.html

* 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 ;
}
}

The code divides the input frequency by 16 bringing it down to our hearing range.

Cheers all.
 

westaust55

Moderator
PASKS,

firstly welcome to the PICAXE forum.

CAN you explain a little further exactly what your end result is.

Are you intending to use an 08M PICAXE chip?
If so, then for the output to a speaker there are the TUNE and SOUND commands available. These only need one PICAXE chip IO pin to be used (not two as per the project you are trying to emulate)

Do you need to divide the received noise by 4 and pass to the speaker or can other sounds/notes suffice?

Ultrasonic sound starts at roughly 20kHz and upwards.

The PICAXE COUNT command can detect pulses:
- up to 25kHz at 4MHz clock speed - probably a bit low.
- up to 50kHz at 8MHz clock speed. (Use SETFREQ m8 to select 8MHz mode)


Have a read about the mentioned commands and give us a better idea of exactly what you are looking for, or can accept.
 

pasks

New Member
Thanks for the reply. Sorry, the original message was a bit too vague.
Yes, I would like to use the 08M.
The original sound doesn't need to be reproduced, other sounds will suffice, but I thought that dividing the received frequency by 32 was the way to go.
Bat detectors generally hear sounds up to 120kHz, although the majority of bats will be in the 20kHz-60kHz range. One concern (apart from rapid learning requirements), is that things like CMCON0, TRISIO, ANSEL, etc don't appear in the 08M datasheet and I'm finding it tricky to understand exactly how the code works.
This is my first project, so apologies if I appear a bit simple at the moment, but thanks for any help available.
 

MFB

Senior Member
Not a PICAXE task

The PICAXE will not be able to continuously divide the ultrasonic signal and output audio. But this digital task can be done very simply using a CMOS ripple counter. For example the HEF4024B, which has seven output stages.

However, the project will require some analog signal conditioning circuitry to feed nice clean signal to the counter. Unless you already have some electronics experience this might prove difficult.
 

pasks

New Member
OK, thanks for advice. Back to basics for me, & I'll try to do it some time in the future.
I was hoping it would be simpler than that.
Thanks anyway.
 

MPep

Senior Member
A different method would be to down-convert the UltraSounds to (human) Audio band.
Similar to RF receivers, use a LO mixed with US, to give HA. I know that some kits were made for this a few years ago. Cannot remember who had them though.
I think Maplin.
 

westaust55

Moderator
Thanks for the reply. Sorry, the original message was a bit too vague.
Yes, I would like to use the 08M.

One concern (apart from rapid learning requirements), is that things like CMCON0, TRISIO, ANSEL, etc don't appear in the 08M datasheet and I'm finding it tricky to understand exactly how the code works.

Those are Special FUnction Registers (SFR's).
You need to have a look at my memory / variable map previously published on this forum for a first idea and then read the relevant Micrcochip PIC 12F683datasheet (for the 08M) if you want to understand those further but for a start, sugegst that you stick with PICAXE BASIC programming.

http://www.picaxeforum.co.uk/showthread.php?t=11514

http://ww1.microchip.com/downloads/en/DeviceDoc/41211D_.pdf
 

hippy

Ex-Staff (retired)
One concern (apart from rapid learning requirements), is that things like CMCON0, TRISIO, ANSEL, etc don't appear in the 08M datasheet and I'm finding it tricky to understand exactly how the code works.
Are you sure the code is complete or does what you expect it to ?

Looking at the code, it sets all I/O as output, sets one pin high (GP0), another low (GP1) then toggles each at what I would imagine to be a reasonable fast rate, with an output transducer driven by those inverse output pins. That will give the audible output to a piezo.

The 'magic' is all in how the PICmicro chip is configured, not in controlling I/O - It appears to use the ultrasonic detector as the internal clock source for the PICmicro.

Given the mechanism used it would appear to be impossible to replicate this operation on a PICAXE. It may be possible to achieve a similar effect but would be much more than a simple one-to-one code translation. A hardware solution such as suggested by MFB my be more appropriate.
 
Last edited:

vttom

Senior Member
Here's a thought....

1) Use a comparator IC to take the analog waveform from a microphone and turn it into something that swings rail-to-rail.
2) Feed that into a digital input pin on the 08M.
3) Use the "count" command to count how many transitions there are within a certain time period. Given the number of transitions and the length of the time period, you should be able to work out the frequency of the signal.
4) From there, you can determine if the input frequency is above whatever threshold you're looking for. If so, then drive an output pin on the 08M with pwmout. If you make the pwmout frequency a function of the count value, then you have effectively divided down the high-frequency signal to something you can hear.
5) Drive a speaker (or headphones) with the PWM coming out of the 08M. You might want to add an analog low-pass filter to smooth the square wave to something a little more pleasing to listen to.
6) Put the count/maths/pwmout stuff in a continuous loop.
 

Andrew Cowan

Senior Member
Just an addition to vttom's technique:

0) Use a microphone designed for ultrasonics (an ultrasonic reciever).
1) Use a comparator IC to take the analog waveform from a microphone and turn it into something that swings rail-to-rail.
2) Feed that into a digital input pin on the 08M.
3) Use the "count" command to count how many transitions there are within a certain time period. Given the number of transitions and the length of the time period, you should be able to work out the frequency of the signal.
4) From there, you can determine if the input frequency is above whatever threshold you're looking for. If so, then drive an output pin on the 08M with pwmout. If you make the pwmout frequency a function of the count value, then you have effectively divided down the high-frequency signal to something you can hear.
5) Drive a speaker (or headphones) with the PWM coming out of the 08M. You might want to add an analog low-pass filter to smooth the square wave to something a little more pleasing to listen to.
6) Put the count/maths/pwmout stuff in a continuous loop.
A
 

MFB

Senior Member
Andrew. One of the more interesting things to do with this type of detector is observing the activity of bats when using echolocation for navigation and hunting. Bats produce ultrasonic sounds that vary in frequency, duration and inter-pulse spacing depending on the species and the activity they are engaged in. A typical hunting sequence starts with the bat emitting pulses at a relatively low repletion rate until a target is acquired, but then increases rapidly as the bat closes on the prey.

I don’t think your suggested PICAXE configuration would be able to present the above information to the operator in a useful real-time way. The ripple counter approach would be simpler/cheaper and more usable in the field.
 

Andrew Cowan

Senior Member
Using a ultrasonic transducer would (maybe) give an yes/no responce. I misunderstood the application - for analyzing the tones, an electret microphone would be more suitable.

After a quick google, I'm amazed at how well small electret mics respond to high frequencies - I would have previously guessed they have a maximum of 25kHz or so.

A
 

MFB

Senior Member
Andrew. Most low cost bat detectors use readily available (e.g. from Jameco Electronics in the US or Maplin in the UK) piezo-electric sensors. As a common application for these sensors is range and proximity detection, they are often sold as a set with a matching piezo-electric emitter. The sensitivity of the sensor tends to peak at around 40 KHz and drops off rapidly either side of this frequency to give a total bandwidth of about 10KHz. Fortunately, the majority of bats emit sounds in the frequency range 20-60 KHz. This is an evolutionary compromise that combines good detection resolution with a useable acquisition range. The attenuation of ultrasonic limits the range of bat echolocation to less than 30 metres.

You will see from the above links that the signal from these piezo-electric sensors needs to be amplified by about a factor of 1000 before being cleaned-up by a comparator. I can see many problems, but no advantage, in trying to replace the ripple counter stage with a PICAXE.
 
Top