EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Monitor RS232 comms with millisecond resolution

Started by rowan.bradley June 20, 2010
On Fri, 25 Jun 2010 22:15:39 -0700, Fred <fuque@hotmail.com>
wrote:

>Last time on comp.arch.embedded, Jon Kirwan <jonk@infinitefactors.org> >said: > >>On Thu, 24 Jun 2010 21:27:15 -0700, Fred <fuque@hotmail.com> >>wrote: >> >>>Last time on comp.arch.embedded, Jon Kirwan <jonk@infinitefactors.org> >>>said: >>> >>>>>If possible I'd like it to run at a non-standard baud rate (62,500 baud). >>>> >>>>I'm not sure an IBM PC uart can run at that rate. >>> >>>It could if you're willing to change the crystal on the UART card... >> >>Yeah. I think that has been mentioned in this thread >>about... 20 times already? > >I only saw one other mention; somehow I missed the other 19.
I believe I saw several different people mention the possibility and more still accepting the point and referring to it.
>>And have you actually done this on a modern PC? > >Not on a PC motherboard, but I have done it on an expansion card.
The comment of mine that you quoted was "I'm not sure an IBM PC uart can run at that rate." Note that I wasn't discussing expansion cards.
>>In any case, I haven't looked recently, but few PCs these >>days seem to sport RS-232 or RS-485 ports. > >Just the other day I bought a 2-port RS-232 PCI expansion card. Cost >me $17 at a local retail store, but you can get the same card online >for ~$12.
I wasn't discussing expansion cards.
>>It's been a long time since I looked, but unless I heard >>directly from someone who has achieved this with a new PC >>system, I'd be skeptical of a claim about it being easy to >>do. >> >>Maybe someone has and can fill us in about it. > >The card I just bought has a normal-looking, through-hole-mounted >crystal on it. Even a software guy like me could swap it out.
I wasn't discussing expansion cards. Jon
> > Without changing system timing, MSDOS won't give you 1ms resolution > only 1/18.5 Hz. Not sure about all forms of Windows and system clock > resolution. > >
Yes, if you use the standard timer of MSDOS. But you can use an com1: read interrupt. To get 1ms resolution, all you need is a clock. I think, you could use com2: tx interrupt to increment a counter which could be used as a timer which is faster than 1/18,5 Hz. Stefan
On Mon, 21 Jun 2010 13:41:10 +0100, Paul Carpenter
<paul@pcserviceselectronics.co.uk> wrote:

>In article <4c1f3dc4$0$3314$8e6e7893@newsreader.ewetel.de>, >stefan___@broering.de says...
>> With MSDOS or Windows, you can use every baudrate that is a >> factor/divider of 115200. > >Without changing system timing, MSDOS won't give you 1ms resolution >only 1/18.5 Hz. Not sure about all forms of Windows and system clock >resolution.
Why bother with the MSDOS clock ? On most Pentium and later processors contained the 64 bit Time Stamp Counter register, which was incremented every clock cycle. You may have to find out what the actual CPU clock frequency was, but that should not be too hard. Check availability of this counter and the availability of the RDTSC (ReaD Time Stamp Counter) instruction using the CPUID instruction.

Paul Keinanen wrote:


>>>With MSDOS or Windows, you can use every baudrate that is a >>>factor/divider of 115200. >> >>Without changing system timing, MSDOS won't give you 1ms resolution >>only 1/18.5 Hz. Not sure about all forms of Windows and system clock >>resolution. > > > Why bother with the MSDOS clock ? > > On most Pentium and later processors contained the 64 bit Time Stamp > Counter register, which was incremented every clock cycle. You may > have to find out what the actual CPU clock frequency was, but that > should not be too hard. > > Check availability of this counter and the availability of the RDTSC > (ReaD Time Stamp Counter) instruction using the CPUID instruction.
Any PC since beginning till our days has 8253 (or compatible), clocked from 14.318MHz/12 ~ 1.193MHz. It can be used for the accurate time measurement. Leave channel#0 at the division ration of 65536 as it is, set channel#2 to 65535, don't touch channel#1 as it was used for memory refresh in the old times. You can measure time intervals up to an hour with the resolution of one tick of 1.193MHz. It works for any version of DOS up to Windows XP. Vista and Win7 won't let you into the ports. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
On 2010-07-05, Paul Keinanen <keinanen@sci.fi> wrote:
> On Mon, 21 Jun 2010 13:41:10 +0100, Paul Carpenter ><paul@pcserviceselectronics.co.uk> wrote: > >>In article <4c1f3dc4$0$3314$8e6e7893@newsreader.ewetel.de>, >>stefan___@broering.de says... > >>> With MSDOS or Windows, you can use every baudrate that is a >>> factor/divider of 115200. >> >>Without changing system timing, MSDOS won't give you 1ms resolution >>only 1/18.5 Hz. Not sure about all forms of Windows and system clock >>resolution. > > Why bother with the MSDOS clock ? > > On most Pentium and later processors contained the 64 bit Time Stamp > Counter register, which was incremented every clock cycle. You may > have to find out what the actual CPU clock frequency was, but that > should not be too hard. > > Check availability of this counter and the availability of the RDTSC > (ReaD Time Stamp Counter) instruction using the CPUID instruction.
Be warned: if you have a dual/multi-core machine, MS Windows does _not_ keep the TSC values of the cores synchronized. You have to lock to a single core the code that's reading the TSC if you want to get useful data. -- Grant
>> Why bother with the MSDOS clock ? >> >> On most Pentium and later processors contained the 64 bit Time Stamp >> Counter register, which was incremented every clock cycle. You may >> have to find out what the actual CPU clock frequency was, but that >> should not be too hard. >> >> Check availability of this counter and the availability of the RDTSC >> (ReaD Time Stamp Counter) instruction using the CPUID instruction. > > Any PC since beginning till our days has 8253 (or compatible), clocked > from 14.318MHz/12 ~ 1.193MHz. It can be used for the accurate time > measurement. Leave channel#0 at the division ration of 65536 as it is, > set channel#2 to 65535, don't touch channel#1 as it was used for memory > refresh in the old times. You can measure time intervals up to an hour > with the resolution of one tick of 1.193MHz. It works for any version of > DOS up to Windows XP. Vista and Win7 won't let you into the ports. >
Sounds good. I am not so familiar with this type of programming on a pc. Its also a long time since i read technical documents about this. The trick with the com-tx int which was used as a timer, was about 25 years ago mentioned in an article in a german computer magazine (MC or C&#4294967295;t). There was also a description of the hardware components of a pc. I think, it was in May 1985 or so. I only used the articles to write programs for the com-port under turbo-pascal at that times. Nowadays, i do microcontroller programming and a bit Delphi. Best regards Stefan

Memfault Beyond the Launch