High frequency measuring

Hi everyone,

I am using a color sensor that has a square signal which varies on frequency as an output. The duty cycle is allways 50%, the freq is the only thing that changes. I need to read two frequency values: 440kHz and 540kHz.
I have read a lot of posts but I have not found a solution. So far I have tried with the “pulseIn” function but it gives me the same frequency for both readings.

Can anyone help me please?

Thanks,

Martin

Ps: I don’t know if it matters but the sensor is the TCS3200

int taosOutPin = 11;//pinC
//int LED = 13;//pinD
void setup() {
//pinMode(LED,OUTPUT); //LED pinD
pinMode(taosOutPin, INPUT);
Serial.begin(115200);
Serial.print("\n\n\nready\n\n\n");
delay(100);
}
// primary loop takes color readings from all four channels and displays the raw values once per second.
void loop() {
detectColor(taosOutPin);
Serial.print("\n\n\n");
//delay(1000);
}
int detectColor(int taosOutPin){
float white = colorRead(taosOutPin,0,1);
Serial.print("white ");
Serial.println(white);
}
/*
This section will return the pulseIn reading of the selected color.
taosOutPin is the ouput pin of the TCS3200.
*/
float colorRead(int taosOutPin, int color, boolean LEDstate){
//setting for a delay to let the sensor sit for a moment before taking a reading.
//int sensorDelay = 100;
// create a var where the pulse reading from sensor will go
float readPulse;
// turn LEDs on or off, as directed by the LEDstate var
/*if(LEDstate == 0){
digitalWrite(LED, LOW);
}
if(LEDstate == 1){
digitalWrite(LED, HIGH);
}
*/
// wait a bit for LEDs to actually turn on, as directed by sensorDelay var
//delay(sensorDelay);
// now take a measurement from the sensor, timing a low pulse on the sensor’s “out” pin
readPulse = pulseIn(taosOutPin, LOW, 80000);
//if the pulseIn times out, it returns 0 and that throws off numbers. just cap it at 80k if it happens
if(readPulse < .1){
readPulse = 80000;
}
// return the pulse value back to whatever called for it…
return readPulse;
}

440kHz and 540kHz.
1/440000 = 2.72uS too fast for pulse in.

Options:
Run the signals thru a low pass filter, get a DC-ish level out and read in via ADC.
http://sim.okawa-denshi.jp/en/CRlowkeisan.htm
Set for say 490kHz; 540KHz will have lower output level than 440 KHz.

Use a counter input, count the number of pulses that occur in 1mS.
440 & 540. Both will wrap around on an 8-bit counter - so ~185 & ~285 get returned instead.

You can use a frequency to voltage converter IC:

This looks interesting:
The function which is used to measure the frequency of TCS3200 is named TCSMeasure()...
http://extremeelectronics.co.in/avr-tutorials/interfacing-tcs3200-colour-sensor-with-avr-atmega32/

Or you can use this...

There is a library:
http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/

Why make things so complicated?

Complicate than what?

Then just measuring the DC level from a low pass filter.

I think software library is more simple solution than hardware filtering. Software counter could give 1 Hz resolution, or even 0.1 Hz over 10 sec counting interval, the same time 1-st order RC could only provide about 10% change in voltage level, and it boils down to 100 ADC tick over 100 kHz, or 1 kHz resolution or so, which is 10 000 times worse

CrossRoads:
Use a counter input, count the number of pulses that occur in 1mS.
440 & 540. Both will wrap around on an 8-bit counter - so ~185 & ~285 get returned instead.

Use a counter and pick off the appropriate counter stage to measure. Example: dividing the input by 16 will give a cycle time of 29 or 36 microseconds, depending on the frequency.