mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 16:31:31 +00:00
Starts poking at a pure total-based formula.
On the assumption that any relevant DC offset will fall out in the wash. This causes one 400kb disk to boot in a Macintosh 128kb, another couple to do reasonably well. So it's better than what was here before.
This commit is contained in:
parent
e3f22e5787
commit
260843e5b1
@ -26,22 +26,23 @@ void DriveSpeedAccumulator::post_sample(uint8_t sample) {
|
||||
// Treat 33 as a zero point and count zero crossings; then approximate
|
||||
// the RPM from the frequency of those.
|
||||
int samples_over = 0;
|
||||
int sum = 0;
|
||||
const uint8_t centre = 33;
|
||||
for(size_t c = 0; c < 512; ++c) {
|
||||
if(samples_[c] > centre) ++ samples_over;
|
||||
sum += samples_[c];
|
||||
}
|
||||
|
||||
// TODO: if the above is the correct test, do it on sample receipt rather than
|
||||
// bothering with an intermediate buffer.
|
||||
|
||||
// The below fits for a function like `a + bc`; I'm not sure it's
|
||||
const float duty_cycle = float(samples_over) / float(samples_.size());
|
||||
const float rotation_speed = 392.0f + duty_cycle * 19.95f;
|
||||
// The below fits for a function like `a + bc`.
|
||||
const float rotation_speed = (float(sum) * 0.052896440564137f) - 259.0f;
|
||||
|
||||
for(int c = 0; c < number_of_drives_; ++c) {
|
||||
drives_[c]->set_rotation_speed(rotation_speed);
|
||||
}
|
||||
// printf("RPM: %0.2f (%d over)\n", rotation_speed, samples_over);
|
||||
// printf("RPM: %0.2f (%d over; %d sum)\n", rotation_speed, samples_over, sum);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user