Skip to content

Commit 77adccc

Browse files
committed
Added comments to example sketch
1 parent 48b206e commit 77adccc

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Arduino/Libraries/MiniGen/Library_Test/Library_Test.ino

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,85 @@
1+
/******************************************************************************
2+
Library_Test.ino
3+
Library test file for the MiniGen library.
4+
Mike Hord @ SparkFun Electronics
5+
6 May 2014
6+
https://github.com/sparkfun/MiniGen
7+
8+
This is a simple test/example file for the MiniGen board and library.
9+
10+
The MiniGen is a Pro Mini shield-type board (although it can be used as a
11+
standalone product as well) that generates sine, square and triangle waves up
12+
to a frequency of approximately 3MHz; above 3MHz, you'll start to see rolloff
13+
as the anti-aliasing filter on the output begins to affect the signal. Expect
14+
a peak-to-peak amplitude of about 1V and a DC offset of Vcc/2.
15+
16+
Resources:
17+
Uses the MiniGen library and the built-in SPI library.
18+
19+
Development environment specifics:
20+
Code developed in Arduino 1.0.5, on an Arduino Pro Mini 5V.
21+
22+
This code is beerware; if you see me (or any other SparkFun employee) at the
23+
local, and you've found our code helpful, please buy us a round!
24+
25+
Distributed as-is; no warranty is given.
26+
******************************************************************************/
27+
// Due to limitations in the Arduino environment, SPI.h must be included both
28+
// in the library which uses it *and* any sketch using that library.
129
#include <SPI.h>
230
#include <MiniGen.h>
331

32+
// Create an instance of the MiniGen device; note that this has no provision for
33+
// alternate CLK and MOSI pins, but you *can* pass it a different CS (or FSYNC,
34+
// as it's referred to elsewhere) pin number.
435
MiniGen gen;
536

637
void setup()
738
{
39+
// Clear the registers in the AD9837 chip, so we're starting from a known
40+
// location. Note that since the AD9837 has no DOUT, we can't use the
41+
// read-modify-write method of control. At power up, the output frequency
42+
// will be 100Hz.
843
gen.reset();
944
delay(2000);
45+
46+
// SQUARE is, as it suggests, a square wave. SQUARE is at the current output
47+
// frequency.
1048
gen.setMode(MiniGen::SQUARE);
1149
delay(3000);
50+
51+
// SQUARE_2 is at half the normal output frequency.
1252
gen.setMode(MiniGen::SQUARE_2);
1353
delay(3000);
54+
55+
// Exactly what you think it is.
1456
gen.setMode(MiniGen::TRIANGLE);
1557
delay(3000);
58+
59+
// Yep.
1660
gen.setMode(MiniGen::SINE);
61+
62+
// This needs a little explanation. The choices are FULL, COARSE, and FINE.
63+
// a FULL write takes longer but writes the entire frequency word, so you
64+
// can change from any frequency to any other frequency. COARSE only allows
65+
// you to change the upper bits; the lower bits remain unchanged, so you
66+
// can do a fast write of a large step size. FINE is the opposite; quick
67+
// writes but smaller steps.
1768
gen.setFreqAdjustMode(MiniGen::FULL);
1869
}
1970

2071
void loop()
2172
{
73+
// Loop is going to increase the frequency in steps of 10Hz, basically
74+
// forever. Since the upper limit is 3MHz, you'll probably not sit
75+
// around long enough for frequency to overflow.
2276
static float frequency = 10.0;
77+
78+
// freqCalc() makes a useful 32-bit value out of the frequency value (in
79+
// Hz) passed to it.
2380
unsigned long freqReg = gen.freqCalc(frequency);
81+
82+
// Adjust the frequency. This is a full 32-bit write.
2483
gen.adjustFreq(MiniGen::FREQ0, freqReg);
2584
delay(100);
2685
frequency += 10.0;

0 commit comments

Comments
 (0)