Help! clock generate
-
:confused:hi experts, i am a newbee here. now i m trying to build a samll program which can generate a 400khz clock pulse. but the problem is now i just can reach 6khz. i hv got some high resolution timer of VB, but i cant set the interval length. Is there any independent counter or timer which can be used to generate such a clock pulse? my platform is WIN2000 and cpu is P3. Thank u guys in advance.....=)
-
:confused:hi experts, i am a newbee here. now i m trying to build a samll program which can generate a 400khz clock pulse. but the problem is now i just can reach 6khz. i hv got some high resolution timer of VB, but i cant set the interval length. Is there any independent counter or timer which can be used to generate such a clock pulse? my platform is WIN2000 and cpu is P3. Thank u guys in advance.....=)
You may find this link[^] useful. If you can create a control that emits an event every 1.25 µS you can use the event to toggle a high/low output state to simulate a square wave. I wouldn't expect any great accuracy, though. Another possibility, though I don't know if VB supports inline assembly language, is to write an asm program segment that uses the CPU's native speed and sufficient NOPs to create a clock. The disadvantage is that for this to work, you have to block all other processes on the machine. Heard in Bullhead City - "You haven't lost your girl -
you've just lost your turn..." [sigh] So true... -
:confused:hi experts, i am a newbee here. now i m trying to build a samll program which can generate a 400khz clock pulse. but the problem is now i just can reach 6khz. i hv got some high resolution timer of VB, but i cant set the interval length. Is there any independent counter or timer which can be used to generate such a clock pulse? my platform is WIN2000 and cpu is P3. Thank u guys in advance.....=)
VB doesn't support in-line assembly, though C/C++ does. The problem your facing is that the highest resolution timers in the system will only generate a pulse once every 1 millisecond, which is your 6Khz rate that your getting. In order to generate a 400Khz pulse, you need something about 200times faster, but, unfortunatly, there is nothing in the system that exploses an interface that can do that for you. In order to generate a clock signal that fast, that you can use in your program, your going to need extra hardware, like some card in a PCI slot, and the drivers for it. RageInTheMachine9532
-
VB doesn't support in-line assembly, though C/C++ does. The problem your facing is that the highest resolution timers in the system will only generate a pulse once every 1 millisecond, which is your 6Khz rate that your getting. In order to generate a 400Khz pulse, you need something about 200times faster, but, unfortunatly, there is nothing in the system that exploses an interface that can do that for you. In order to generate a clock signal that fast, that you can use in your program, your going to need extra hardware, like some card in a PCI slot, and the drivers for it. RageInTheMachine9532
hi, Thank U guys! now i am trying to call the kernel function QueryPerformanceCounter and QueryPerformanceFrequency to achieve the interval. here is my code: Set tmr = New PerformanceTimer With tmr Do While (True) Do While (iTotal < 100):confused: .StartTimer .StopTimer iTotal = iTotal + .TimeElapsed(pvMicroSecond) DoEvents Loop Out 890, 1 Label3.Caption = "1" Out 890, 0 Label3.Caption = "0" DoEvents Loop End With Set tmr = Nothing MsgBox iTotal & " ms" what i did is i am trying to use a high-resolution timer which is provided by the kernerl to time the interval i need. but i dont know whether it's accurate enough or not. Guys u hv any suggestion abt it? i get a software which also generate such 400khz clock but it's written in Delphi. i am not so sure i can get it in VB or not. can help me to figure it? thank U in advance!!!!!
-
hi, Thank U guys! now i am trying to call the kernel function QueryPerformanceCounter and QueryPerformanceFrequency to achieve the interval. here is my code: Set tmr = New PerformanceTimer With tmr Do While (True) Do While (iTotal < 100):confused: .StartTimer .StopTimer iTotal = iTotal + .TimeElapsed(pvMicroSecond) DoEvents Loop Out 890, 1 Label3.Caption = "1" Out 890, 0 Label3.Caption = "0" DoEvents Loop End With Set tmr = Nothing MsgBox iTotal & " ms" what i did is i am trying to use a high-resolution timer which is provided by the kernerl to time the interval i need. but i dont know whether it's accurate enough or not. Guys u hv any suggestion abt it? i get a software which also generate such 400khz clock but it's written in Delphi. i am not so sure i can get it in VB or not. can help me to figure it? thank U in advance!!!!!
I think you still have a performance problem. In order to get a 400kHz pulse, you would have to generate an Out signal every 0.0000025 seconds (1/400000). According to this little timer in C:
#include <windows.h>
#include <stdio.h>
#include <conio.h>int main()
{
BOOL rc;
LARGE_INTEGER liCountPerSecond, liStartTime, liEndTime, liCounts;
double dSeconds;rc = QueryPerformanceFrequency( &liCountPerSecond ); printf( "Counts per second: %I64i\\n", liCountPerSecond ); rc = QueryPerformanceCounter( &liStartTime ); // We are timing this assignment statement and the call to // QueryPerformanceCounter after it. rc = true; rc = QueryPerformanceCounter( &liEndTime ); // End Timed Section printf( "Start Counter: %I64i\\n", liStartTime ); printf( "End Counter : %I64i\\n", liEndTime ); liCounts.QuadPart = liEndTime.QuadPart - liStartTime.QuadPart; printf( "Counts : %I64i\\n", liCounts ); dSeconds = (double)liCounts.QuadPart / (double)liCountPerSecond.QuadPart; printf( "Time in Seconds : %15.10f seconds\\n", dSeconds ); getch();
}
My Athlon 2600+ takes .0000013968 seconds to execute a boolean assignment statement and make the call to QueryPerformanceCounter after it. Keep in mind that 'In' and 'Out' port statements are notoriously slow to execute! RageInTheMachine9532
-
I think you still have a performance problem. In order to get a 400kHz pulse, you would have to generate an Out signal every 0.0000025 seconds (1/400000). According to this little timer in C:
#include <windows.h>
#include <stdio.h>
#include <conio.h>int main()
{
BOOL rc;
LARGE_INTEGER liCountPerSecond, liStartTime, liEndTime, liCounts;
double dSeconds;rc = QueryPerformanceFrequency( &liCountPerSecond ); printf( "Counts per second: %I64i\\n", liCountPerSecond ); rc = QueryPerformanceCounter( &liStartTime ); // We are timing this assignment statement and the call to // QueryPerformanceCounter after it. rc = true; rc = QueryPerformanceCounter( &liEndTime ); // End Timed Section printf( "Start Counter: %I64i\\n", liStartTime ); printf( "End Counter : %I64i\\n", liEndTime ); liCounts.QuadPart = liEndTime.QuadPart - liStartTime.QuadPart; printf( "Counts : %I64i\\n", liCounts ); dSeconds = (double)liCounts.QuadPart / (double)liCountPerSecond.QuadPart; printf( "Time in Seconds : %15.10f seconds\\n", dSeconds ); getch();
}
My Athlon 2600+ takes .0000013968 seconds to execute a boolean assignment statement and make the call to QueryPerformanceCounter after it. Keep in mind that 'In' and 'Out' port statements are notoriously slow to execute! RageInTheMachine9532
ThanK U!!!!! now i c the problem clearly. it's because VB is a high level language so it cant achieve so high speed, rite? so to achieve the 400khz what i hv to do is use C's in line assemble language? or can i read the CPU information from the BIOS everytime, so i can directly use the system clock to generate such pulse? Can i do this in VB or C or other high level language? Thank U again, Sir!!! u really help me a lot:rolleyes:
-
ThanK U!!!!! now i c the problem clearly. it's because VB is a high level language so it cant achieve so high speed, rite? so to achieve the 400khz what i hv to do is use C's in line assemble language? or can i read the CPU information from the BIOS everytime, so i can directly use the system clock to generate such pulse? Can i do this in VB or C or other high level language? Thank U again, Sir!!! u really help me a lot:rolleyes:
Well, when VB is executed, one statement in VB can equate to several statements in C. The problem your going to run into is that the time you require between pulses, MAY not be enough to execute the required statements to generate the pulses and track the time between them. You can use the program in my previous post to find out how long it takes your machine to execute just a simple assignment and a call to QueryPerformanceCounter. Remember, you only have 0.0000025 seconds between pulses! Your going to need a bunch more statements to track the time between pulses with near continuous calls to QueryPerformanceCounter, fire an Out statement or some other event on Time (or really close to it!), AND let the system do other housekeeping work while you literally HOG the CPU generating this clock pulse so fast! This is the ONLY high resolution timer that has (1) sub 1 millisecond resolution and (2) has an API call to it. Oh! and not all systems support this timer! Also, you can forget about capturing the CPU clock, it's WAY to fast and there is no way grab it. A better test to see how fast your system will execute statements:
#include <windows.h>
#include <stdio.h>
#include <conio.h>
int main()
{
BOOL rc;
int iReturn;
LARGE_INTEGER liCountPerSecond, liStartTime, liEndTime, liCounts;
double dSeconds;
rc = QueryPerformanceFrequency( &liCountPerSecond );
printf( "Counts per second: %I64i\n", liCountPerSecond );
rc = QueryPerformanceCounter( &liStartTime );
// We are timing this section.
// 10 simple assignment statements and an extra call
// to QueryPerformanceCounter should make a crude, but
// simple demonstration of performance. This doesn't
// include ANY error checking either!
iReturn = 0;
iReturn = 1;
iReturn = 2;
iReturn = 3;
iReturn = 4;
rc = QueryPerformanceCounter( &liEndTime );
iReturn = 5;
iReturn = 6;
iReturn = 7;
iReturn = 8;
iReturn = 9;
rc = QueryPerformanceCounter( &liEndTime );
// End Timed Section.
printf( "Start Time: %I64i\n", liStartTime );
printf( "End Time : %I64i\n", liEndTime );
liCounts.QuadPart = liEndTime.QuadPart - liStartTime.QuadPart;
printf( "Counts : %I64i\n", liCounts );
dSeconds = (double)liCounts.QuadPart / (double)liCountPerSecond.QuadPart;
printf( "Time in Seconds : %15.10f seconds\n", dSeconds );
getch();
}RageInTheMachine9532
-
Well, when VB is executed, one statement in VB can equate to several statements in C. The problem your going to run into is that the time you require between pulses, MAY not be enough to execute the required statements to generate the pulses and track the time between them. You can use the program in my previous post to find out how long it takes your machine to execute just a simple assignment and a call to QueryPerformanceCounter. Remember, you only have 0.0000025 seconds between pulses! Your going to need a bunch more statements to track the time between pulses with near continuous calls to QueryPerformanceCounter, fire an Out statement or some other event on Time (or really close to it!), AND let the system do other housekeeping work while you literally HOG the CPU generating this clock pulse so fast! This is the ONLY high resolution timer that has (1) sub 1 millisecond resolution and (2) has an API call to it. Oh! and not all systems support this timer! Also, you can forget about capturing the CPU clock, it's WAY to fast and there is no way grab it. A better test to see how fast your system will execute statements:
#include <windows.h>
#include <stdio.h>
#include <conio.h>
int main()
{
BOOL rc;
int iReturn;
LARGE_INTEGER liCountPerSecond, liStartTime, liEndTime, liCounts;
double dSeconds;
rc = QueryPerformanceFrequency( &liCountPerSecond );
printf( "Counts per second: %I64i\n", liCountPerSecond );
rc = QueryPerformanceCounter( &liStartTime );
// We are timing this section.
// 10 simple assignment statements and an extra call
// to QueryPerformanceCounter should make a crude, but
// simple demonstration of performance. This doesn't
// include ANY error checking either!
iReturn = 0;
iReturn = 1;
iReturn = 2;
iReturn = 3;
iReturn = 4;
rc = QueryPerformanceCounter( &liEndTime );
iReturn = 5;
iReturn = 6;
iReturn = 7;
iReturn = 8;
iReturn = 9;
rc = QueryPerformanceCounter( &liEndTime );
// End Timed Section.
printf( "Start Time: %I64i\n", liStartTime );
printf( "End Time : %I64i\n", liEndTime );
liCounts.QuadPart = liEndTime.QuadPart - liStartTime.QuadPart;
printf( "Counts : %I64i\n", liCounts );
dSeconds = (double)liCounts.QuadPart / (double)liCountPerSecond.QuadPart;
printf( "Time in Seconds : %15.10f seconds\n", dSeconds );
getch();
}RageInTheMachine9532
So what i hv to do is use C or C++, rite? but using C is too troublesome. Can i use a DLL which contain the assemble one, then i call it from VB? I hv read some articles abt MASM. it says that the MASM support a mixed programming language. it means MASM can also be used for Basic or VB? Thank U very much!!! =):-O