I am trying to compare the rpm of an engine's output shaft with that of a drive shaft. I need the program to wait until the two are within a certain ratio then take action(this is for a downshift throttle blip during an automated gear shifting event for a track car) .
I am trying to do this inside a while loop after some initial actions . I am using interrupts to count the logic pulses on the engine and drive shaft.
Hi,
I dont fully understand what you are doing, but you seem to be counting RPM where as I think you might be better off looking at the period of a revolution.
Am I right in understanding that your interested in the point at which the two RPM speeds match in which case you want to blip as soon as possible ?
One way to do this would be two have your interrupts updating a 'revolution period' for each input, this will be updated every rotation, your loop code just needs to check are the two values within a tolerance if so, lets blip !
because "rpmenginecount" has value 20 and "(millis() - timeoldengine)" has value around 100 (6000rpm = 100 rev per second = 10 rev in 100 milliseconds). In fact the variable "rpmengine" is not the engine RPM but the revolutions per millisecond.
So the ratio is still initially read as greater than 2 and then exits the while loop. This however is not true as I am using two signal generators for the logic pulses for the engine and driveshaft and they are both initially set to the same value (10Hz). The RPM value, inside the rpm calculating if statements, cannot be correct though I am struggling to see what is wrong with it
Some serial output would be good to see. What values are you seeing for rpmengine and rpmdrive?
What problem are we trying to solve? An incorrect value for rpmengine? An incorrect value for rpmdrive? An incorrect value for rpmratio? Or, incorrect logic to deal with the correct rpmratio?
It really helps to have facts and data to narrow down where the problem is occurring.
Hi,
It does make sense, so again what you are looking for is the point when the time taken for X to revolve once is the same as the time for Y to revolve once - give or take a margin.
As you interested in the time, I would measure the time and take my decision based on the time.
I was going to put in a sample of this approach, but give me an hour our two and I will dig out some old code that you can use if this approach is of interest to you.
Hi,
I have sent you a PM with an extract from one of my current projects, you will see that its measuring wheel speed, I have tested this with 700 interrupts per seconds so its more than fast enough for your application.
The servo is just in there to generate test pulses on pin 13, you can connect this to pin 2 or 3 to check the code, you should see a period very close to 20000 microseconds.
From there on in, its upto you.
I will publish the code on my blog in a few days time so if you don't mind, keep it between you and me in the meantime.