Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Accurately Measuring Drive RPM
2020-08-03 16:07
chatGPZ

Registered: Dec 2001
Posts: 11290
Accurately Measuring Drive RPM

To bring the discussion from 1541 Speed Test into the forum....

first lets recapitulate:

The general idea is: have a "marker" on a track, then measure the time for one revolution using timers. Generally there are different ways to achieve this:

- wait for the marker and toggle a IEC line. the C64 measures the time using CIA timer. this is what eg the well known "Kwik Load" copy does, the problem is that it is PAL/NTSC specific, and it can never be 100% exact due to the timing drift between drive and C64.

- wait for the marker and measure the time using VIA timers on the drive. the problem with this is that VIA timers are only 16bit and can not be cascaded, so you either have to measure smaller portions at a time, or rely on the wraparound and the value being in certain bounds at the time you read it.

now, to make either way slightly more accurate, a special kind of reference track can be used. typically this track will contain nothing except one marker - which makes the code a bit simpler and straightforward. this is what 1541 Speed Test does. the DOS also does something similar when formatting, to calculate the gaps. This obviosly has the problem that we are overwriting said track.

Now - the question isn't how to do all this, that's a solved problem. The question is, given a specific implementation, how *accurate* is it actually, and why?

The basic math to calculate the RPM is this:

expected ideal:
300 rounds per minute
= 5 rounds per second
= 200 milliseconds per round
at 1MHz (0,001 milliseconds per clock)
= 200000 cycles per round

to calculate RPM from cycles per round:
RPM = (200000 * 300) / cycles

two little test programs are here: https://sourceforge.net/p/vice-emu/code/HEAD/tree/testprogs/dri.. ... the first reads timer values between each sector header and then the total time for a revolution is accumulated from the delta times. the second leaves the timer running for one revolution and then indirectly gets the time for a revolution from that. to my own surprise, both appear to be accurate down to 3 cycles (in theory the second one should be more accurate, at least thats what i thought. i also expected some more jitter than just 3 cycles)

1541 Speed Test writes a track that contains one long sync, and then 5 regular bytes which serve as the marker. it then reads 6 bytes and measures the time that takes, which equals one revolution. somehow this produces a stable value without any jitter, which was a bit surprising to me too (i expected at least one cycle jitter, due to the sync waiting loops) (i am waiting for the source release and will put a derived test into the vice repo too)

So, again, the question is... how accurate are those and why? (a stable value alone does not tell its accurate). Some details are not quite clear to me, eg if we are writing a reference track, how much will that affect the accuracy of the following measurement? how will the result change when the reference track was written at a different speed than when doing the measuring? Will using a certain speedzone make it more or less accurate?

Bonus question: can we use https://en.wikipedia.org/wiki/Chinese_remainder_theorem with two VIA timers to make this more accurate? or is it a pointless exercise?
 
... 263 posts hidden. Click here to view all posts....
 
2020-08-06 14:13
chatGPZ

Registered: Dec 2001
Posts: 11290
I dont see why using a disk written on a drive with different speed causes a different type of error with the "wait for sector 0" method than with using a test track. because basically both do the same thing (see post above). unless perhaps you write the test track again and again? please elaborate. As i understand, when you start and read the timer at the same point on the disk after one revolution, it doesnt matter at all if the sync before that is longer or "stretched" or whatever - you are still starting and reading the timer at the exact same spot.

PS: it might also be worth trying P64 images for these experiments, in theory they do not have the mentioned limitations of G64 files. (Now that i wrote it... P64 rotation code always uses 300rpm no matter what. meh)
2020-08-06 15:43
Zibri
Account closed

Registered: May 2020
Posts: 304
They are not the same thing.
The test track I used in my program is a long sync followed by five bytes that start and end with a 0, a different byte would cause another 3 or even 6 cycle error.
Measuring data, you are subject to reading and writing speeds "deltas".
Now, this difference is insignificant mathematically in the case of the 5 bytes but the more BVC loops you use to read bytes the more significant it will be.
To be even more accurate I could use 2 or 3 bytes but after some testing there seems to be no problem using 5 because even a totally out of speed drive will always read and write about 5 bytes and something leading anyway to a full revolution.

My program is still accurate on totally out of speed (real) drives.
And I repeat: I see nothing wrong in writing track 36 which is out of the standard tracks of a normal disk which you are supposed to use for testing the drive anyways.

In the D64 archive on github there is also a small configure program which creates a customized version allowing to change the test track, the hardness of the track42 align and afew other parameters.
But that is useful only if who fixes the drives has special needs.
2020-08-06 15:51
Zibri
Account closed

Registered: May 2020
Posts: 304
Quoting tlr
I'm assuming here that you are still measuring time (as opposed to capacity)


Indeed.
It is also possible to write a long bit pattern and then count "how many bits did I write?".
This could also work but it is more difficult to implement with absolutely no advantage.
Counting bytes instead of bits is also possible but it will lead to less accuracy too.
Before chosing the implementation, I considered all possibilities and I chose the more effective, easier to code, fastest to check and best overall.
The result speaks for itself.
I could add the number of bytes written (5 now) as a parameter in the configure program, but I doublt it would be really useful.
2020-08-06 15:52
chatGPZ

Registered: Dec 2001
Posts: 11290
i dont see how reading more or less bytes makes a difference, you are in sync with the disk after each byte (with 2 cycles jitter). if that wasnt the case and errors added up like you say, you'd never be able to read a sector.
2020-08-06 16:02
Zibri
Account closed

Registered: May 2020
Posts: 304
Quoting Groepaz
unless perhaps you write the test track again and again? please elaborate.

No. I write the test track at the start of the test.
I could avoid it and write it just once and check if it's there otherwise write it again, but why?
Again: I see no problem at all in writing a test track.
Doing so I am sure the test results are independent of any external factors induced by who wrote the disk, how it was formatted, etc.
2020-08-06 16:10
Silver Dream !

Registered: Nov 2005
Posts: 108
Quoting Zibri

And I repeat: I see nothing wrong in writing track 36 which is out of the standard tracks of a normal disk which you are supposed to use for testing the drive anyways.

Being Dolphin user, virtually all of my disks are 40 tracks formatted. While you can of course say "read the docs, they say you must not use disks containing data on track 36 (or whichever)", it is still a very good and common practice to at least warn the user before destructive operations. So yes - I see nothing wrong with destroying data even on the whole disk as long as the user is forewarned and can safely confirm his intentions or cancel the operation. Just that.
2020-08-06 16:12
Zibri
Account closed

Registered: May 2020
Posts: 304
Quoting Groepaz
i dont see how reading more or less bytes makes a difference, you are in sync with the disk after each byte (with 2 cycles jitter). if that wasnt the case and errors added up like you say, you'd never be able to read a sector.


I know you don't see it.
The reading is not in sync with a clock, but with the written bits.
Reading let's say 100 bytes written by a slow drive will take way less time than reading 100 bytes written by a fast drive.

And this happens even if it is the same drive writing and reading.

As I said, I studied the drive down to the schematics.
I suggest you to do the same and do not rely too much on "commented roms" because 50% of the important routines are commented or understood/explained wrong.

An example:
check BIT 5 and BIT 6 of $1C00 in most commented roms I found their function is written badly.
If you check the schematics of 1541 their function becomes immediately clear.
2020-08-06 16:15
Zibri
Account closed

Registered: May 2020
Posts: 304
Quoting Silver Dream !

Being Dolphin user, virtually all of my disks are 40 tracks formatted. While you can of course say "read the docs, they say you must not use disks containing data on track 36 (or whichever)", it is still a very good and common practice to at least warn the user before destructive operations. So yes - I see nothing wrong with destroying data even on the whole disk as long as the user is forewarned and can safely confirm his intentions or cancel the operation. Just that.

And that's where the configure program comes into play:
just set 41 as your test track and you are good to go.
Instructions were incomplete at the time a friend of mine uploaded the program to csdb, but it is written clearly in the instructions on github.
2020-08-06 16:17
chatGPZ

Registered: Dec 2001
Posts: 11290
Quote:
The reading is not in sync with a clock, but with the written bits.

exactly. and every time 8 bits arrived in the shift register, V flag is being set to signal just that. in turn that means after every byte (BVC *) we are in sync (with 2 cycles jitter) to the bits on the disk. it doesnt matter how often we do this, every single time we are again in sync. if that wouldnt be the case, you wouldnt be able to read more than a couple bytes without an extra sync marker.
2020-08-06 16:31
Zibri
Account closed

Registered: May 2020
Posts: 304
Quoting Groepaz
Quote:
The reading is not in sync with a clock, but with the written bits.

exactly. and every time 8 bits arrived in the shift register, V flag is being set to signal just that. in turn that means after every byte (BVC *) we are in sync (with 2 cycles jitter) to the bits on the disk. it doesnt matter how often we do this, every single time we are again in sync. if that wouldnt be the case, you wouldnt be able to read more than a couple bytes without an extra sync marker.

Yes, that is obvious, but I don't understand what you are trying to say.
Since we count the time, yes we are in sync, but it will take more or less time depending on drive speed.
But in that way you are anyway counting bytes.
That's unacceptable inaccuracy in my book.
I thought of counting bits, and it was ok, but the program was overly complex.
My final approach resulted to be the best.
I see no reason to change it.
Previous - 1 | ... | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ... | 28 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
celticdesign/G★P/M..
hedning/G★P
iAN CooG/HVSC
Airwolf/F4CG
Tomxx/KAplus
Sychamis
Guests online: 123
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 Uncensored  (9.6)
7 Comaland 100%  (9.6)
8 Wonderland XIV  (9.6)
9 No Bounds  (9.6)
10 Unboxed  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Morph  (9.5)
8 Dawnfall V1.1  (9.5)
9 Onscreen 5k  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.2)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.069 sec.