Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: uM2(+): AD9833 Function generator Post ReplyPost New Topic
Page of 2 Next >>
Author
Message << Prev Topic | Next Topic >>
matherp
Guru
Guru


Joined: 11 December 2012
Location: United Kingdom
Online Status: Offline
Posts: 2708
Posted: 13 October 2015 at 10:18am | IP Logged Copy link to clipboard   Quote matherp

The AD9833 is a DDS function generator programmable by a SPI interface. The version I bought , pictured below, includes a MCP41010 8-bit digital potentiometer and an opamp to boost and control the amplitude of the output.



The attached Basic program shows how to control both the potentiometer and function generator to create Sine, Triangle, and Square waves of varying amplitude and frequency. It would be easy to combine this code with the GUI from this post to make a complete application.


OPTION EXPLICIT
OPTION DEFAULT NONE
'
' AD9833 Control Bits
'
CONST B28%=&H2000
CONST HLB%=&H1000
CONST FSELECT%=&H800
CONST PSELECT%=&H400
CONST RESET%=&H100
CONST SLEEP1%=&H80
CONST SLEEP12%=&H40
CONST OPBITEN%=&H20
CONST DEV2%=8
CONST MODE%=2
'
' Micromite pin allocation
'
CONST CS%=24 ' pin for MCP41010 chip select (CS) pin on module
CONST FSY%=23 ' pin for AD9833 chip select(FSY) pin on module
'
' Output modes 
'
CONST TRIANGLE%=1
CONST SINE%=0
CONST SQUARE%=-1
'
pin(CS%)=1
PIN(FSY%)=1
setpin CS%,dout
setpin FSY%,dout
spi open 1000000,2,16 'has to be mode 2 for AD9833, MCP41010 doesn't seem to mind
'
  updateamplitude(255) 'scale output 100%
DO
  updatefrequency(20000,SQUARE%) '20KHz square wave
  pause 2000
  updatefrequency(10000,TRIANGLE%) '10KHz triangle wave
  pause 2000
  updatefrequency(40000,SINE%) '40KHz sine wave
  PAUSE 2000
LOOP
end
'
sub updateamplitude(i%) ' Sets the output of the MCP41010 digital potentiometer (0-255)
  local j%=&H1100 OR (i% AND 255)
  pin(CS%)=0
  spi write 1,j%
  PIN(CS%)=1
end sub
'
sub updatefrequency(fin%, wave%) 'Sets the frequency (Hz) and waveform of the AD9833 (Sine:wave%=0, Triangle:wave%=1, Square:wave%=-1)
  local oscillator%=25000000 'Crystal frequency
  local twoby28%=268435456 '2^28
  local f%=(fin%*twoby28%)\oscillator%
  LOCAL c%=0
  local f1%=(f% and &H3FFF) OR &H4000
  local f2%=(f%>>14) OR &H4000
  LOCAL p%=&B1100000000000000
  if wave% =1 then c%=c% OR MODE%
  if WAVE%=-1 then c%=c% OR SLEEP12% OR OPBITEN% OR DEV2%
  pin(FSY%)=0
  spi write 5,c% OR RESET% OR B28%,f1%,f2%,p%,c%
'  print bin$(c% OR RESET% OR B28%,16)," ",bin$(f1%,16)," ",bin$(f2%,16)," ",bin$(p%,16)," ",bin$(c%,16)
  PIN(FSY%)=1
end sub


Edited by matherp on 13 October 2015 at 11:09am



Back to Top View matherp's Profile Search for other posts by matherp
 
boss
Senior Member
Senior Member
Avatar

Joined: 19 August 2011
Location: Canada
Online Status: Offline
Posts: 268
Posted: 13 October 2015 at 3:35pm | IP Logged Copy link to clipboard   Quote boss

Nice idea

another choice is to use an optical encoder. I found this one (Grayhill with push button) on ebay for ~$10 new.





Back to Top View boss's Profile Search for other posts by boss
 
disco4now
Guru
Guru


Joined: 18 December 2014
Location: Australia
Online Status: Offline
Posts: 345
Posted: 21 April 2016 at 1:32pm | IP Logged Copy link to clipboard   Quote disco4now

I ordered one of the AD9833 modules above sometime ago and started to write a GUI for it. I was removing the header pins to put it into a case when I made it not work by breaking some tracks.
So I ordered another one and then also managed to repair the first one.
So I updated the GUI to make a dual channel signal generator.

It looks like this.




The code for an MM2 with a 320*240 screen is below. It uses all Peter's code, gets a few ideas from Parking Assist and Boat computer, and I used FontTweak to make the graphic fonts. Thanks,Peter,Geoff and Jim.

I terminate the signal output in a 50ohm resistor as its supposed to be 50ohm output impedance.

The software works without any hardware attached so it can be run to get a feel for the interface with just the MM2.


2016-04-21_131530_SignalGeneratorAD9833_v1.0.bas.zip


Regards
Gerry
Back to Top View disco4now's Profile Search for other posts by disco4now
 
hitsware
Guru
Guru


Joined: 23 November 2012
Location: United States
Online Status: Offline
Posts: 527
Posted: 21 April 2016 at 2:12pm | IP Logged Copy link to clipboard   Quote hitsware

If one wants a really clean output signal,
DDS is NOT the way to go. The residual digital
garbage is always somewhat remaining.
(filter as one may) A controller running an
analog chip (ICL8038 or XR2206) (and the peripherals)
will give much better results. Though perhaps not
as handy .

Back to Top View hitsware's Profile Search for other posts by hitsware
 
matherp
Guru
Guru


Joined: 11 December 2012
Location: United Kingdom
Online Status: Offline
Posts: 2708
Posted: 21 April 2016 at 6:52pm | IP Logged Copy link to clipboard   Quote matherp

Gerry

Excellent GUI and I really like the dual channel capability
congrats

Quote:
A controller running an
analog chip (ICL8038 or XR2206)


I've used the XR2206 and IMHO it is not a good device. You need two pots to adjust the symmetry and distortion of the waveform (how do you do that without an expensive spectrum analyser? Also the XR2206 generates a sine wave by diode shaping of a triangle wave. There is a small glitch in the sinewave that is generated at the peak of the triangle wave, which is also the transition point of the square-wave output. To get rid of this you need a low-pass filter so no advantage over DDS
Back to Top View matherp's Profile Search for other posts by matherp
 
hitsware
Guru
Guru


Joined: 23 November 2012
Location: United States
Online Status: Offline
Posts: 527
Posted: 21 April 2016 at 8:21pm | IP Logged Copy link to clipboard   Quote hitsware

matherp ,

I happened to buy one of these after disappointment with DDS :

http://www.sinometer.com/uploadImage/2012-09-27/2012092714544811255546.jpg

It was after the purchase that I found it used 8038 with microprocessor.
No glitch @ the peak (I've seen that myself)
It must have some filtering, but the DDS units I've seen always have
little steps left in the signal that annoy me.
(But then I won't use a digital scope for the same reason) ...
MegaRegards ..... hitsware


Edited by hitsware on 21 April 2016 at 8:48pm
Back to Top View hitsware's Profile Search for other posts by hitsware
 
robert.rozee
Guru
Guru


Joined: 31 December 2012
Location: New Zealand
Online Status: Offline
Posts: 1395
Posted: 22 April 2016 at 3:15am | IP Logged Copy link to clipboard   Quote robert.rozee

hitsware wrote:

But then I won't use a digital scope for the same reason
hitsware


digital scopes are a very good example of a really useful tool for certain tasks, masquerading as a very different tool that is emulated poorly.

over the years i've used several different DSOs (including $50,000 agilent models), and been highly disappointed with their inability to work like an analog scope. but this is the nature of the beast - DSOs are not a real-time display device, they are a high-speed data acquisition system who's output is best viewed after the event. an analog scope, on the other hand, does not acquire data, but merely displays an event as it happens, with the successful displaying being largely dependant upon the event being repetitive.

there are many tasks that a DSO performs admirably, tasks that an analog scope could not handle. similarly, there are tasks that an analog scope can do most successfully, but at which a DSO struggles or fails completely.

a modern 4-channel DSO with deep memory is magic for digital work, but no replacement for a relatively inexpensive (older) analog scope when you're doing RF work. much the same holds for digital synthesised signal generators.


cheers,
rob :-)

Back to Top View robert.rozee's Profile Search for other posts by robert.rozee
 
hitsware
Guru
Guru


Joined: 23 November 2012
Location: United States
Online Status: Offline
Posts: 527
Posted: 23 April 2016 at 12:59am | IP Logged Copy link to clipboard   Quote hitsware

What the world needs is an analog flat panel display !
Back to Top View hitsware's Profile Search for other posts by hitsware
 
damos
Newbie
Newbie


Joined: 15 April 2016
Location: Australia
Online Status: Offline
Posts: 19
Posted: 24 April 2016 at 5:07am | IP Logged Copy link to clipboard   Quote damos

Funny, lots of people must be thinking the same thoughts. I bought a really cheap AD9833 module ($7) and added a 7-bit pot, a 50 ohm driver and an incremental encoder to set the frequency and output level. It works really well. Here is the source code.2016-04-24_045753_function.zip

It uses the Micromite backpack and has touchscreen support. Features

0-12.5MHz with 0.1Hz increments
Square, Triangle and Sine outputs
Fine and Coarse Adjustment of frequency through encoder
Numeric entry of frequency through keypad
Sweep mode with 3 sweep speeds
Remembers last 3 frequencies

This will work with the other modules described here with a few small modifications to the code. If anyone want my circuit diagram, please ask.

I used a PEC16-42 24-detent incremental encode available from Element14 for a couple of dollars. These things are cheaper than pots, and can then be re-used by the software. Also much better when you want to save favourite values.

In terms of the DDS, the output is VERY clean, one of the best sine wave sources I have ever used. The XR2206s are awful and a really designed for RC setup rather than microcontrollers, and while a good Wein bridge is very clean, they can be very contankerous.
Back to Top View damos's Profile Search for other posts by damos
 
boss
Senior Member
Senior Member
Avatar

Joined: 19 August 2011
Location: Canada
Online Status: Offline
Posts: 268
Posted: 24 April 2016 at 7:14pm | IP Logged Copy link to clipboard   Quote boss

@damos

Nice project indeed. Could you release schematics?

Bo
Back to Top View boss's Profile Search for other posts by boss
 
damos
Newbie
Newbie


Joined: 15 April 2016
Location: Australia
Online Status: Offline
Posts: 19
Posted: 25 April 2016 at 8:13am | IP Logged Copy link to clipboard   Quote damos

2016-04-25_075908_function_gen_circuit.zip

Sorry about the hand drawn design.

It doesn't have a huge output swing (600mV p-p), but it does drive 50ohms. I would add a gain stage if I was better at RF. I built this on prototyping board and it works very well. I'd be inclined to use the fully implemented board if buying from fresh. The code could be easily modified to suit.

You could probably get away with a single 5V supply, although I haven't tested the LTC1010 with it.

If you want to use the sweep, think about adding a couple of lines of code to output a pulse at the start of the sweep to trigger the DSO.

The code implements a basic windowing API. I know the mm plus has this already, but there is no space left on the mm2, so I don't think it will be added. This allows you do create dialogs by defining the controls and providing a command code. This does all the drawing and touch detection, so you just need to add case statement entries for your event handler.

I had a go at using gradients for buttons - the code is in my bas file. They look really good, and change the appearance to look professional, but are a bit slow to draw so they need to be implemented in C.
Back to Top View damos's Profile Search for other posts by damos
 
boss
Senior Member
Senior Member
Avatar

Joined: 19 August 2011
Location: Canada
Online Status: Offline
Posts: 268
Posted: 25 April 2016 at 3:56pm | IP Logged Copy link to clipboard   Quote boss

@damos

Thank you very much. I'd like to have constant signal level in frequency range from 1000 Hz-12.5 Mhz, but no fully success yet. The signal generator is built on SnadPic (MM+ 100 pin) board so I have plenty of pins left for additional functionality . I tried to use some ultra-fast operational amplifiers, but nothing works fine. I'm surprised you are omit LP filter on DDS output. Did you check the output signal with oscilloscope?
May be the LT buffer chip will work for me as well.

Regards
Bo

Btw The chip is LT1010CN (not LTC1010 as is in diagram)
Back to Top View boss's Profile Search for other posts by boss
 


Page of 2 Next >>
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1094 seconds.
Privacy Policy     Process times : 0, 0, 0, 0.11