Hello, I am new to the forum and I am new to programming. I’m trying to control the minigenerator (AD 9837 MiniGen Sparkfun) and I can not even get a square signal.
The post on futurascience forum is my post for francophones. I tried everything but I still can not control this generator. No square or sinusoidal triangle signal works
I put you all the links below:
- The Minigen : MiniGen Hookup Guide - learn.sparkfun.com
- The librairy : https://github.com/sparkfun/MiniGen
- The code example I have insipired : https://github.com/sparkfun/MiniGen/blob/master/Libraries/Arduino/examples/SparkFun_MiniGen_Library_Test/SparkFun_MiniGen_Library_Test.ino
- electric circuit (just replace the mini arduino pro by the minigen sparkfun (same pin) in your mind and you have my editing) : [Programmation] Utilisation du SPI arduino pour contrôler un générateur
The code :
#include <SPI.h>
#include <SparkFun_MiniGen.h>
// Create an instance of the MiniGen device; note that this has no provision for
// alternate CLK and MOSI pins, but you *can* pass it a different CS (or FSYNC,
// as it's referred to elsewhere) pin number.
MiniGen gen;
void setup()
{
pinMode(10, OUTPUT);
Serial.begin(9600);
digitalWrite(10, HIGH);
SPI.setDataMode(SPI_MODE2);
SPI.begin();
SPI.setBitOrder(MSBFIRST); // LSBFIRST does not work too
delay(100);
// Clear the registers in the AD9837 chip, so we're starting from a known
// location. Note that since the AD9837 has no DOUT, we can't use the
// read-modify-write method of control. At power up, the output frequency
// will be 100Hz.
gen.reset();
delay(2000);
// SQUARE is, as it suggests, a square wave. SQUARE is at the current output
// frequency.
gen.setMode(MiniGen::SINE);
delay(3000);
// This needs a little explanation. The choices are FULL, COARSE, and FINE.
// a FULL write takes longer but writes the entire frequency word, so you
// can change from any frequency to any other frequency. COARSE only allows
// you to change the upper bits; the lower bits remain unchanged, so you
// can do a fast write of a large step size. FINE is the opposite; quick
// writes but smaller steps.
gen.setFreqAdjustMode(MiniGen::FULL);
}
void loop(){
int tension;
tension = analogRead(A0);
float voltage = (tension/1024.0)*3.3;
Serial.println(voltage);
byte c;
// enable Slave Select
digitalWrite(10, LOW); // SS is pin 10
// send test string
for (const char * p = "Fab" ; c = *p; p++)
SPI.transfer (c);
// disable Slave Select
digitalWrite(10, HIGH);
delay (100);
}
Thank you for you help