Announcement

Collapse
No announcement yet.

Signal synthesis for simple PI detector

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Signal synthesis for simple PI detector

    This is one of my early attempts, more like educational example.
    Code is based on previous Joop's work.
    I just made adaptation for Barracuda PI metal detector.
    I will use this occasion too; to place big THANKS and tribute to previous Joop's work!
    Code is pretty much self explanatory. Also Joop added essential comments in it.
    I think there is no need me to add anything above.


    Code:
    #include <Wire.h> 
    #include <LiquidCrystal_I2C.h>
    #include <LCDBitmap.h>
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    LCDBitmap bitmap(&lcd, 12, 0);
    
    #define DIGITAL_OUT PORTB
    #define TX_PIN_A 5       // 13     
    #define SAMPLE_PIN_B 4   // 12 
    #define SAMPLE_PIN_C 3   // 11
    
    unsigned int Sample1Delay = 65295;
    static int value;
    static int Mikrosekunde;
    
    void setup ()
    {
    Init (); 
    InitTimer2 ();
    InitTimer1 ();
    TCNT2 = 200; 
    //*********************
    Serial.begin(1200);
     lcd.begin(16,2);
     lcd.clear ();
     lcd.setCursor(2, 0);
     lcd.print("BARRACUDA");
     //**************************************************
     bitmap.begin();  
     bitmap.home();
     for (byte x=0; x<=4; x++) 
      {
        bitmap.line(x, BITMAP_H-1, x+BITMAP_H-1, 0, ON, NO_UPDATE);  
        bitmap.line(x, 0, x+BITMAP_H-1, BITMAP_H-1, ON, NO_UPDATE);  
      }
      bitmap.update();  
    }
    void VoidDelay (unsigned int n)
    {
    n += 12; 
    TCNT1 = n; 
    bitSet (TIFR1, TOV1);
    while (!(TIFR1 & (1<<TOV1))) {;} 
    }
    void loop ()
    {
          lcd.setCursor(0, 1);
          lcd.print("D=");
          lcd.print(Mikrosekunde);
          lcd.print("uS ");
          delay(50);
    }
    void InitTimer1 (void)
    {
    TCCR1A = 0;
    TCCR1B = 0;
    bitClear (TIMSK1, TOIE1); 
    TCNT1 = 0; 
    TCCR1B = 0x01; 
    }
    void InitTimer2 (void)
    {
    TCCR2A = 0;
    TCCR2B = 0;
    bitSet (TIMSK2, TOIE2); // Enable Timer2 interrupt, TIMSKx, Timer/Counter Interrupt Mask Register
    TCCR2B = 0x05; // Prescaler = /128 (8 us resolution)
    }
    void Init (void)
    {
    DDRB = B00111111; 
    }
    void ReadDelayPot (void)
    {
    value = analogRead(A0);
    Sample1Delay = 65535 - 16 - value; 
    Mikrosekunde = (65535 -Sample1Delay)/16;
    }
    ISR (TIMER2_OVF_vect)
    {
    TCNT2 = 47; 
    //******************************** MAIN PULSE - TX ******************************
    DIGITAL_OUT |= (1<<TX_PIN_A);                   
    VoidDelay (63935);  // 65535-63935=1600, 1600/16=100uS
    DIGITAL_OUT &= ~(1<<TX_PIN_A);                   
    //*******************************************************************************
    //******************************** MAIN DELAY ***********************************
    VoidDelay (Sample1Delay); // Main Delay pauza
    //*******************************************************************************
    //****************************** MAIN DELAY PULSE *******************************
    DIGITAL_OUT |= (1<<SAMPLE_PIN_B);               
    VoidDelay (64850); // 65535-64850=685, 685/16=42,8125 uS
    DIGITAL_OUT &= ~(1<<SAMPLE_PIN_B);             
    //*******************************************************************************
    //******************************** EF DELAY *************************************
    VoidDelay (65135); // 65535-65135=400, 400/16=25uS
    //*******************************************************************************
    //****************************** EF DELAY PULSE *********************************
    DIGITAL_OUT |= (1<<SAMPLE_PIN_C);                  
    VoidDelay( 64850); // 65535-64850=685, 685/16=42,8125 uS
    DIGITAL_OUT &= ~(1<<SAMPLE_PIN_C); 
    //******************************************************************************* 
    //******************************** EF+TX DELAY **********************************
    VoidDelay( 64850); // 65535-64850=685, 685/16=42,8125 uS
    //*******************************************************************************
    ReadDelayPot();
    }

  • #2
    This is the supporting circuit, explaining the code:

    Click image for larger version

Name:	Barracudaavr.JPG
Views:	1
Size:	347.5 KB
ID:	352783

    Comment


    • #3
      Pay attention on this: "LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);"
      And the value "0x27".
      It is the address of adapter used to drive parallel LCD16x2 via I2C.
      Not all similar adapters are having the same address.
      You'll have to find out the proper address of I2C adapter you'll use.
      How?
      http://www.geotech1.com/forums/showt...737#post252737

      Comment


      • #4
        Nice but What Processor???
        The processor block in the schematic is blank.

        I used a PIC16F88 for my Hammer Head which does what yours does.
        A processor is a great way to go for PI detectors instead of all the timer chips and allows easy changes to timing.

        Comment


        • #5
          Originally posted by waltr View Post
          Nice but What Processor???
          The processor block in the schematic is blank.

          I used a PIC16F88 for my Hammer Head which does what yours does.
          A processor is a great way to go for PI detectors instead of all the timer chips and allows easy changes to timing.
          Atmega328P. Pinout is for Arduino UNO, Mini Pro, Nano...
          Arduino IDE is the compiler.

          Comment


          • #6
            Output Transister a MPSA 13 ?

            Comment


            • #7
              Originally posted by homefire View Post
              Output Transister a MPSA 13 ?

              I believe so. I had MPSA14 at the time.
              BC517 will do the same.

              Comment


              • #8
                Digital part is quite alright, providing pretty precise timings.
                I simply replaced 40106 with Arduino and performed series of testings.
                It is the "hardware" which needs a bit of improving. To be able to provide properly what's coming from digital part.
                I hadn't enough time to do that. At the time.
                So i got situation to adjust "1uS" sample delay at digital part. Precisely.
                But i seriously have doubts that hardware really follows that.
                It was back than, several years ago. Since that i did nothing on that subject.
                I even had short video, posted on Yotube... than removed, by me... can't recall the reason why...
                Now i can't find that video on my backup disks.
                Point is; code is tested and alright. Providing quite precise timings.
                Task; to work around the hardware and improve it for shorter delays.
                As i recall; i got significant detection improvements on small targets at 9uS adjusted delay.
                Was it real 9uS on hardware? I do seriously doubt that.
                This is now open project. Public domain. More conversant people can join and try to improve the hardware part.
                Welcome!

                Comment


                • #9
                  "...value = analogRead(A0);..."

                  And on schematic is A3 used for pot reading.
                  So...
                  Correct in code:
                  "...
                  value = analogRead(A3);..."

                  Reason for this is because i had "trillion" of versions on each of my works i did so far.
                  Sometimes you learn through the work. Sometimes you make skim decisions and later you forgot to correct in documentation.
                  But it is not a problem at all. Everything is later easy to adjust in code.


                  Comment


                  • #10
                    "'' Was it real 9uS on hardware? I do seriously doubt that. ""

                    The processor is doing way more then just a timing simple loop. Any other functions are causing inherent delays. All of those commands ( Execution Times ) need to be added in the over all time train.

                    Add up the propagation delays through all Fets and Op Amp, Transistors.

                    Your actual realized timing may have been a Multiple or a Fraction ( If it jumped Timing ) of your set 9uS ?

                    Comment


                    • #11
                      I agree; hardware part is weaker point here, need improvements.
                      As for code, when interrupt occurs; Atmega fires up the sequence which is pretty correct in timings.
                      I stopped there because i didn't solve the problem of "third" pwm pin which i'll need if later want to add second channel on detector.
                      If you analyze the sequence; you'll notice the schedule:
                      100uS + pot adjusted delay + 42.8125uS + 25uS + 42.8125uS + 42.8125uS = 253.4375uS + pot adjusted delay.
                      Plenty spare time till 1666.667us. That time can be used to play with LCD, other free pins on Atmega etc.
                      It's the Atmega328 architecture. I could use only those 2 pins internally tied to active timer.
                      I guess it is solvable. But i stopped than and never continued later.
                      But one thing is for sure; when sequence fires up: all the calculated times are pretty correct.
                      So, "9uS" are real 9uS within the sequence, unfortunately not real in hardware.

                      Comment


                      • #12
                        Ivconic,
                        take a look on this:
                        https://wp.josh.com/2015/03/05/the-p...shots-on-avr8/

                        Comment


                        • #13
                          Originally posted by Altair View Post
                          Dang! Blast!
                          COOL!
                          I will take time tonight to try to completely understand that!
                          Hell interesting!
                          THANKS!

                          Comment


                          • #14
                            You have a few good threads here on using Arduino for Timing in a PI detector.
                            These are readily available, I even have a few, and easy to code and use.

                            Good stuff.

                            Comment


                            • #15
                              Originally posted by ivconic View Post
                              Dang! Blast!
                              COOL!
                              I will take time tonight to try to completely understand that!
                              Hell interesting!
                              THANKS!

                              My pleasure, a little contribute to your huge effort to all projects!
                              I have used that in my MD experimentation with great success!

                              Comment

                              Working...
                              X