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.
{
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.
Comment