From owner-freebsd-multimedia Fri Mar 28 05:05:53 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id FAA09747 for multimedia-outgoing; Fri, 28 Mar 1997 05:05:53 -0800 (PST) Received: from deacon.cogsci.ed.ac.uk (deacon144.cogsci.ed.ac.uk [129.215.144.7]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id FAA09742 for ; Fri, 28 Mar 1997 05:05:48 -0800 (PST) Received: from pitcairn.cogsci.ed.ac.uk (pitcairn.cogsci.ed.ac.uk [129.215.197.19]) by deacon.cogsci.ed.ac.uk (8.6.10/8.6.12) with ESMTP id NAA18037; Fri, 28 Mar 1997 13:05:43 GMT Date: Fri, 28 Mar 1997 13:05:41 GMT Message-Id: <27629.199703281305@pitcairn.cogsci.ed.ac.uk> From: Richard Tobin Subject: Tuner AFC To: Steve Passe Organization: just say no Cc: multimedia@freebsd.org Sender: owner-multimedia@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 #include #include #include #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; }