fixed calibration loop

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1352 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Arnim Läuger 16 years ago
parent 794cc6bbd0
commit 92ee843b70

@ -1,5 +1,7 @@
2008-09-06 Arnim Laeuger <arniml@users.sourceforge.net>
* src/tap/cable/generic.c: fixed calibration loop
* src/svf/svf.c: require frequency setting from cable for
RUNTEST MIN SEC command, fixes
[ 2090432 ] SVF programming problem with "x SEC" arg to runtest

@ -357,26 +357,24 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency )
{
if (new_frequency == 0) {
cable->delay = 0;
cable-> frequency = 0;
cable->frequency = 0;
} else {
const double tolerance = 0.1;
uint32_t loops;
const uint32_t loops = 2000;
uint32_t delay = cable->delay;
uint32_t frequency = cable->frequency;
printf("requested frequency %u, now calibrating delay loop\n", new_frequency);
if (new_frequency > (1.0 - tolerance) * frequency &&
new_frequency < (1.0 + tolerance) * frequency)
return;
if (delay == 0) {
delay = 1000;
loops = 10000;
} else {
loops = 3 * frequency;
}
printf("requested frequency %u, now calibrating delay loop\n", new_frequency);
while (1) {
uint32_t i, new_delay;
long double start, end, real_frequency;
cable->delay = delay;
start = frealtime();
for (i = 0; i < loops; ++i) {
cable->driver->clock(cable, 0, 0, 1);
@ -388,11 +386,11 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency )
printf("new real frequency %Lg, delay %u\n",
real_frequency, delay);
loops = 3 * fmax(real_frequency, new_frequency);
new_delay = (long double)delay * real_frequency / new_frequency;
if (real_frequency >= (1.0 - tolerance)*new_frequency) {
if (real_frequency <= (1.0 + tolerance)*new_frequency) {
frequency = real_frequency;
break;
}
if (new_delay > delay) {
@ -400,16 +398,20 @@ generic_set_frequency( cable_t *cable, uint32_t new_frequency )
} else {
delay++;
}
} else {
if (new_delay < delay) {
delay = new_delay;
} else {
delay--;
}
if (delay == 0) {
printf("operating without delay\n");
frequency = real_frequency;
break;
}
if (new_delay < delay) {
delay = new_delay;
} else {
if (delay > 0)
delay--;
}
}
}

Loading…
Cancel
Save