Go Down

Topic: Code to control the generator AD 9837 MiniGen Sparkfun with arduino Uno (Read 409 times) previous topic - next topic


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 : https://learn.sparkfun.com/tutorials/minigen-hookup-guide/all
- 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) : https://forums.futura-sciences.com/electronique/847059-utilisation-spi-arduino-controler-un-generateur.html#post6346230
The code :
Code: [Select]
#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);
  digitalWrite(10, HIGH);
  SPI.setBitOrder(MSBFIRST); // LSBFIRST does not work too

  // 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.
  // SQUARE is, as it suggests, a square wave. SQUARE is at the current output
  //  frequency.
  // 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.

void loop(){
  int tension;
  tension = analogRead(A0);
  float voltage = (tension/1024.0)*3.3;
  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  :smiley-confuse:


Code: [Select]
  // SQUARE is, as it suggests, a square wave. SQUARE is at the current output
  //  frequency.

That comment looks rather stupid there.

Code: [Select]
  int tension;
  tension = analogRead(A0);

That could be done in one line. And should.

Go Up