Announcement

Collapse
No announcement yet.

question regarding ITMD PI-3 source code

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

  • question regarding ITMD PI-3 source code

    void ReadSample(void)
    {
    GO = 1; // Start the conversion
    while(GO == 1); // Wait for the ADC to finish

    CurrentSample = ADRESH & 0x03;
    CurrentSample <<= 8;
    CurrentSample += ADRESL;
    CurrentSample &= 0x03FF; // Mask off 6 MSBs
    }



    I am not familiar with PIC programming so much. I am confused here that is it taking value from 0-255(8bits) or full 0-1024(10bit) values



    void ProcessSample(void)
    {
    static unsigned int sampleArray[sampleArraySize];
    static unsigned int trackArray[trackArraySize];
    static char sampleIndex = 0, trackIndex = 0;
    static unsigned int tmp = 0;
    static char i, sampleCount;

    tmp += CurrentSample; // tmp is effectively a 12-bit value
    sampleCount++;

    if(sampleCount == 4) // If we've accumulated 4 samples, then store
    {
    sampleArray[sampleIndex] = tmp>>2; // Store the current sample - 10 bits
    sampleCount = 0;
    tmp = 0;

    sampleIndex++; // Increment the array pointer
    if(sampleIndex == sampleArraySize) // If we're wrapping around...
    sampleIndex = 0; // Set the pointer back to the beginning

    SampleAve = 0;
    for(i = 0; i < sampleArraySize; i++) // Average all the samples
    SampleAve += sampleArray[i]; // This is effectively a 15-bit value

    SampleAve >>= sampleAveShift; // Divide back down to a 10-bit value

    trackArray[trackIndex] = SampleAve; // Store the average

    trackIndex++; // Increment the array pointer
    if(trackIndex == trackArraySize) // If we're wrapping around...
    trackIndex = 0; // Set the pointer back to the beginning

    TrackAve = 0;
    for(i = 0; i < trackArraySize; i++) // Average all the averages
    TrackAve += trackArray[i]; // This is effectively a 16-bit value

    TrackAve >>= trackAveShift; // Divide back down to a 10-bit value
    }
    }


    And this part is also confusing me I have read the description multiple time and also the explanation in the book but I am still confused. I trying to implement this code according to my metal detector in arduino

    If someone can give me brief explanation will help alot thanks so much.

  • #2
    What are you attempting to measure with the Arduino?
    Are you measuring the signal from the output of the sampling integrator, or direct sampling the preamp?
    A schematic would be a great help.

    Comment


    • #3
      Click image for larger version

Name:	gtr2.JPG
Views:	1
Size:	57.8 KB
ID:	361802


      this is the schematic and I am trying to measure the signal from the blue square I made

      right now i am prototyping with arduino uno but my end goal is to make pcb small so I will be using ATTiny.

      Comment


      • #4
        Originally posted by haseeb zaib View Post
        [ATTACH]55847[/ATTACH]


        this is the schematic and I am trying to measure the signal from the blue square I made
        Carl wrote the PI-3 PIC code in ITMD, so he will be able to explain in detail what he's doing there.
        I think he's using a tracking array to create a threshold which follows the sampling at a slower rate.

        I assume that VCC is the same as +5V. I've not used the ATTINY1614 before, but it appears to be able to accept either 5V or 3V3, and has a 10-bit ADC.
        If the signal from the blue square swings between 0V and VCC, then you should be able to simply read it using analogRead(), or is there a problem with that?
        The Arduino is not great at taking accurate ADC readings, but that may not be a problem since you're dealing with relative rather than absolute values. ADC resolution can also be increased in software using oversampling and decimation, but this is at the expense of time. For example I've just written some code to read a thermometer chip using an Arduino Nano, and increased the resolution to 16-bits. Luckily speed is not important as it takes 3 seconds to acquire one sample.

        Comment


        • #5
          yes the wave swings between 0V and VCC.And i am using registers so reading the wave is also not the problem, the only confusion I have and I cant find the solution that how do I descriminate the wave when metal appears, like how do I tell the controller to sound the buzzer when metal is there , I was trying to find question to this answer in Carl PI-3 source code.

          Comment


          • #6
            Originally posted by haseeb zaib View Post
            yes the wave swings between 0V and VCC.And i am using registers so reading the wave is also not the problem, the only confusion I have and I cant find the solution that how do I descriminate the wave when metal appears, like how do I tell the controller to sound the buzzer when metal is there , I was trying to find question to this answer in Carl PI-3 source code.
            Looking at the datasheet for the ATTINY, it appears to have only 1 ADC. This precludes you using an external threshold pot as you're already using the ADC to read the target signal.
            In that case you will need to take two running averages of the signal from the blue square. One of the running averages should have a large number of samples, such that it changes very slowly when compared to the main sample. In that way you can create a threshold from which to trigger an audio response. Alternatively you could add a self-adjusting threshold (SAT) circuit in hardware using just a capacitor and a resistor. This is the way most of the PI detector circuits here work.

            Comment


            • #7
              So basically I have to use same technique as Carl PI-3 code, because what I understand from it that his sample array move faster and the tracker changes slowly.

              Comment


              • #8
                Originally posted by haseeb zaib View Post
                I am not familiar with PIC programming so much. I am confused here that is it taking value from 0-255(8bits) or full 0-1024(10bit) values
                10 bits. ADRESH contains the 2 MSBs and ADRESL contains the 8 LSBs. ADRESH is bit-shifted and added to ADRESL to create a 10b value.

                And this part is also confusing me I have read the description multiple time and also the explanation in the book but I am still confused. I trying to implement this code according to my metal detector in arduino
                If someone can give me brief explanation will help alot thanks so much.
                4 successive samples are averaged and placed in a 32x "sample" array. Each time this happens, the 32 values in the array are averaged and placed in a 64x "tracking" array. The 64 values in this array are averaged to form a tracking average, and the faster-moving sample average is compared to the slow-moving tracking average to determine whether there is a target.

                Comment


                • #9
                  Thanks alot carl!

                  really appreciate it.

                  Comment

                  Working...
                  X