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: 11108
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-10 20:29
chatGPZ

Registered: Dec 2001
Posts: 11108
Wasnt there some protection doing something similar? MMmmh.

I thought you'd set up a timer that underflows say 50 cycles (much more than a byte takes), then you read a byte and add/sub from the timer value alternating values until you are at perfect zero after reading (maybe more than one) byte. *shrug*
2020-08-10 20:33
tlr

Registered: Sep 2003
Posts: 1714
Quoting Groepaz
Wasnt there some protection doing something similar? MMmmh.

I thought you'd set up a timer that underflows say 50 cycles (much more than a byte takes), then you read a byte and add/sub from the timer value alternating values until you are at perfect zero after reading (maybe more than one) byte. *shrug*

The point wasn't the protection bit. The point is that you can generate a squarish pattern on the msb of $1c00, perhaps allowing a simpler way of cycle exact synchronization.
2020-08-10 20:44
chatGPZ

Registered: Dec 2001
Posts: 11108
Yeah it might be easier, of course. I'm still thinking along the lines of just reading an arbitrary track (sector headers). Why go the easier route when you don't have to? :)
2020-08-10 20:54
tlr

Registered: Sep 2003
Posts: 1714
Fair enough. :)
2020-08-10 23:48
Zibri
Account closed

Registered: May 2020
Posts: 304
IMHO:

Whatever could be the error of a quartz is totally irrelevant to the RPM calculations.
Even the worst quarts loose or gain a few seconds per year. Not only we are talking about measuring 200milliseconds but the quarts real frequency is divided by 16 (iirc).

Writing a test track: https://github.com/Zibri/C64-1541-Speed-Test/blob/master/rpm.prg

Or not writing a test track: https://github.com/Zibri/C64-1541-Speed-Test/blob/master/rpm3wr..

Give exactly the same result. (the first one is more reliable since he knows the track is written correctly, while the second "wrong" one assumes (hence the "wrong") that track 35 is formatted and never written to.

Any accuracy below the 2 digits is not enough to assess the status of the belt or mechanics and disk.

Any accuracy over the 2 digits does not add any useful information and will just induce more latency.

Just fyi, the "wrong" version was tested even with disks formatted by a drive whose speed was 290RPM at the time of formatting and still showed the right speed before and after the tuning.
2020-08-10 23:52
chatGPZ

Registered: Dec 2001
Posts: 11108
Quote:
Even the worst quarts looses or gains a few seconds per year.

wat.

you should re-read the thread perhaps. the deviation you can expect from the quarz results in almost 10 times bigger error than your supposed 3 cycles jitter. soci was quite correct with what he said.
2020-08-11 02:32
ChristopherJam

Registered: Aug 2004
Posts: 1378
Quoting Zibri
IMHO:

Whatever could be the error of a quartz is totally irrelevant to the RPM calculations.
Even the worst quarts loose or gain a few seconds per year. Not only we are talking about measuring 200milliseconds but the quarts real frequency is divided by 16 (iirc).


Dividing the frequency by 16 doesn't change the percentage error. If it's 20-30ppm before you divide by 16, it's 20-30ppm after - in either case that's going to be bigger than the 10ppm error you get from 2 cycles jitter on a measurement of a ~200,000 cycle time period

Quote:
Just fyi, the "wrong" version was tested even with disks formatted by a drive whose speed was 290RPM at the time of formatting and still showed the right speed before and after the tuning.


Every version of any tool that determines RPM by timing one or more full rotations of the disk (ie any of the releases by you, Groepaz or I under discussion) will be unaffected by the speed of the drive used to write the track being read, regardless of whether it's a special track or just whatever data is already there.

It's still a 360 degree rotation each time a marker or selected sector sails by.

I'd have been a lot more surprised if you'd manage to get a *wrong* answer from a disk that was written at a different speed, that would be quite special :)
2020-08-11 03:22
Zibri
Account closed

Registered: May 2020
Posts: 304
Quoting ChristopherJam

I'd have been a lot more surprised if you'd manage to get a *wrong* answer from a disk that was written at a different speed, that would be quite special :)

Well, I didn't do the math but since I read (past tense) 6 bytes, I thought that if a drive is really slow it could mistake 5 bytes for 6... but I think it should be so slow that this thought was just theoretical.

Anyway, Just to be on the safe side, I wrote a new version:

It uses a slightly different way to measure the speed.
It uses track 36 if writing is enabled and track 35 if writing is disabled.
(But in this case it expects track 35 to be formatted and empty and never written)
It is still as fast as before.
It is still as accurate as before.

It has been tested on at least 20 different drives and the speed reported by my program was compared to the speed read optically by the strobe "disc" printed on the motor spindle.

If anyone has a better way to check (by instruments) the motor speed we can do the final tests but I am pretty confident there will be no difference.

I undesrtand your theoretical thoughts about quartz tolerances but empirically I can tell that so far it has been proven to be very accurate.

If you want to test it, here is the new version.
https://github.com/Zibri/C64-1541-Speed-Test/blob/master/rpm4.p..

...but I still think the first version is perfect...
2020-08-11 08:21
Oswald

Registered: Apr 2002
Posts: 5017
Ive seen on youtube a device that measures rpm by sound
2020-08-11 08:54
Krill

Registered: Apr 2002
Posts: 2839
Quoting ChristopherJam
Dividing the frequency by 16 doesn't change the percentage error. If it's 20-30ppm before you divide by 16, it's 20-30ppm after - in either case that's going to be bigger than the 10ppm error you get from 2 cycles jitter on a measurement of a ~200,000 cycle time period.
Indeed, but the errors add. So even getting rid of the smaller part is the pointless demoscene thing to do, just because! :D

That said, a simple way to get down from 2 cycles jitter to 1 cycle is using a chain of 18-ish "BVS readtimer" instead of "BVC *". (Or 11-ish NOPs plus 7-ish BVS in the red zone, you get the idea.)

Will give either 0-cycle delay (spot on) or be 1 cycle late.
Previous - 1 | ... | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ... | 28 | 29 - 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
manganoid/Hokuto Force
j0x
Airwolf/F4CG
celticdesign/G★P/M..
tlr
Lavazza/Censor Design
Flex/Artline Designs
Magic/Nah-Kolor
Guests online: 140
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 The Ghost  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.8)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 S!R  (9.9)
3 Mr Zero Page  (9.8)
4 Antitrack  (9.8)
5 OTD  (9.8)

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