ok guys i'm stuck, lol...
I've made really good progress on my project but i'm stuck. I really have to give it up for how easy this audrino is to program on, i went from knowing almost nothing about code to within 2 days coming up with this.
I'm using an audrino leonardo and i'm sampling 4 ABS wheel speed sensors on an automobile, averaging the front and the rear separately and trying to calculate slip % based on the difference. Right now i'm just using an agilent function generator and an audrino uno as a 2nd function generator to simulate 2 different +5vpp square wave inputs (split to the 4 inputs). I'll be using 2 max9926 chips to condition the vr sensors (or hall effect) to give me +5vpp signals, once they're actually in a car. i've already got that setup working so the hardware i done with i'm just stuck on the software.
I have the 4 inputs working using interrupts, i have a cycle that repeats every 250ms or so (i need fairly fast response) so it counts the pulses, averages them and displays it all on an lcd (lcd is just for debugging right now) then clears the pulse count.
I can get the pulses for each input, i can average and i can subtract the difference and get that to display. the problem is is when i try to get a slip %. I need it to take the speed of the non drive wheels, subtract that from the drive wheels, get the difference then divide the non drive speed by the difference. For example drive wheels are spinning at 90mph, non drive wheels are at 60mph, difference is 30mph; 30/60= .5 or 50%.
All I can get to display is 0, or 0.00 when i set that variable as float or try to use floating point math coming up with the "slip" variable. Eventually I need to get the slip amount to output a "voltage" using the pwm trick mapped out by the threshold set by a potentiometer.
Anyway here is my code, hopefully someone can point out what i'm doing wrong:
volatile int pulse0 = 0;
volatile int pulse1 = 0;
volatile int pulse2 = 0;
volatile int pulse3 = 0;
int pot = A0;
int threshold = 0;
const int TxPin = 6;
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
void setup() {
mySerial.begin(9600);
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
mySerial.write(22);
mySerial.write(17);
attachInterrupt(0, count0, RISING);
attachInterrupt(1, count1, RISING);
attachInterrupt(2, count2, RISING);
attachInterrupt(3, count3, RISING);
}
void loop() {
mySerial.write(12);
delay(5);
noInterrupts();
mySerial.print(pulse0);
mySerial.print("/");
mySerial.print(pulse1);
mySerial.print(" ");
mySerial.print(pulse2);
mySerial.print("/");
mySerial.print(pulse3);
mySerial.write(13);
int drive = (pulse0 + pulse1) / 2;
mySerial.print(drive);
mySerial.print("/");
int nondrive = (pulse3 + pulse3) / 2;
mySerial.print(nondrive);
mySerial.print(" SLP:");
int diff = (drive - nondrive);
int slip = diff / nondrive;
mySerial.print(slip);
// threshold = analogRead(pot);
// threshold = map(threshold, 0, 1023, 0, 100);
// mySerial.print("THR:");
// mySerial.print(threshold);
pulse0 = 0;
pulse1 = 0;
pulse2 = 0;
pulse3 = 0;
interrupts();
delay(243);
}
void count0()
{
pulse0++;
}
void count1()
{
pulse1++;
}
void count2()
{
pulse2++;
}
void count3()
{
pulse3++;
}