ClockMaster
8/8/2002
11
www.spincore.com
// This sample application uses the PM02PC01 DLL to control the
// ClockMaster-100 board through the cm_set_freq DLL function call.
//
// SpinCore Technologies, Inc.
// August 2002
// http://www.spincore.com
//
// Notes: Remember to include PM02PC01.lib in your Project settings when
//
using the PM02PC01 DLL
//
#include <stdio.h>
#include <math.h>
#define KILO
1000
#define MEGA
1000000
#define FREQ_BITS
32
#define CLOCK_RATE
100*MEGA
// Imported Function from PM02PC01
extern "C" __declspec(dllimport) int cm_set_freq(double Freq_to_Output,
double Clock_Rate);
int main(int argc, char* argv[])
{
double
Freq, TempFreq;
Freq = 125.500;
// Freq to output in kHz
// The Output to ClockMaster
int cm_ret = cm_set_freq(Freq, CLOCK_RATE);
// Check Function Return for Success
if (cm_ret == -1) return -1;
// For Display Purposes Only, Convert to Hex and Back to get the Rounded
True Value Output
TempFreq = Freq * pow(2, FREQ_BITS - 1) * KILO / (CLOCK_RATE / 2);
TempFreq = (unsigned int) TempFreq;
TempFreq = (float) TempFreq / pow(2, FREQ_BITS - 1) * (CLOCK_RATE / 2) /
KILO;
printf("Now Outputting --\nFrequency: %.4f kHz\n", TempFreq);
return 0;
}
Appendix I: Example C Program