News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

PIC Powered Metal Detector

Started by SeanG_65, Aug 17, 2022, 03:38 AM

Previous topic - Next topic

SeanG_65

I KNOW there are many designs already out there, but I wanted to teach myself to master interrupts so I thought this would be  good way.

I have to generate;

1) A main Tx 100us long pulse every 500us (or near enough).

2) A main sample 25us long pulse between 6 to 30us after Tx goes low

3) A "ground" sample 30us long pulse approximately 120us after Tx pulse goes low

4) An "Earth Field Effect" sample 30us long pulse approximately 50us BEFORE the next Tx pulse goes high.

There is enough time break the rules and simply use DELAYUS (x) but I need to read potentiometer values as some of the delays are manually controlled.

Thinking about the task in hand I wondered if the following would be a good way;

1) Assign each delay as an array entry
2) Set up a min loop value
3) load the first array value into the timer and allow the timer to overflow
4) Process the required action based upon the array pointer (reload counter or set an output high for a DELAYUS, then low)
5) Increment array pointer
6) Do it all again

This would ensure that the time available to process ADC reads etc was maximised as each delay would no longer be stopping the PIC as using the DELAYUS would.

Any thoughts on improvements for this, or what do you Experts think of this way of generating multiple delay times?



david

Sounds a bit like a pulse induction metal detector which I did dabble with.   As you say there are adequate delays to allow the simple use of DelayuS and while this could be tidied up there are considerable issues with the hardware such as detecting mV of change right after a 400V pulse.
For what it's worth here is one of my numerous attempts to get a good sensitivity PI metal detector. 
'PI metal detection using 16F683 (8MHz)
'Using comparator for gain block and gating PWM if still high
'after the selected delay period. Using 250uS 8V pulse

'               V+ <1  U  8>  GND
' FET gate GPIO.5  <2     7>  Cin+  GPIO.0  AC iput
' ADC 3    GPIO.4  <3     6>  Cin- GPIO.1   Bias at 50mV
'  not used GPIO.3 <4     5>  PWM tone GPIO.2

        Device  12F683
        Declare Xtal 8
        Config FCMEN_OFF, IESO_OFF, BOD_OFF, CPD_OFF, CP_OFF, MCLRE_OFF, PWRTE_ON, WDT_OFF, INTOSCIO
   
        'Declare Adin_Res 10         
       'Declare Adin_Tad 4_FOSC   
       'Declare Adin_Stime 20                     
        TRISIO = %00011011         ' turn on ADC0 as input   
        OSCCON=%01110000          'set Fosc to 8MHz =0111
        T1CON=%00000000           'Tmr1 off
        CMCON0=%00000010          'turn off comparator                   
        ADCON0  = %00000001         ' Select GPIO.0 as AD, left justified (8 bits)       
        ANSEL = %01010011    'Fosc/4
        CCP1CON=%00001100          'PWM on, active high
        T2CON=%00000110            'Tmr2 On, prescale 16
        PR2=178                    'period
        CCPR1L=9                  'duty
    Symbol gate=GPIO.5        'FET drive
    Symbol tone=GPIO.2        'Gated PWM output
    'Symbol sense=GPIO.3       'Pot for sampling delay
    DelayMS 100
    GPIO.4=0
   
    Dim delay As Byte  '10 to 40uS
    Dim Potpos As Word

Begin: 
       Potpos=ADIn 3       'ADC read of pot position for sampling delay
       delay=10+ADRESH/10  'Potpos 0 to 255.  eg ADIn=117, Potpos=11+10=21
       gate=1             'FET on 
       DelayUS 180        'drive pulse duration
       gate=0             'FET off
       DelayUS delay      'delay after FET off before sampling
       'GPIO.4=1
       'DelayUS 1        'temp marker pulse only
       'GPIO.4=0
       If CMCON0.6=1 Then CCP1CON=%00001100   'If comp still high, turn on PWM
       If CMCON0.6=0 Then CCP1CON=%00000000   'If comp low, turn off PWM
       DelayUS 4800-delay
       GoTo Begin
 
  End 
  'NOTES
  'Due to diode limiters there is no amplitude variation until signal is below diode threshold

I wish you luck with your project.  I should get back on to it also.  I bought some Schottky diodes as pulse clamps and also some fast rail to rail op-amps to try but somehow got side tracked.

Cheers,
David

SeanG_65

#2
I have a novel way of getting around the flyback issue.

Conventional designs are very insensitive to gold as the initial sample time has to be around 10us and such a fast time is impossible due to the Tau of the input amplifier which invariably uses a high gain and thus goes into saturation.

The method I am using is patented by a chap called Dave Emery who is a good friend of mine and doesn't use FET blocking. Think of a diode that can conduct in REVERSE. By forward biasing an ultra fast diode such as ES1G the high voltage is blocked as the diode is reverse biased. As the voltage decays past the point of bias, the diode becomes conductive and any signal on the cathode is translated into the anode and then passed through another diode and into the amplifier.

Sampling can now occur at a very short time after Tx is turned off and makes for a VERY sensitive detector as the front end amplifier never saturates. Oh, and a snubber is also used on the coil.

Do NOT use a PICs ADC as the resolution is too low and poor depth will result. Likewise the comparator or CCP module. Keep it analogue and use low distortion amplifiers.

top204

#3
That sound like a really interesting project Sean.

I do hope you present the finished project here on the forum, because it is something I have always had an interest in as well, since I was a boy. :-)

I still remember making a very simple metal detector as a 10 or 11 year old boy. It was a BFO type and it needed a MW radio beside it, but being so young it was like magic. :-) But I could never get the screening of the coil correct, so ground capacitance always got in the way and moved the signal. LOL. I got the circuit out of the Practical Wireless magazine, in the "Take 20" section. Anyone else remember that magazine and section from back in the 1970s? That was when "Practical Wireless" was a real magazine full of circuits, and not like it is now, just full of adverts and commercial stuff that has no technical interest.

I always looked forward to dad bringing in the "Practical Electronics" magazine or the "Practical Wireless" magazine or the "Practical Television" magazine each month on his way back from work. Then we would read it together on his chair, and I would ask loads of questions. :-) Then he would read whatever magazine he had bought, in bed, then I would the next night, after he was finished with it. :-)

I did make a more advanced metal detector from the excellent ETI (Electronics Today International) magazine, back in the 1980s, and it used all analogue components and was very good. I think that was actually a pulsed metal detector.

John Lawton

See, you can go back in time courtesy of the internet:

https://worldradiohistory.com/Practical_Wireless_Magazine.htm

Enjoy PW all over again!

top204

#5
I use that site all the time, and it has a huge amount of wonderful old books and magazines on it from all over the world. :-)

It takes me back to my young days with some of the wonderful UK magazines, and some of the books I used to get out from the library as a boy, or scan through in the book shop to see if I could cover its cost with my saved up pocket money. I still love the Babani and Bernards books, but I never see them at the friday flea market or car boot sales. There was actually a Babani book named "Build your own Metal Detector". :-)

It is an excellent site and very highly recommended. Another site with huge amounts of everything is: "https://archive.org", but they are starting to get a bit devious on there recently, with having to subscribe and pay and rent a lot of the scanned old books etc... :-(

SeanG_65

#6
I've had to move to an 18F14K22 from my 16F88. I needed to change the timings of pulses to automatically optimise performance and the 88 simply couldn't cut it.

I also needed to move to floating point math to scale potentiometer values. I figured a way to do it in integer but couldn't understand my calculations next morning (seems to be happening more frequently) I solve a problem then next day I have no idea how I got there 😭.

Oh and Carl and George (forum mods) have written a great book called "Inside the Metal Detector". There's also "The Voodoo Project". Both have schematic, code Gerber's etc however, input from brilliant programmers such as ALL you guys would be greatly appreciated on Geotech. We do a LOT of collaborations.

I'm on the geotech as me and I'm more than happy to post schematics and code on here as I go along.

Thanks for the encouragement all 👍😃👍😃

SeanG_65

THis code doesn't work YET but I'm on it ;ike a rash  ;D

'****************************************************************
'*  Name    : Main Micro Code DEVICE 18F14K22.bas                *
'*  Author  : Sean Goddard                                      *
'*  Notice  : Copyright (c) 2020 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 19/08/2022                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

DEVICE = 18F14K22

CONFIG_START
  FOSC = ECCLKOUTL   ;EC, CLKOUT function on OSC2 (low)
  PLLEN = ON   ;Oscillator multiplied by 4
  PCLKEN = ON   ;Primary clock enabled
  FCMEN = OFF   ;Fail-Safe Clock Monitor disabled
  IESO = OFF   ;Oscillator Switchover mode disabled
  PWRTEN = OFF   ;PWRT disabled
  BOREN = SBORDIS   ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 27   ;VBOR set to 2.7 V nominal
  WDTEN = OFF   ;WDT is controlled by SWDTEN bit of the WDTCON register
  WDTPS = 32768   ;1:32768
  HFOFST = OFF   ;The system clock is held off until the HFINTOSC is stable.
  MCLRE = ON   ;MCLR pin enabled, RA3 input pin disabled
  STVREN = ON   ;Stack full/underflow will cause Reset
  LVP = OFF   ;Single-Supply ICSP disabled
  BBSIZ = OFF   ;1kW boot block size
  XINST = OFF   ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  DEBUG = OFF   ;Background debugger disabled, RA0 and RA1 configured as general purpose I/O pins
  CP0 = OFF   ;Block 0 not code-protected
  CP1 = OFF   ;Block 1 not code-protected
  CPB = OFF   ;Boot block not code-protected
  CPD = OFF   ;Data EEPROM not code-protected
  WRT0 = OFF   ;Block 0 not write-protected
  WRT1 = OFF   ;Block 1 not write-protected
  WRTC = OFF   ;Configuration registers not write-protected
  WRTB = OFF   ;Boot block not write-protected
  WRTD = OFF   ;Data EEPROM not write-protected
  EBTR0 = OFF   ;Block 0 not protected from table reads executed in other blocks
  EBTR1 = OFF   ;Block 1 not protected from table reads executed in other blocks
  EBTRB = OFF   ;Boot block not protected from table reads executed in other blocks
CONFIG_END

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

XTAL = 20

SYMBOL TMR0IE           INTCON.5
SYMBOL TMR0IF           INTCON.2
SYMBOL GIE              INTCON.7
SYMBOL PS0              T0CON.0
SYMBOL PS1              T0CON.1
SYMBOL PS2              T0CON.2
SYMBOL PSA              T0CON.3
SYMBOL T0CS             T0CON.5
SYMBOL T08BIT           T0CON.6
SYMBOL TMR0ON           T0CON.7

SYMBOL Tx_P             PORTB.0
SYMBOL S1               PORTB.1
SYMBOL GS               PORTB.2
SYMBOL ES               PORTB.3
SYMBOL SDR              PORTB.4

ANSEL = %00011111

TRISB = %00000000

DIM ARRAYPOS            AS BYTE
DIM Del_Val[4]          AS FLOAT
DIM Pls_Wdth[4]         AS WORD
DIM Pot1                AS WORD
DIM Pot2                AS WORD
DIM Pot3                AS WORD
DIM Pot4                AS WORD
DIM WDR                 AS FLOAT

'CTR_Val = 108

PORTB = %11111111
DELAYMS 500           ' Wait for things to stabilise
PORTB = %00000000

ON_HARDWARE_INTERRUPT Process_Interrupt

Tx_P  = 0             ' Make sure main FET is NOT on
S1    = 0             ' Sample_1 LOW
GS    = 0             ' GROUND Sample LOW
ES    = 0             ' EFE Sample LOW
SDR   = 0             ' Audio Output LOW (may end up being PWM channel driving a counter IC al la Tesoro)


GOTO Over_Interrupt

'* This is a simple routine to test the timer is working. Array pointer handling and reset needs to be added

Process_Interrupt:
CONTEXT SAVE
TMR0IF = 0
TIMER0 = Del_Val[0]
HIGH Tx_P
DELAYUS 100
LOW Tx_P
DELAYUS 15
HIGH S1
DELAYUS 20
LOW S1
'TMR0 = CTR_Val
CONTEXT RESTORE

Over_Interrupt:

T08BIT = 0               ' Set Timer0 to 16bit mode
GIE    = 0               ' General Interrupts DISABLED
PSA    = 0               ' Assign Prescaler to WDT (1:1)
PS0    = 1               '
PS1    = 1               ' Set Clock Divisor to "1:1"
PS2    = 0               '
T0CS   = 0               ' Timer0 Clock Select 1 = EXT. 0 = INT
TMR0IE = 1               ' Enable Interrupts for Timer0
GIE    = 1               ' General Interrupts ENABLED (LET'S ROCK)

'* This is the main code area to read pots and change array entries for Timer0 values at each stage of the 4 pulses to be generated *
'* LOTS more to go in here

WHILE 1 = 1

Pot1 = ADIN(0)
Pot2 = ADIN(1)
Pot3 = ADIN(2)
Pot4 = ADIN(3)


WEND

SeanG_65

#8
Still in the "Dodge the magic smoke" stage

PI PROTO.pdf

Front end amplifier is a AD8597ARZ (at the moment)

david

Is that a resonant pulse induction system rather than the standard pulse induction type?   D6 is a bit of a giveaway and wouldn't be used in a traditional pulse induction circuit.   Also, rather than clamping the back EMF with diodes until the level has dropped below the diode threshold you have used a classic two diode analog transmission circuit (D4, D5). I assume those 10R resistors are place holders and not actual circuit values. I think few people have come across this switch/attenuator circuit but it works well for low level signals which is what  we're dealing with here.  Good luck with the project.

Cheers,
David 

david

Here'a link to a very simple PIC based resonant pulse induction project if anyone is interested.
https://www.digiwood.ee/8-electronic-projects/2-metal-detector-circuit

Cheers,
David

SeanG_65

#11
Nope, it's not resonant. The Res/diode/cap is a snubber which stop the FET from avalanching and thus makes recovery time a lot faster consequently helping the faster sampling time.

The 10R are fixed and help keep any Tx pulse off the supply rails which in turn makes for a very stable threshold and thus the user will be able to hear faint signals more easily.

The analogue circuitry isn't done yet, but if you Google "Whites surfmaster schematic" you will get an idea where I am heading except there is an additional integrator to handle the EFE

david

OK but it looks to me that D6 is added to stop the substrate diode of Q4 from clamping the ringing search coil.
I was also curious about R7 and R12 being 10R along with D5 all across +5V.  That's a bit more than the 2mA bias mentioned which would be more typical.
So I guess the next stage is all about the detector and discrimination circuitry.   Good luck.

David

SeanG_65

#13
Ah, yes, those are placeholders they are SOT
(select on test) I had the wrong 10R's.
As some components are on stupid lead times I can only simulate. Yes you are correct re the function of the diodes. Trust me, it DOES work...sort of 😁


Did anyone ever see the PE Magnum by Andy Flind? Andy was a hero of mine when I was learning electronics. Imagine my excitement when I found he lived just up the road from me in Taunton. We became good friends until he sadly passed away from asbestosis. At the time I smoked and Andy begged me to give up, he said "You don't want to die like this". I stopped the next day.

david

OK.
I know of the PE Magnum but not the man behind it. 
I think watching someone slowly die from asbestosis would be a fairly compelling reason to give up smoking. He may have saved your life even if he couldn't save his own.

David
 

charliecoutas

Many years ago  I made a simple metal detector (hetrodyne I think). My local pub was The Bell at Aldworth and I  took it there with a view to discovering a vast fortune in the fields nearby. "Let's test it" said Ian, the landlord. Somebody hid a 50 pence coin in the gravel outside and off I went: up and down. I didn't find it.

"Jack" was then sent out with his two right-angle bent, welding rods. On the second pass he bent down, rummaged in the gravel and picked up the coin. I didn't believe dowsing was a real thing then but now I'm not so sure.

Good luck, tell us all about it please.

Charlie

SeanG_65

I know a lot of people cannot accept dowsing works because there is no scientific explanation of how, but I have witnessed it many times.

I have given up explaining so many things, like a Rainbow is just diffraction. Who cares, it's beautiful? Sit and watch a spider spin a web or bees on flowers. I just accept the wonder of these things.

David, I think Andy did. He went from being someone who used to run up Snowdon to a skeleton with skin in a matter of four weeks. I could not refuse the wish of a dying man. Andy was a true Gent and self taught in electronics and programming.

SeanG_65

If anyone is interested in metal detectors etc, take a look at The Geotech Forum https://www.geotech1.com/forums/forum.php

They are a GREAT bunch, and will always listen to ideas and help make them a reality.

RGV250

Hi Les,
QuoteThere was actually a Babani book named "Build your own Metal Detector".

£107  https://www.amazon.co.uk/Treasure-Locators-Bernards-Babani-electronics/dp/085934035X

top204

#19
£107 !!!!!!!!!

I know amazon have always been greedy crooks, but that is just utter stupidity. :-)

That book is one of my prized posessions, along with my other lovely Babani and Bernards books. I bought it when I was a young-un and built my own metal detectors from it, and based around the circuits in it.

The book, in PDF format, can be downloaded from here:

Metal and Treasure Locators