/*
 * Copyright(C) Paul und Scherer (mct.de/mct.net)
 *
 * This example demonstrates how to...
 *
 *  ... generate a sine wave using DDS.
 */

#include <stdio.h>
#include <target.h>

/*
 * Connect a scope to VDACout.
 *
 * You are prompted for the frequency select word (FSW).
 * The sine wave has the frequency: FSW*20.8896MHz/2^32.
 */
int
main(void)
{
	/*
	 * Reference voltage
	 *
	 * Setting refcon to 1 activates the internal
	 * reference and connects it to the Vref pin.
	 *
	 * Note: A 0.47uF capacitor is required (from
	 * Vref to GND) for proper operation!
	 */
	Intern_refcon = 1;

	Intern_daccon = 0x26;			// DDS/DAC active, output enable
	Intern_ddscon = 0x28;			// output enable, scale ratio =1

	while (1) {
		char line[9];			// input buffer
		long new;			// new FSW

		printf("Current FSW: %08lx\n"
		       "New FSW (0.. ffffffff): ", Intern_ddsfrq);
		fgets(line, sizeof(line), stdin);
		putchar('\n');
		if (sscanf(line, "%lx", &new) == 1) Intern_ddsfrq = new;
		else puts("?");
	}
}
