flat assembler
Message board for the users of flat assembler.

Index > Windows > frequency counter

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi all..

I am looking a making a PC frequency counter, but have a few questions..

If I am using the ack pin on the Lpt1 port....what would be the max frequency I could apply directly, without using divide hardware....I looked at an idea using an IRQ and count the number pulses in a fixed Time..

that would be my second question...is the IRQ's system accurate as far as time period is concerned.

will be using a 133mhz laptop.....

The idea is getting a 10hz accuracy from 30mhz down to about 3mhz.


John
Post 06 May 2010, 09:39
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac,

QNX developers' docs mention P-166 interrupt latency of 3.3 µs, thus you have to divide more than 10 times.

There is also "Raw data: Interrupt latency measurements" PDF document that contain similar (if not worse) figures.

Most SuperIOs are clocked at 24/48 MHz, this introduces additional granularity.

Do you really need this 0.0000(3)% accuracy? Let's pretend your program can handle 0.3 MHz ACK frequency: for 30 MHz ±10 Hz accuracy, measurement cycle will be… 10 seconds! Wink

Are you going to measure it under Windows? Shocked
Post 06 May 2010, 12:50
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi al


Thanks for the reply...

The general idea is similar to what is used when using a PIC...3 external Binary Counters.....being fed with a bufferd Signal...and gated into the counters...when the Gate Period is finished...then the counters are clocked until an overflow condition exsists....once that happens...count the number of pulses needed to overflow the counters..do a little Maths and you have the Frequecy......adjustment can be made if having a known frequency source....to adjust the gate period...ie if you know the Freq. and check the counters...you can work out the gate period...

Ok..a high frequency going onto the LPT1 was just a curious question....and yes I want to be able to read down to 10hz...

Ok...what slows down the LPT1 port if your not actually doing all the handshaking used while talking to a printer...
If I was to pulse say the strobe line....what would limit its speed..besides the computer clock speed.....

just additional info...the laptop I will be using(trying),,,133mhz and the LPT1 port is ECP compatable.....and from what I have read the ECP port can run at a max 2MBps

John
Post 10 May 2010, 03:30
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac,

Program PIT channel 0 with initial count 1 and try to handle all these IRQ0s (and that's only ~1.2 MHz).

ECP uses FIFO/DMA and performs handshaking itself.
Post 10 May 2010, 08:32
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Jmac wrote:
looking a making a PC frequency counter, but have a few questions..

using the ack pin on the Lpt1 port....what would

idea using an IRQ and count the number pulses in a fixed Time..


Are you sure to do this with Windows? You can't easily access the hardware or handle IRQ's then Neutral
Post 10 May 2010, 09:26
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi all.....


well possibly don't need the IRQ....can use an input instead I guess..

Using assembly....why cant I access the LPT1 port.....from memory it is easier than using the com port....maybe I am wrong ...

John
Post 10 May 2010, 10:42
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Jmac wrote:
why cant I access the LPT1 port.....


Windowz appz run in Ring3 with IOPL=0 so CLI, IN and OUT instructions don't work (and writing into the IDT usually neither) and ........................................................
Post 10 May 2010, 11:22
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi all...

well I assumed that all applies to the Com port also....and it was easy enough to send signals through that port...from memory using In and Out....
Post 10 May 2010, 11:37
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi all...


what counters are available for use in asm..

the ones I know are.....GetTickCount, QueryPerformanceCounter/Frequency RDTSC

not sure if its possible to use TmeGetTime

what is the Test if the computer has QPC..

One question that keeps confusing me...when you get the period of a piece of Code. is that an accurate value for the period....even though the count may be different the next time you run it,,,,is each count accurate in its own right....or does the counting function add in there own variable issues....

John
Post 26 May 2010, 01:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
In a multi-threaded OS like Windows you can never guarantee any execution times.

Usually, for short timing, you would do things like raising the priority and using RDTSC.

For longer times just use the wall clock. Razz

[edit] Even a modern CPU with cache poses a lot of problems for accurate timing of short functions. Usually this can cause the first run of something to take longer while the code is read directly from SDRAM, the second run, and subsequent runs, will be faster from cache (unless the OS has done something in between the runs).
Post 26 May 2010, 09:55
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
measure the execution time of a piece of code in a multitasking environment is meaningless

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 26 May 2010, 10:56
View user's profile Send private message Send e-mail Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
hi....

Yeah I get the idea about accurately measuring a section of code.....
hi....

Yeah I get the idea about accurately measuring a section of code.....

all I was looking for was to measure delay code with good resolution on each run.....I know each run wont be the same.....but all I want is when I measure it this time its accurate....I know that multiple runs will show different results....but as long as each run on its own is accurate that is all I was looking for..

Call me silly...but I still dont see why not.......regardless if something happens to slow the count or lengthen the count.....the count itself will stll be accurate when measured.. The only problem I do see, is if there is some slow down when calling the counter....that will give a false time.

all I was looking for was to measure delay code with good resolution on each run.....I know each run wont be the same.....but all I want is when I measure it this time its accurate....I know that multiple runs will show different results....but as long as each run on its own is accurate that is all I was looking for..

Call me silly...but I still dont see why not.......regardless if something happens to slow the count or lengthen the count.....the count itself will stll be accurate when measured.. The only problem I do see, is if there is some slow down when calling the counter....that will give a false time.

anyway all you guys know more about this than I do...so I will take what you say as right....and look for another option..

Just curious as to what effect setting the realtime Priority to the timing process..would have

John
Post 27 May 2010, 04:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
Jmac wrote:
Just curious as to what effect setting the realtime Priority to the timing process..would have
The OS won't switch to another task while your code is running. But if left for a long time at realtime priority system tasks tend to get left undone. Generally it is not a good idea for anything more than a few milliseconds.
Post 27 May 2010, 06:11
View user's profile Send private message Visit poster's website Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi all.

I know you have probably had enough of this topic....but I tried a program by Matrix I think it was....BUT it works on my XP..but not on my win95.
using this program the clock seems pretty stable....it did jump 1 or 2 times ..
I was trying to see how that worked on the win95 computer but it compiles ok,,, the DOS window comes up it says something about performing an illegal operation....

NOT sure what operation that is as it is suppose to work on a win95 computer

http://board.flatassembler.net/topic.php?t=2207

john
Post 28 May 2010, 00:25
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac,

It can be rdtsc (do your Win95 computer's CPU support it?) or in / out instructions used to program PIT. Step through it under debugger, you'll see where the fault occurs.
Post 28 May 2010, 00:49
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Ok.....

looking into those......but I assume if it did not support something it would not compile on the computer....wrong assumption I guess....

I have a motor controller that uses the " out " instruction ...so guessing its not the " in ".

just for the hell of it...I placed the rdtsc in the motor controller program...it ran ok...did not spit anything up...mind you...I did not check if it provided a count....but still....no illegal operation either.

The error is a General Protection exception, fault location 0A11:010E

now:

did a test on the eax register...after previously setting it to 0...
after the rdtsc instruction the program continues...thus 0 was no longer in the eax..
Post 28 May 2010, 01:33
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac wrote:
The error is a General Protection exception, fault location 0A11:010E
Then rdtsc isn't supported or is disabled (CR4.TSD==1). You may look at the disassembly of cpuspeed#4.com yourself.
Code:
00000100: FA               cli
00000101: E87800           call        00000017C
00000104: B91800           mov         cx,00018
00000107: 51               push        cx
00000108: FA               cli
00000109: E89E00           call        0000001AA
0000010C: 89C3             mov         bx,ax
0000010E: 0F31             rdtsc
00000110: 66A30402         mov         [00204],eax
00000114: 6689160802       mov         [00208],edx    
Which CPU does your Win95 box have?
Jmac wrote:
did a test on the eax register...after previously setting it to 0...
after the rdtsc instruction the program continues...thus 0 was no longer in the eax..
You ran this test on Win95 box?
Post 28 May 2010, 05:29
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi ..

thanks for the help..

Type of Processor....it only says a Pentium with VRT (133 Mhz)

yes I ran the rdtsc test on another little program using the win95 computer.
ie.....I think that test would indicate it does have rdtsc...? or am I wrong.
Post 28 May 2010, 07:03
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Jmac,

Attach failing program binary (that causes GPF at xxxx:010E). Also you may use some CPU ID program to determine exactly your CPU make/model and whether it supports rdtsc. For example, CHKCPU v1.19: with /v option it will show this exactly.
Post 28 May 2010, 07:55
View user's profile Send private message Reply with quote
Jmac



Joined: 23 Nov 2009
Posts: 54
Jmac
Hi

using that download......Intel Pentium 133 (P54) C0-step, 132.6Mhz ( using internal time stamp Counter )
Current CPU mode : Protected
Internal (L1) cache : enabled in write-back mode
Post 28 May 2010, 10:36
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.