Announcement

Collapse
No announcement yet.

Announcement

Collapse
No announcement yet.

Modified sketch for improved timing precision.

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

  • SaltyDog
    replied
    Originally posted by Teleno;
    This second mod connects the output of the amplifier (TP10) to analog input A1 of the Nano via a resistor divider. 56k from TP10 to A1, and 120k from A1 to GND. This limits the max. voltage at the analog pin to 5V.
    Hmm, doesn't the analog voltage at TP10 cover +-5v ? The A1 input of the uP will only except positive 0..5v, are you relying on the uP input protection diode clipping the negative?

    Leave a comment:


  • Teleno
    replied
    Originally posted by SaltyDog View Post
    Presume connections are:
    SDA -> A4
    SCL -> A5 ?
    Yup

    Leave a comment:


  • SaltyDog
    replied
    Presume connections are:
    SDA -> A4
    SCL -> A5 ?

    Leave a comment:


  • Teleno
    replied
    Originally posted by SaltyDog View Post
    Be interested in the display code, please post the code when you are ready. At the moment I am just marking the pot, were it is sensitive to gold, but would be good to get exact numbers ..
    Here's the display code.

    Place this snippet at the beginning of the sketch

    PHP Code:
    #define USE_OLED

    #ifdef USE_OLED
      #include <Tiny4kOLED.h>
      #include <font16x32digits.h>
      
    const DCfont *largeFont FONT16X32DIGITS;
      const 
    DCfont *smallFont FONT8X16;
      
    uint8_t width 128;
      
    uint8_t height 32;
    #endif​ 


    This snippet at the beginning of setup()

    PHP Code:
    #ifdef USE_OLED
      
    oled.begin(widthheightsizeof(tiny4koled_init_128x32br), tiny4koled_init_128x32br);
      
    oled.setFont(smallFont);
      if (
    smallFont->width == 0) {
        
    oled.setSpacing(1);
      } else {
        
    oled.setSpacing(smallFont->spacing 1);
      }
      
    oled.on();
      
    oled.clear();
      
    oled.setCursor(02);
      
    oled.print("DELAY");
      
    oled.setCursor(00);
      
    oled.print("us");
      
    oled.setFont(largeFont);
      if (
    smallFont->width == 0) {
        
    oled.setSpacing(1);
      } else {
        
    oled.setSpacing(largeFont->spacing 1);
      }
    #endif​ 


    and this snippet in the loop()

    PHP Code:
    #ifdef USE_OLED  
        
    oled.setCursor(700);  
        
    oled.print(mainDelay);
        
    oled.print(" ");
    #endif​ 


    This is what you'll get

    Click image for larger version  Name:	20240210_215145.jpg Views:	0 Size:	57.1 KB ID:	420154

    If you won't use the OLED comment out the "#define USE_OLED" line and rebuild. Otherwise Nano will wait forever for a display to be ready that doesn't exist.

    Install the following libraries in Arduino (using search box)

    Tiny4kOLED
    TinyOLED-Fonts

    The display is 0.91 inch OLED 128x32 based on controller SSD1306. Like this one: https://www.aliexpress.com/item/1005006431809403.html?

    Leave a comment:


  • Teleno
    replied
    To the administrators: Please delete my post #40 or replace it with this post. The resistor values shown were wrong and it could cause damage to the Nano board.

    This is a second mod to allow not only increases in volume in the presence of a target, but also increases in pitch (frequency + ampitude modulation). The human ear is much more sensitive to changes in pitch than in amplitude, so this feature can result in an improved detection experience.

    [ATTACH]n420152[/ATTACH]

    To use the attached sketch you'll have to do the PWM mod first (swapping pins 8 and 10) as explained on page 3, post #15

    This second mod connects the output of the amplifier (TP10) to analog input A1 of the Nano via a resistor divider. 56k from TP10 to A1, and 120k from A1 to GND. This limits the max. voltage at the analog pin to 5V.

    Click image for larger version  Name:	Mod_frequency.png Views:	0 Size:	503.6 KB ID:	420149

    If the frequency excursions are not broad enough try replacing this line:

    PHP Code:
    word freq map(target101024FREQ_MINFREQ_MAX); 
    with this:

    PHP Code:
    word freq map(target5121024FREQ_MINFREQ_MAX); 

    Leave a comment:


  • SaltyDog
    replied
    Originally posted by Gunghouk View Post

    Couldn't you initially serial print to a laptop to see the values in a bench setting? If the pot value is enough then put a DVM on the wiper and measure using a 10 turn pot.
    No, this must be done outside in the field, as inside there is too much interference from metal and electronic noise.

    Leave a comment:


  • Teleno
    replied
    Originally posted by SaltyDog View Post
    Be interested in the display code, please post the code when you are ready. At the moment I am just marking the pot, were it is sensitive to gold, but would be good to get exact numbers ..
    I will. But that's anything anyone here could do, since the loop() is fully available. Find a display of choice, get the library and insert the code in the sketch. It doesn't matter how heavy the library is cause the MCU here does basically nothing and the memory use is minimal.

    you could even add a videogame too )

    With this sketch you can set the default main sample delay all the way down to zero. There is no latency. Just edit the define "defMainDelay" to be as early as your coil allows

    Leave a comment:


  • SaltyDog
    replied
    Originally posted by Teleno View Post

    Actually I've attached a 128x32 OLED and can see the delay in real time. My eyes are not so good anymore so I'm looking for big fonts. Will post the code when I'm satisfied with it.
    Be interested in the display code, please post the code when you are ready. At the moment I am just marking the pot, were it is sensitive to gold, but would be good to get exact numbers ..

    Leave a comment:


  • Teleno
    replied
    This is a second mod to allow frequency modulation depending on tatget strength. You'll get a signal that not only increases in volume in the presence of a target, but also increases in pitch.

    Aduino_PI2_F_modulation.zip

    To use the attached sketch you'll have to do the PWM mod first (swapping pins 8 and 10) as explained on page 3, post #15

    This second mod connects the output of the amplifier (TP10) to analog input A1 of the Nano via a resistor divider. 47K from TP10 to A1, and 56K from A1 to GND. This limits the max. voltage at the analog pin to 5V.

    Click image for larger version

Name:	Mod_frequency.png
Views:	249
Size:	503.3 KB
ID:	420138



    If the frequency excursions are not broad enough try replacing this line:

    PHP Code:
    word freq map(target101024FREQ_MINFREQ_MAX); 
    with this:

    PHP Code:
    word freq map(target6001024FREQ_MINFREQ_MAX); 

    Leave a comment:


  • Gunghouk
    replied

    Leave a comment:


  • Teleno
    replied
    Originally posted by Gunghouk View Post
    Another thought couldn't the audio frequency be tied to the delay setting?
    ... my search for relief from retirement boredom.
    We're on the same boat.
    Certainly you can fiddle with the audio frequency, but keep in mind that it uses Timer2 wich is also used by Arduino's analogWrite(), so it will break this function. Anyway it's not used anywhere in the sketch, so that isn't a problem for this project.

    So here's some code. Add these lines to the setup() function

    PHP Code:
    /**
    * URL: https://dbuezas.github.io/arduino-web-timers/#mcu=ATMEGA328P&timer=2&timerMode=CTC&topValue=OCR2A&OCR2A=126&CompareOutputModeA=toggle&clockPrescalerOrSource=128
    * Mode : CTC
    * Period : 1 ms
    * Frequency: 1 kHz
    * Outputs :
    * - B3: 50.00%, toggle
    */

      
    TCCR2A << COM2A0 << WGM21;
      
    TCCR2B << CS22 |<< CS20;
      
    DDRB |= << DDB3;
      
    OCR2A 127;​ 

    Delete or comment out this line:
    PHP Code:
    analogWrite(audioPin127);     // Set audioPin with 50% duty cycle PWM 

    ​The value OCR2A sets the frequency. A value of 128 gets you 490 Hz. A value of 60 gets you 1Khz, and proportionally the other values in between.
    So if you want the mainSample delay to modulate the tone you map the values like this:

    Place this line in the loop().
    PHP Code:
    OCR2A map(mainDelaydefMainDelay2060128); 

    Then you'll hear 1 KHz at minimum delay of 10us and gradually decreasing to 490 Hz at delay 20us. Set the limits as you will.

    Leave a comment:


  • Gunghouk
    replied
    Another thought couldn't the audio frequency be tied to the delay setting?

    You'll have to excuse any dumb or obvious statements I make as this is my first excursion into metal detecting and Arduinos as part of my search for relief from retirement boredom.

    Leave a comment:


  • Gunghouk
    replied
    Originally posted by Teleno View Post

    Will post the code when I'm satisfied with it.
    Will post some gold when I'm satisfied with your code

    Leave a comment:


  • Teleno
    replied
    Originally posted by Gunghouk View Post

    Couldn't you initially serial print to a laptop to see the values in a bench setting?
    Certainly, now just send me some gold, haha!
    Actually I've attached a 128x32 OLED and can see the delay in real time. My eyes are not so good anymore so I'm looking for big fonts. Will post the code when I'm satisfied with it.

    Leave a comment:


  • Gunghouk
    replied
    Originally posted by Teleno View Post
    Nice teamwork! Huge shoutout to you for fearlessly rewiring your box and patiently testing multiple versions of my mod. Without your feedback I couldn't have ironed out the devilish details.

    Curious about how the sensitivity with this mod compares to previous.

    What you say about the delays and gold, it's probably time to populate the now deserted loop() with code to drive some cheap I2C OLED display from the Chinese supplier and visualize what the actual delays are. We then can tune the range in code.
    Couldn't you initially serial print to a laptop to see the values in a bench setting? If the pot value is enough then put a DVM on the wiper and measure using a 10 turn pot.

    Leave a comment:

Working...
X