Go Down

Topic: Maximum Sample rate (Read 1 time) previous topic - next topic

dtu89

Hey All

Iam currently doing a project were i have to detect cars with a magnetic sensor which is controlled by an Arduino Duemilanove.
I have a question regarding the sample rate of the Atmega168. Is it right that the Atmega168 maximum sample rate is 10Khz?
And how is it possible to set it to an higher sample rate if needed.

Thanks

The magnetic sensor is either open or closed, so its digital?
Digital pins can be sampled faster than 10 KHz, which is 100uS/sample, or sample every 1600 clock cycles.

AWOL

Even if you use analogue input, it is possible to get a higher sample rate, at the expense of lower resolution.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grumpy_Mike

Quote
Iam currently doing a project were i have to detect cars with a magnetic sensor

OK cars are generally not magnetic so how is it going to work?

Quote
Is it right that the Atmega168 maximum sample rate is 10Khz?

No, that is the rate for an analogue 10 bit sample, go down to 8 bits and it will go faster. Go digital and faster still.
How fast are these cars going anyway!!!

dtu89

Okey so i found this guy which shows 3 ways how to get ur sample rate higher. Which example should i go after..

link: http://dam.mellis.org/Mellis%20-%20Sensor%20Library%20for%20Arduino%20-%20Paper.pdf

dtu89

Because vehicles contain ferrous metales (iron, steel, nickel cobalt)

AWOL

Quote
Which example should i go after..

The one that works best for you.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

MarkT

Well this isn't relevant now, but in case anyone else is wondering:

The default analog clock speed is 125kHz, and sampling takes 13 clocks I think.  You can make the clock faster, and the accuracy will then
suffer somewhat.  Also the signal being sampled will need to be a lower impedance to drive the sample/hold capacitor quicker.

To set the clock on the 328 to faster frequencies:
Code: [Select]

 ADCSRA = (ADCSRA & 0xF8) | val ;


Where val = 7 for 125kHz (about 10kHz conversion rate, 10k input impedance, default, accuracy < +/- 2 LSB
val = 6 for 250kHz (about 20kHz conversion, 5k input impedance, accuracy +/- 2LSB)
val = 5 for 500kHz (about 40kHz conversion, 2.5k input impedance, accuracy +/- 3LSB)
val = 4 for 1MHz, 80kHz conversiom, 1k input impedance, accuracy about +/- 4.5 LSB
[ I won't respond to messages, use the forum please ]

Grumpy_Mike


Because vehicles contain ferrous metales (iron, steel, nickel cobalt)

It does not make them magnets nor detectable with a magnetic detector. What sort of sensor are you thinking of, you will get no joy out of a hall effect sensor.

dtu89

#9
Dec 10, 2012, 05:03 pm Last Edit: Dec 10, 2012, 05:12 pm by AWOL Reason: 1
MY code looks like this.. where should i place the code which makes sample rate faster?? (iam new at this):
Code: [Select]

/*
 Analog input, analog output, serial output

Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.

The circuit:
* potentiometer connected to analog pin 0.
  Center pin of the potentiometer goes to the analog pin.
  side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground

created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe


*/

// These constants won't change.  They're used to give names
// to the pins used:
const int analogInPinA = A0;  // Analog input pin that the potentiometer is attached to
const int analogInPinB = A1;  // Analog input pin that the potentiometer is attached to

const int analogOutPin = 9; // Analog output pin that the LED is attached to

int outputValueA = 0;  
int outputValueB = 0;  
int oldValueA = 0;
int oldValueB = 0;
int countSame = 0;
int vehicle = 0;
int wait = 0;
int changes = 0;
int led = 10;
int vset;
int i, imax =10;
void setup() {
 // initialize serial communications at 9600 bps:
 Serial.begin(9600); //9600
 /*pinMode(led, OUTPUT);
 digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(10);               // wait for a second  
 digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
 delay(10);               // wait for a second  
 digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(10);*/
}

int valueChanged(int newValueA, int oldValueA, int newValueB, int oldValueB)
{
 int check = 1;
 int diff = 40;
 if(newValueA < (oldValueA+diff) && newValueA > (oldValueA-diff) && newValueB < (oldValueB+diff) && newValueB > (oldValueB-diff))
  check = 0;
 return check;
}



void logDataScreen(int newValueA, int newValueB)
{
 // print the results to the serial monitor:
 Serial.print("sensor A = " );
 Serial.print(newValueA);      
 Serial.print("\t sensor B = " );
 Serial.println(newValueB);
}
int getData(const int analogInPin)
{
 int sensorValue = 0;        // value read from the pot
 // read the analog in value:
 sensorValue = analogRead(analogInPin);  //Mulig returværdi?
 // map it to the range of the analog out:
 //return map(sensorValue, 0, 1023, 0, 1023);
 return sensorValue;
}


void loop() {
 outputValueA = getData(analogInPinA);
 outputValueB = getData(analogInPinB);
 /*for(i=0;i<imax;i++)
 {
   outputValueA += getData(analogInPinA);
   outputValueB += getData(analogInPinB);
 }
 outputValueA /= (imax+1);
 outputValueB /= (imax+1);*/
 
 
 if(valueChanged(outputValueA, oldValueA, outputValueB, oldValueB))
 {
     countSame=0;
     changes++;
     oldValueA = outputValueA;
     oldValueB = outputValueB;
 }
 else
   countSame++;
   

 logDataScreen(outputValueA, outputValueB);  
 

 
 if(countSame>=10) //Muligvis højere værdi
 {
   countSame = 0;
   if(changes > 1) //Kan
     vehicle++;
   changes =0;
   
   Serial.print("Antal Biler" );
   Serial.print(vehicle);
   Serial.print("\n" );      
   wait = 1;
   
   while(wait==1)
   {
       outputValueA = getData(analogInPinA);
       outputValueB = getData(analogInPinB);
       
         if(valueChanged(outputValueA, oldValueA, outputValueB, oldValueB))
         wait=0;    
   }
   changes++;
   logDataScreen(outputValueA, outputValueB);
 }

 
 
 // wait 2 milliseconds before the next loop
 // for the analog-to-digital converter to settle
 // after the last reading:
 delay(50);                    
}


Moderator edit: Code tags. Again.

dtu89



Because vehicles contain ferrous metales (iron, steel, nickel cobalt)

It does not make them magnets nor detectable with a magnetic detector. What sort of sensor are you thinking of, you will get no joy out of a hall effect sensor.
Its a AMR magnetic sensor from honeywell (HMC1052)

AWOL

Quote
where should i place the code which makes sample rate faster?

In "setup ()".

Please use code tags when posting code.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grumpy_Mike

Code: [Select]
// wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle

You don't have to do this. Or if you do the this delay is in the wrong place to achieve what you want to do.

Assuming yo are sampling at 10KHz, that is one sample every 0.1mS. So in order to miss a car, assuming it is 10' long, it has to be going at just over 18.9 miles a second.

dtu89


Code: [Select]
// wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle

You don't have to do this. Or if you do the this delay is in the wrong place to achieve what you want to do.

Assuming yo are sampling at 10KHz, that is one sample every 0.1mS. So in order to miss a car, assuming it is 10' long, it has to be going at just over 18.9 miles a second.

soo is it better to ignore that line?

Grumpy_Mike

Quote
soo is it better to ignore that line?

Well removing it is not going to change what is happening and you don't waste 2mS per loop.

Go Up