Site icon Microcontroller Based Projects

AD9850 PIC16F Interface

AD9850 8-Bit Parallel Load DataControl Main

A simple wave generator should be a part of every electronics enthusiast toolset. Basic Sine/Square output in reasonable frequency range will be sufficient for general use. Luckily such generators are available in form of a very popular AD9850 module.  Search the web for AD9850 designs/code and  you’ll find a lot of material available on how to build various circuits around this module. Some are relatively complex for beginners and most of the interface software is written in C and not as simple to understand. I could not found an easy parallel interface assembly code for Microchip PIC microcontrollers so I had to construct a simple hardware configuration and write a basic PIC16F compatible code.

The code was written for PIC16F876A, however it should work on all similar MCU.As you can see in the design schematic 11 I/O are required: 8 bits of PORTC are used as Data and 3 bits of PORTA are controlling the parallel loading W_CLK, FU_UD and Reset of AD9850.Here is the parallel load timing sequence as provided by IC manufacturer Analog Devices.

Full data sheet can be downloaded here. Minimum time delay should not be a problem as PIC port switching time is much slower. Also a big delay was intentionally put in the code, about 0.5 s to give enough time to see signals flow.The delay can be reduced to a minimum if all works well. If you’ve followed the schematic and used the same code you’ll see the following sequence as soon as PIC is released from Reset state:

  1. Line RA2 will reset the AD9850,Reset LED  ON for 0.5s and OFF.
  2. First 8 bit Word out of 5 Words will be sent by PIC to PORTC. Bit RA0 will toggle W_CLK  line to load the Word into AD9850.
  3. Additional 4 parallel loads will be done. After loading 5 words RA1 will toggle FU_UD.

Shortly after you can see an output available on AD9850 representing the 5 words frequency value. Actually only 4 words represent the frequency, first byte in parallel load is Phase and 2 control bits.

Analog Devices also offers an online calculator for proper word value for each frequency. For AD9850 with 125 MHz oscillator and 8.1Khz output the 32 bit Word in hex is 00043F2A. 00 is Word 1 ,04  – Word 2, 3F – Word 3, 2A – Word 4.What about Word 0 ? At least in the beginning you probably don’t need a Phase change so leave it at 0.The full 40 bit Word looks like this

Word 0 – 0x00 MSB (Send first)
Word 1 – 0x00
Word 2 – 0x04
Word 3 – 0x3F
Word 4 – 0x2A

Attached code does exactly the same sequence as described above producing 8.1 KHz output. See DS2072 scope screen capture.

Sine wave is shown, however AD9850 also has square wave output with same frequency. Change the 4 Words being sent for other frequencies. Word of advice about square wave output. Square wave is produced by AD9850 module built in comparator. One of the comparator inputs is a potentiometer on the module board, second one is the Sine wave. If you rotate the potentiometer too much it will cause the comparator to produce a constant value “1” or “0”.So if for some reason you get the Sine but Square wave is not working, check the potentiometer. If you are going to power AD9850 module with 5V taken from 7805,LM317 or similar regulators make sure to use a small heat sink. Assembly code can be downloaded here. You may also be interested in a more advanced AD9850 Generator version available here.

Exit mobile version