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