Hello everyone,
I know there is a build in real time clock inside the computer
and I know it's possible to use this clock when you write a program on Assembler(using an interupt that I don't remember at the moment),is there a way to use the real time clock
while programing on VC++ ?
(I use VC++ 6.0 with the 6th service pack instaled)


Yes, you get clock functionality from library <ctime> (or maybe it's still <time.h> in VC++ 6)
See here for a quick reference.

Check your MSDN help information in VC++ for what's actually supported in that compiler.

Consider moving into the 21st century with newer versions. VC++ 2008 Express is a freebie.

Regrettably, all <ctime/time.h> stuff does not bear a relation to the computer Real Time Clock device. Moreover, you can't directly access RTC in standard Windows user mode.

In what modes can I acces it?

I think partially on device driver level or lower (HAL).

Did you need so low level really? The Windows without (as usually third-party and commercial) special software is not a real-time system. Your programs have no direct access to ALL hardware (except CPU in user mode ;) ) on Windows installations. Didn't you know that?

Why you need RTC direct access? May be Windows API or even RTL stuff is enough for your task?..

Well, ofcourse I know that from win 2000 and upwards the acces to the ports is blocked,
but I have a driver that opens the access(and I already tested it many times while working with the parallel port),so I do have access to the hardware.
I need a real time clock to generate accurate PWM for a robot...

It's not a true RTC access (even with RTC driver) because Windows threads sheduling adds unpredictable delays for your robot control process irrespective of its priority.
That's why Windows is not RT system...

Ok,first of all I want to thank everyone for their help,thanks everyone! :)

Now,dougey83, thank you for the program,did you try it? How accurate is it?
How much windows distortes the timers accuracy?(oh,and this time I use an H-bridge and regular DC motors,not servos,if it's possible I want to generate PWM with frequancies of 1 to few Khz).
ArkM,you didn't pay attention,I said a driver that gives me access to ports(in other words,it allows me to access hardware),not a RTC driver...

Arctic wolf, you didn't pay attention that I said about Windows thread sheduling. You can't garantee that your processing code continued immediatly after your wonderful driver gets data from the hardware port.

Arkm,I see your point,I agree.
But I guess there is a way to give the code first priority...
(I also need to look into the code that dougey83 gave,and see how did they solve that problem there,because if they didn't then it's no good...)

Chris,I didn't understand your question,every timing inside the computer eventualy comes from hardware,it's just that the standart timing functions of C++ are no good for my application...

Have a microcontroller generate the PWM.
You can communicate with the microcontroller using the PC.

Chris and Colin, you're missing the point,
ofcourse I can make my own hardware,and I actually plan to use the microcontroller after I finnish some tests using the PC, BUT the point of this test is to use the PC! :)
And by the way Chris,the PC has it's own build in oscilator(the proccessor uses it for timing itself),so basically there is no need to build another one,the problem is what Arkm discribed...

Arkm,I have an old verssion of Borland C that operates in Dos mode,
it's just that I wanted to build on a modern version of C++ and also to use the API to make a good GUI...

I understand that all my "advices" are totally "light-weight" ones (I never made robot control systems)...
About good GUI: remember wonderful videogames implemented in DOS extender environments. Look at SDL game library, for example.
Apropos, Open WATCOM C++ is a cross-compiler (free now) so it's possible to implement all stuff in comfort Windows environment.

I'm aware of that arctick wolf. But i was going down the lines of what Colin said. My fault for missing the bit that it must be done on PC. Sorry.


Arkm,I never said that your advices are no good!
Don't underestimate yourself!

I will check all the leads and if I'll have questions I'll come back :) ...

Thanks again to everyone.


+Points for exuding professionalism and respecting the individuals who gave you advice! =)
This article has been dead for over six months. Start a new discussion instead.