SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Audio category should be posted in this forum.
User avatar
By LWitter
#204262
I have been trying to get the MiniGen board to work. My ultimate aim is to have a standalone board that can generate a pure tone on power up.

I am connecting the MiniGen to a Arduino Uno, via the Sparkfun Logic Level Converter( BOB12009; 5V => 3.3V). Power to the Minigen is from the 3.3V pin on the Arduino. The three pin connections are: 10 => FSYNC, 11 => SDATA, 13 => SCLK.

I have checked the pinouts with an oscilloscope to check that my sketches are actually putting out some signals. Also, I have checked again with the oscilloscope that the pulses on the three pins are actually reaching the appropriate pins on the AD9837. Some pictures of the signals on the pins:

FSYNC:
FSYNC.jpg
SDATA:
SDATA.jpg
SCLK:
SCLK.jpg
I have tried different SPI speeds, the pulses on the three pins change accordingly, but the MiniGen doesn't want to budge.

Below is the simplest code I could come up with since the reset on the MiniGen should set it to 100Hz Sine. It doesn't work though:
Code: Select all
#include <SPI.h>
#include <SparkFun_MiniGen.h>

MiniGen gen;

void setup() {
  // put your setup code here, to run once:
  gen = MiniGen(10);
  gen.reset();
}

void loop() {
  // put your main code here, to run repeatedly:

}
I also tried hard setting the SPI mode, speed, bit order and interchanged all connections (Ran through all combination options). No improvement.

This sketch should reset the MiniGen and then put out 2 seconds of 100Hz and then 1200Hz:.Also, doesn't work (Sometimes puts out some sine wave at 1000Hz for some reason).
Code: Select all
#include <SPI.h>
#include <SparkFun_MiniGen.h>

MiniGen gen;

void setup() {
  SPI.begin();
  // put your setup code here, to run once:
  SPI.setClockDivider(SPI_CLOCK_DIV64);
  
  gen = MiniGen(10);
  SPI.setDataMode(SPI_MODE2);
  SPI.setBitOrder(MSBFIRST);
  gen.reset();
  delay(1000);

  gen.setFreqAdjustMode(MiniGen::FULL);
  delay(1000);
  
  gen.setMode(MiniGen::SINE);
  delay(1000);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  float frequency = 100.0;
  unsigned long freqReg = gen.freqCalc(frequency); 
  gen.adjustFreq(MiniGen::FREQ0,MiniGen::FULL,freqReg);
  delay(2000);
  
  frequency = 1200.0;
  freqReg = gen.freqCalc(frequency); 
  gen.adjustFreq(MiniGen::FREQ0,MiniGen::FULL,freqReg);
  delay(2000);
}
The weird thing though is that sometimes the MiniGen does something seemingly random. On sometimes suddenly changes to square wave, triangle wave or sine, it sometimes changes frequency in a random direction after a reset. This makes me think that I am really doing something wrong here, but I can't figure it out. I hope someone can help me sort this out!
You do not have the required permissions to view the files attached to this post.
User avatar
By TS-Chris
#204269
Have you tried our example code? You might start with that and modify it to meet your needs.

Also, your signals look really noisy. I don't know if that's just your scope doing that or if that's what the MiniGen is actually seeing. If the MiniGen is getting noisy data, that could be causing your issues. Make sure you have all of your connections soldered securely to help eliminate the noise as that can result in unpredictable operation.
User avatar
By LWitter
#204273
I have tried the example code, but it doesn't work.

I'll have a look at getting more secure connections, but I'm doubtful that is the issue though. When I measure from a jumper cable directly connected to the UNO I get a similar waveform (but 5V of course). What I did notice is some oscillation on especially the FSYNC channel when the signal goes low. Could I filter that out with a small cap to 0V?
Looking at the datasheet of the AD9837 (which sees the inputs) I see that logic low is <0.7V and high is >2.0V which both should be fine I think. The weird signal on the SCLK channel is just aliasing of the display. I can post a more zoomed-in picture tomorrow if that helps.

I'll post the output from the UNO tomorrow to see whether that is better.
User avatar
By LWitter
#204293
Here are the direct readings from the pins (10, 11, 13) of the Arduino Uno.

10: FSYNC
Ch10_Zoom.jpg
11: SDATA
Ch11_Zoom.jpg
13: SCLK
Ch13_Zoom.jpg
The oscillation on onset doesn't seem crazy to me. Also, like I note in the previous post, they should be well within what the AD9837 can handle. If you think noise is the issue, what can I do to filter out some of it? Some capacitor to 0V?
You do not have the required permissions to view the files attached to this post.
User avatar
By TS-Chris
#204304
I tried hooking up a MiniGen through our Bi Directional LLC and I'm seeing the same issues you are. I just don't know what is causing them.

I am seeing a lot of noise and ringing on the SPI lines when I hook a scope up and I'm beginning to think that the MiniGen can't cope with the noise/ringing. If you're able to buffer the output somehow, that might do the trick, but at this point, the only solution I can think of would be to use a 3.3 volt micro controller and no level shifter. Caps might help but I can't say for sure. It won't hurt to give them a try. If you have one available, a 74HC4050 might work as a logic level converter and buffer. I don't have one here to test with unfortunately.
User avatar
By LWitter
#204394
Solved:

I ditched the level shifter board and used a CD4050BE and put a capacitor between 0 and 3.3V to dampen oscillations coming in from Vcc. I do still have to put the speed of the system down with SPI_CLOCK_DIVIDE64 though.
Now it works and does what it is supposed to do.
User avatar
By LWitter
#204395
Sorry to keep bugging you.

I want to run the board stand-alone, but for some reason it doesn't work. How do I run the board in stand-alone mode? I can't find any description.

Thanks!
Laurens