/*          Copyright 1995  Novatech Instruments, Inc.
            1530 Eastlake Ave East, Suite 303
            Seattle, Washington 98102

FILE:       bits.c

This file, written for and compiled by Power C, prints the binary
values required for Novatech Instruments, Inc. modular Direct
Digital Synthesizers.  It is provided for the convenience of Novatech
Instruments, Inc. product user and is without any warranty, expressed
or implied.

Author:
     Steven D. Swift, P.E.
     Principal Engineer
     Novatech Instruments, Inc.
*/
#include <stdio.h>
void main()
{       unsigned long n ;
	double Base ;  /* resolution */
	double Freq,Fmax,Fmin;
	int Model;   /* 3 means dds3m, 4 means dds4m */
	int i;   /* counter for loop */
	unsigned long mask; /* mask to zero word */

     printf("\nWhich Model are you using ( DDS4m or DDS3m )? \n");
     printf("Type  \"3\"  for Model DDS3m, type  \"4\"  for DDS4m: ");
     scanf("%d", &Model);
     if (Model == 3) {
	Fmax = 12.000e6;
	Fmin = 2.0;
	Base = 2.0;
	i = 24;
	mask = 0x000ffffff; }
    else if (Model == 4) {
	Fmax = 34.000e6;
	Fmin = 1.0;
	Base = 0.02;
	i = 32;
	mask = 0x07fffffff; }
    else { printf("\nBogus Model number!  Must be 3 or 4. Try again.\n");
 	exit(0); }
     printf("\nInput Desired Frequency : ");
     scanf("%lf", &Freq);
   if(Freq < Fmin || Freq > Fmax) {
    printf("\nBogus Frequency!\n");
    printf("Model DDS%dm requires frequency >= %.2lf Hz and <= %.2lf MHz.\n",
		Model,Fmin,Fmax/1.0e6);
    exit(0); }
	n = (unsigned long) (Freq/Base) ;
	n = mask & n ;
	Freq = ((double) n )*Base;
printf("\nActual output Freq: %0.2lf Hz \n",Freq);
printf("Hex value needed: %lx \n",n);
printf("Binary: ");
i--;  /* MSB is always zero for these products */
while ( i >= 0 ) {
 printf("%lx ", (n >> i) & 0x00000001);  /* shift out MSB first */
 i--; }
printf("\n");
}

