Trouble verifying FreqCounter.h library added

I have utilized an arduino Uno to control the lockup function of the torque converter clutch in my daily driven pickup truck. I don't care for the set points and function of the OE PCM. My original intent was to use the vehicle speed sensor as my signal source, a 3 wire 5V hall effect sensor. It has suffered some version of hardware failure when I tried to bench test it. I decided that I would move on to the Output Shaft speed sensor, a two wire, variable reluctance sensor. Using my Fluke 88V, I established a working frequency of ~200Hz, to just over 1000Hz AC signal. The OE circuit consists of a signal wire to the PCM and a return tied to all of the 5V sensors on the powertrain.

I thought that the change of plan would spur me to learn how to utilize the FreqCounter Library. The thing Is, I can't publish a working frequency to the serial monitor. I have the control circuit and shield functioning. I checked the hardware with a 5V pot circuit, setting thresholds for Locking and Unlocking of the torque converter.

I have included the LCD library and some code, as I intend to utilize this when I receive an LCD screen.

I am completely NEWB, Green. I work in the On Highway Truck industry, and have industry standard electronics knowledge for that field. As far as micro controllers, coding and so-forth, this is my first run, other than picking up a few of the example sketches. I have relied heavily on fragments of code found with google.

This is it:

/* To provide a lockup controller so that pin 9 controls lockup status, pin A3 receives 5V signal from the speedometer and allows lockup or unlock at separate speeds x, y */

const int analogPin = A3;     // speedometer out connected to analog pin 3

int speedo = A3;         // name pin 3 speedo - is unused currently so serial print works

int Lock = 9;           // Name pin 9 for lockup output

int sensorValue = 0;           // variable to store the value read

#include <LiquidCrystal.h>  // include the library code:

#include <FreqCounter.h>



LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  // initialize the library with the numbers of the interface pins


void setup()

{
  Serial.begin(57600);     //  setup serial
  
  // Serial.println("Frequency Counter");  //prints line "frequency counter" unused
  
  pinMode(Lock, OUTPUT);  // sets "Lock" pin as an output 
  
  pinMode(speedo, INPUT); // sets "speedo" pin as an input
  
  lcd.begin(16, 2);       // designates 16 columns and 2 rows of lcd display
  
  
}

long int frq; // allows large numbers to be stored for freq amounts

void loop()

//Sensor, Mode and Serial Print configuration

{
  FreqCounter::f_comp= 8;             // Set compensation to 12
  FreqCounter::start(100);            // Start counting with gatetime of 100ms
  while (FreqCounter::f_ready == 0)   // wait until counter ready
 
  frq=FreqCounter::f_freq;            // read result
  Serial.print("Frequency = ");
  Serial.println(frq);                // print result
  delay(100);
  
  sensorValue = analogRead(analogPin);  // sets sensor value as constant analog pin outlined above
  Serial.print("sensor = ");             // sets sensor value as printable
  Serial.println(sensorValue);          // sets sensor value to print
  delay (100);

   // What to print to Serial and when

  if (digitalRead(Lock) == HIGH)        //if digital pin 9 "Lock" output is high
    Serial.println("ON");               //serial print will display the word "ON"
  else                                  //otherwise
    Serial.println("Unlocked");         //serial print will print Unlocked

  delay(100);
  
  // What to do with the Sensor values and Output
  
  if (sensorValue>= 800)               //if sensor value, aka analogreadpin aka speedo is over desired value
  {
    digitalWrite(Lock, HIGH);           // Lock pin will be turned on
  }
  if (sensorValue<= 550)                // is sensor value, aka analogreadpin aka speedo is under desired value
  {
    digitalWrite(Lock, LOW);            // Lock pin will be turned off
  }
  
  //Serial LCD configuration
  
  if (Serial.available()) // when characters arrive over the serial port...
  
   {
    delay(100); // wait a bit for the entire message to arrive
    
    lcd.clear();// clear the screen
    
    while (Serial.available() > 0)// read all the available characters 

     {   
       lcd.write(Serial.read());// display each character to the LCD
     }
   }
}

As I said, first try there. Anything and everything is welcome to improvement. I tried to add notes, some of which are not mine, to help me track structure. As far as where particular fragments ended up, I have no real reasoning. This is my default file on my USB stick. The file I tried uses (5) delay and 1ms gate time.

I changed "Locked" to On so that it could be easily seen on the serial monitor (and the change could be seen in the powertrain). I have not yet added code to react to a frequency input. I just want to establish frequency serial print first, in order to allow me to set for integers I will be seeing in motion.

I had trouble adding the library file (permissions) to my Ubuntu Thumbdrive(n) laptop so I threw everything on a USB stick and loaded the library using a windows pc.
I borrowed the library from http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/ I realize it says to use the other library for <1Khz. I wanted to consult before I revamped.
I found a reference to checking the source with an LED to determine if it was sufficient to drive the arduino without amplification. It lights a white LED in daylight.

I guess ultimately I'm trying to narrow down a hardware issue or coding error.
Sorry for the long winded post. I tried to be thorough.

Thanks
Kyle

I started over with only the code needed to view frequency at the advise of a member here. I had to switch from frequency counter to frequency measure, which was a good move.

I have used this circuit to buffer the signal http://forum.arduino.cc/index.php?action=dlattach;topic=185066.0;attach=52587;image

I used an A1585 transistor salvaged from some junk.

I had to omit the 10k resistor because my input voltage was relatively low. My multimeter could read the frequency, but the arduino would not.

I did end up with a somewhat useful frequency published to serial monitor. I had about 400Hz on my multimeter and roughly 250-300Hz printing to serial.

I have a problem. Something in the circuit is causing the vehicle to go to pull up voltage. I do have the arduino and shield Grd to vehicle battery ground. I think this is also causing my reading to be inversely proportional. If I speed the driveline up, my frequncy drops to near Zero.

Any input as to why the vehicle goes to diag would be great.
Thanks
Kyle

I had time to come back to my project this evening.

#include <FreqMeasure.h>

void setup() {
  Serial.begin(57600);
  FreqMeasure.begin();
}

double sum=0;
int count=0;

void loop() {
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      double frequency = F_CPU / (sum / count);
      Serial.println(frequency);  //                                                          <--this integer as it's being published to serial?
      sum = 0;
      count = 0;
    }
  }
}

Is there a way to use this frequency to control an output? I tried to use (frequency) but it says that I haven't declared it. How to I go about declaring frequency as an integer?

#include <FreqMeasure.h>

int Lock = 9;           // Name pin 9 for lockup output

void setup() 
{
  Serial.begin(57600);
  FreqMeasure.begin();
  
  pinMode(Lock, OUTPUT);
}

double sum=0;
int count=0;

void loop() 
{
  if (FreqMeasure.available()) 
 {
    sum = sum + FreqMeasure.read(); // average several reading together
    count = count + 1;
   
   if (count > 30) 
    {
      double frequency = F_CPU / (sum / count);
      Serial.print("Frequency = ");
      Serial.println(frequency);
      sum = 0;
      count = 0;
    }   
   if (frequency >= 80)
    {
      digitalWrite(Lock, HIGH);
    }
  if (frequency <= 60 && Lock == HIGH)
    {
      digitalWrite (Lock, LOW);
    }
  if (digitalRead(Lock) == HIGH)
    Serial.write('Locked');
  else
    Serial.write('Unlocked');
 }
}

I tried to use (frequency) but it says that I haven't declared it.

You tried to use it where/how?

How to I go about declaring frequency as an integer?

Just like here:

      double frequency = F_CPU / (sum / count);

(except that you spell it int).

In the second code, frequency goes out of scope at the } that follows the declaration. You need to use frequency BEFORE that }.

I'm learning so please forgive me. I also would need to use frequency before sum = 0 and count = 0 in addition to the string terminus } as they reset the integer?

sum = 0;
count = 0;

Also

#include <FreqMeasure.h>

int Lock = 9;           // Name pin 9 for lockup output

int double frequency = F_CPU / (sum / count);   //should declare the int "frequency"? for me?

void setup()

I'm sorry I wasn't clear on how I had tried to use "frequency" in the first block of code. I had tried to set some If statements to control output on pin 9.

if (frequency >= 80)
    {
      digitalWrite(Lock, HIGH);
    }
  if (frequency <= 60 && Lock == HIGH)
    {
      digitalWrite (Lock, LOW);
    }
  if (digitalRead(Lock) == HIGH)
    Serial.write('Locked');
  else
    Serial.write('Unlocked');

Thank You
Kyle

I have this installed and functioning on my vehicle. Thank you all for your help. This code below is functional. I do have a question below:

#include <FreqMeasure.h>

unsigned int frequency;

int Lock = 9;           // Name pin 9 for lockup output

void setup() 
{
  Serial.begin(57600);
  FreqMeasure.begin();
  
  pinMode(Lock, OUTPUT);
}

double sum=0;
int count=0;

void loop() 
{
  if (FreqMeasure.available()) 
 {
    sum = sum + FreqMeasure.read(); // average several reading together
    count = count + 1;
   
   if (count > 30) 
    {
      double frequency = F_CPU / (sum / count);
      Serial.print("Frequency = ");
      Serial.println(frequency);
      sum = 0;
      count = 0;   
      if (frequency >= 80)
       {
        digitalWrite(Lock, HIGH);
       }
      if (frequency <= 60)
       {
        digitalWrite (Lock, LOW);
       }
      if (digitalRead(Lock) == HIGH)
         Serial.write('Locked');
        else
         Serial.write('Unlocked');
      
    }
  }
}

Why had it added the "d" in front of the Frequency? When it was just the frequency library and code running, it didn't do this.

The other issue, It makes no attempt to run the other serial print commands. I'm sure this is a conflict I have created. If one of you have a suggestion, I will pursue it. Otherwise it will take me longer to stumble across it.

dFrequency = 53.67
dFrequency = 53.63
dFrequency = 53.72
dFrequency = 53.75
dFrequency = 53.79
dFrequency = 53.83
dFrequency = 53.67
dFrequency = 53.58
dFrequency = 53.68
dFrequency = 53.59
dFrequency = 53.61

There wasn't enough delay to allow a full print. It was only publishing the last letter of each return.

{
      double frequency = F_CPU / (sum / count);
      sum = 0;
      count = 0;   
      if (digitalRead(Lock) == HIGH)
         
         Serial.write("Locked");
         
        else
         Serial.write("Unlocked");
         
         Serial.println();
         delay (20);
         
      if (frequency >= 58)
       {
        digitalWrite(Lock, HIGH);
       }
      if (frequency <= 55)
       {
        digitalWrite (Lock, LOW);

This may be flawed somehow, but it does exactly what I'm asking of it.
Now to add an LCD with button interfaces.