Any Programmers around here?

GoldenMotor.com

Prasinos

Member
Dec 1, 2008
261
0
16
California
Hey guys I have been thinking about making a dyno for my bikes and I have figured out the hardware part. I plan on using one or two 45lb plates as a flywheel and they will be spun by the back tire of a bike. I will use a mouse or a keyboard along with a cam that will click a button a number of times per revolution.

So the reason for the title.

I need a program that will record the time between clicks and possibly output them into an excel file. This way I can just use the first derivative to calculate angular velocity, the second derivative to calculate torque and the third to calculate power. It would be able to make some really nice graphs that could show the difference in power from different upgrades, I think it would be really cool.

Anyway I don't think it would be that difficult for someone that knew what they were doing. I have acess to labview, matlab, and c++. So if anyone could lend advice, or ideally write this program, I would appreciate it greatly.
 

TheE

New Member
Jun 26, 2009
185
0
0
Canada
Um yeah, that wouldn't be too hard to do in good ol' fashioned C. Could export the results directly in .csv format too.

The multi-tasking of a modern OS will throw off the timing a hair, just for fair warning.
 
Last edited:

Prasinos

Member
Dec 1, 2008
261
0
16
California
not to impose, but if i gave you my email could you make the program and send it to me? I dont want to cause you too much trouble and i dont know how complicated the code would be, but if it isnt too hard....
 

TheE

New Member
Jun 26, 2009
185
0
0
Canada
I've actually been trying to code it a bit. Turns out that getting any kind of precision timing in C is alot harder than I thought. I'll let you know if I find anything.
 

Prasinos

Member
Dec 1, 2008
261
0
16
California
hmmm, yea i can only make the flywheel so heavy, if i could get to within like 50 miliseconds i think it would be enough.
 

TheE

New Member
Jun 26, 2009
185
0
0
Canada
Welp, I did a bit of researching about something called the QueryPerformanceCounter function which, as the name implies, queries a counter inside the CPU for really high-res timing. Here's my code with it so far (for Visual Studio C++):
Code:
#include "stdafx.h"
#include <windows.h>

#include <winbase.h>
#include <stdlib.h>
#include <conio.h>

int main(void)
{

	
    unsigned long int revs=0;
    LARGE_INTEGER total_time,diff_time,start_time,end_time,TICKS_PER_SECOND;
	char c=0;
	FILE *outp;

	QueryPerformanceFrequency(&TICKS_PER_SECOND);

	total_time.QuadPart=0;
	outp=fopen("output.csv","a");
	fflush(stdin);
	printf("QPC Freq: %I64d\n",TICKS_PER_SECOND.QuadPart);
	

	printf("Press any key to begin capturing.\n");
	
    
	getch();

	printf("Capturing counts to output.csv, press 'x' to quit...");

    QueryPerformanceCounter(&start_time);

	while(c!='x')
	{
		if(kbhit())
		{
		
		   QueryPerformanceCounter(&end_time);
		   diff_time.QuadPart=end_time.QuadPart-start_time.QuadPart;
		   total_time.QuadPart+=diff_time.QuadPart;
		   QueryPerformanceCounter(&start_time);
		   revs++;
		   fprintf(outp,"%ld,%I64d,%I64d,\n",revs,total_time.QuadPart,diff_time.QuadPart);
		   c=getch();
		}
		
	}

	fclose(outp);

	printf("\n\nTotal of %ld revolutions were counted!\n",revs);
	getch();

     return EXIT_SUCCESS;
}
It will tell you how many ticks per second at the beginning, and then append the results into an "output.csv" file in the same directory as the executable(will be created if it hasn't already). You can later multiply (number of ticks * (1/tick frequency)) to get the time.

I really have no idea how accurate it is, and I'm not a professional programmer by any stretch of the imagination. I'm sure someone will chime in with a better solution. Personally I prefer a microcontroller because you can manually calculate it's timing down to the nanosecond, but a general goes to war with the army he's got...
 
Last edited:

Prasinos

Member
Dec 1, 2008
261
0
16
California
Thanks alot E, il see how this works. I get home around thanksgiving so il let you know how this all goes when i try it ou
 

Prasinos

Member
Dec 1, 2008
261
0
16
California
K i looked at the code and tried it out just messing around. It doesent seem to be very accurate at all... once you click more than twice a second the times can be off by almost 50 percent. Ive been looking this up and it seems like lots of people are making programs like this but i couldn't find any posted code. I also found many online games that measured exact time between clicks but obvously none of them could outut to excel.....
 

TheE

New Member
Jun 26, 2009
185
0
0
Canada
How were you checking the timing?

Did you say you had LabView? It's probably better suited to this kind of thing, I've never used it though.
 
Last edited:

Prasinos

Member
Dec 1, 2008
261
0
16
California
yea it would be pretty easy with labview but i still cant find my license online, i had it last year and Virginia Tech normally keeps those available....
 

Prasinos

Member
Dec 1, 2008
261
0
16
California
there are literally hundreds of dyno designs, mine would use the moment of inertia of a flywheel. Torque=(angular acceleration) x (moment of inertia). So id use the program to record the angular acceleration and i would calculate the moment of inertia of the flywheel, so using both the values i can calculate torque. Then you just multiply that by angular velocity to get power.


Yea im working on labview and i think this owuld be pretty easy if i can just get my licence for it back...
 

Prasinos

Member
Dec 1, 2008
261
0
16
California
k boys looks like i can get labiew i just need to fill out some paperwork to renew my license. Il take care of that part tommorow and see what i can do as far as code is concerned.
 

Prasinos

Member
Dec 1, 2008
261
0
16
California
I just got labview and i have no idea what im doing, i cant figure out how to make a loop that records the time between clicks, can anyone help...
 

xlite

New Member
Jun 18, 2009
735
0
0
ny,ny
there are literally hundreds of dyno designs, mine would use the moment of inertia of a flywheel. Torque=(angular acceleration) x (moment of inertia). So id use the program to record the angular acceleration and i would calculate the moment of inertia of the flywheel, so using both the values i can calculate torque. Then you just multiply that by angular velocity to get power.
Yes... I understand now. Dynamic. I looked at building a water paddle type dyno but ended up using a long gradual hill nearby in conjunction with a GPS to get a relative idea of engine performance.

Like TheE I am inclined to do this type of logging with a cheap AVR or PIC micro and download result to a PC instead of trying to make the PC do reliable low level timimg. It seems to get worse with each new version of Windoze.