Date: Fri, 28 Mar 1997 13:05:41 GMT From: Richard Tobin <richard@cogsci.ed.ac.uk> To: Steve Passe <smp@csn.net> Cc: multimedia@freebsd.org Subject: Tuner AFC Message-ID: <27629.199703281305@pitcairn.cogsci.ed.ac.uk>
next in thread | raw e-mail | index | archive | help
It turns out that some of the channels here aren't on precisely the
official frequencies, so I wrote a program to do AFC.
The AFC works using the 3 bottom bits of the tuner status register.
When it's centred, they are 0 1 0. 1 0 0 means it's too low, 0 0 1
too high. The TEMIC datasheet refers to a 5-level ADC suggesting
that it might return 1 1 0 or 0 1 1 but that doesn't seem to happen
for me.
-- Richard
afc.c:
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <machine/ioctl_bt848.h>
#define AFC 7
#define MAX_STEP (5 * 16) /* Don't move more than 5 MHz */
void xerror(char *msg)
{
perror(msg);
exit(1);
}
int main(int argc, char **argv)
{
int fd, f, step, stat;
fd = open("/dev/tuner0", O_RDONLY);
if(fd < 0)
xerror("/dev/tuner0");
if(ioctl(fd, TVTUNER_GETFREQ, &f) < 0)
xerror("getfreq ioctl");
printf("starting at %f MHz\n", f / 16.0);
for(step = 0; step < MAX_STEP; step++)
{
if(ioctl(fd, TVTUNER_GETSTATUS, &stat) < 0)
xerror("getstatus ioctl");
if((stat & AFC) == 2)
{
printf("stopped at %f MHz\n", f / 16.0);
return 0;
}
if((stat & AFC) > 2)
f++;
else
f--;
if(ioctl(fd, TVTUNER_SETFREQ, &f) < 0)
xerror("setfreq ioctl");
}
printf("abandoned at %f MHz\n", f / 16.0);
return 0;
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?27629.199703281305>
