Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer with 100kHz frequency in Windows XP

Status
Not open for further replies.

C4C

Technical User
Jan 1, 2003
11
US
Hello,

I have been persuing this matter for two years without any positive results so I have decided to ask for help.

There is a popular CNC machine tool control software named 'Mach 3' and it operates in Windows XP. The application has a timer that generates a user selectable frequency ranging from 25kHz to 100kHz~+ with a maximum CPU cost of 12%. I suspect that the author is manipulating the 'System Timer' or another on board timer. It will operate with all mainboards and the only known limitation is use with laptop computers due to their ACPI. The frequency is used to generate a pulse train signal which is emitted from the PC parallel port so it can and has been verified.

I program in Visual Basic 6.0, but I have wrote some drivers and dlls in C/C++. I learned to program using the 'Monkey See Monkey Do' approach. Please do not construe that to mean that I always copy another authors code. I revise their code to suit my purpose, but on the rare occasions where their code is 'Just Right' then I'll paste it right in to my program. The endless amount of code on the internet facilitates that approach very well, however with the 'Timer' there's only one 'Monkey' that has accomplished the task and he has not published his code.

I desparately need the 100kHz timer in order for my application to work.

C4C
 
It is possible that it is making use of the timer interrupt built into the system. This would be a very low level function and I can't say how difficult it would be to access via XP. You would need to chain into the PCI interrupt signal, inserting your handler in the chain, as appropriate.

There should be lots of examples, especially under DOS. Look for 'tutorials' such as Paul Carters Assembly book and the DJGPP compiler.

There may be "better" more modern ways to implement this within the OS, but my perspective is from someone who does predominatly embedded design.
 
I don't know if this is relevant, but Michael Abrash's old "black book" of assembler for DOS contained a "Zen timer" with fairly phenomenal characteristics. You could try googling zen timer abrash and see what happens. Abrash was very open about everything he described, explaining clearly how it all works.
 
Noway2 & lionelhill,

Thanks for your input. My application runs in Windows XP so the solution must also run in Windows XP.

Is a Timer actually a thread with a Loop and an interrupt?

C4C

 
Let me preface this by saying that I am NOT a windows programmer. It very well may be possible to REQUEST XP to provide your application a signal on a timed basis and you may use this for your application. However, every bit of windows programming learning I have done says that XP is in charge and there is nothing you can do to guarantee that you will get this signal on time.

If you absolutely MUST have this signal on time, every time, you will need to use some form of hardware driven signal. Such a hardware signal will require a driver interface to XP. The driver interface will likely contain a link / chain into the interrupt handler, which will come in on one of the PCI interrupt lines.

If you must use XP, you will find that you have XP and all its glory, on top of the low level hardware stuff. Starting your investigation in DOS will show you the low level portions that will in turn interface into XP. For the XP portion, you will most likely need to consult a driver development kit (beyond my knowledge).

For answering you other question, there are multiple levels of "timers". Timers can consist of a periodic signal driven by an accurate oscillator with a counter and a comparator. When the comparator matches, a signal is emitted, that is caught by the CPU or in turn by the OS. More advanced timers can then be built upon this basic concept.
 
Noway2,

I checked the Zen Timer and it is no more than a stopwatch timer. I have a Windows dll that I wrote that covers that task so the Zen Timer is a no starter.

I'm a very determined individual when I actually set my mind to something. My very first programming project was to write the OS for a full service CNC milling machine controller which involved some very extreme logic and mathematics so using my head is not a problem.

This is something that would be very benificial to many Windows programmers so I'm really hoping to bring many minds together in an effort to figure this out.

The author that I referenced in my first post made his software available at no cost and he claimed it to be open source, however the source that I have certainly does not facilitate creating a 100kHz timer.

With that stated, I have no problem with picking his driver in order to duplicate it. I'm not talking about disassembling or decompiling his driver. A person can simply open a driver in a text editor and get an idea for some of the kernel functions that were used in making the driver. Another method is to use the Driver Studio utility WdmSniff to reveal calls made to and from the driver. If all goes well there should be a link to a picture I placed in photobucket which shows a screen capture of WdmSniff. In the picture it shows that he is creating two interrupts which I suspect from other knowledge that I have gained that he is using those interrupts with two watchdog timers.

Again, this would be of benifit to many Windows programmers who are currently limited to the not so great Microsoft Multi-Media timer and its not so stable 988 to 999 frequency.

I have no problem with this approach considering that the afore mentioned author copy alot of his code from the EMC (Enhanced Machine Controller) program that was wrote by NIST (National Institute of Standards and Technology) which is funded with our tax dollars.

I would have probably done the same had I have been smart enough to understand the code. Every one has their own unique logic and if you cannot get in touch with their logic then their code is almost worthless to you. I'm proud to say that my profile motion code that handles linear and circular moves along with tool path offsets makes the EMC code look like it was wrote by some government employs, hey that's right! It was.

C4C

C4C
 
 http://s843.photobucket.com/albums/zz354/CNC4Cheap/?action=view&current=WdmSniffer.jpg
One of the problems with windows is that it refuses to guarantee timing. The CPU and mother board (and the BIOS) will provide accurate clock/timer, but WINDOWS won't let you at them directly. You will need to interface to these signals by writing a hardware driver which will give you more direct access to the hardware.

This is certainly do-able, and it would appear that given your experience you will be successful, but there a level of complexity associated with it because windows IS DESIGNED TO abstract you from these details.

I recommended DOS and assembly tutorials because they often times show examples of using these timers and this would be the basis of your XP driver.






 
Noway2,

>but WINDOWS won't let you at them directly<

I have wrote drivers and I have accessed those forbidden I/O addresses but the end result is very similar to walking an elephant through a tulip bed. It wasn't pretty.

My System does not support the SMBus so my last driver project was for reading all of the system hardware temperatures from the Super I/O which also required writing to the the I/O. I persued that task for over two years and I encountered many BSOD along with freezing my machine up several times.

If I could get a Hot Shot Windows programmer onboard then I could give them enough clues and it would all probably fall in place for them. Heck, I've got the instructions (see picture) but I haven't been able to figure it out.

Looks like I'm in for another mind altering experience. If you run across any Windows programmers then send them my way.

C4C
 
 http://s843.photobucket.com/albums/zz354/CNC4Cheap/?action=view&current=Timer.jpg
If you haven't yet, try stackoverflow.com. Warning, it is a very popular sight and you will need to keep close tabs on your post, possibly "bumping" it if it falls off the radar too quickly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top