Java Program Controls Tuning Of Direct Digital Synthesizer Chip

Sept. 19, 2011
A direct digital synthesizer (DDS) board needed a 40-bit tuning value. A PC-based Java application uses large integers to deliver the necessary accuracy.

Fig 1. A Java program on a host PC calculates and loads the frequency settings of the direct digital synthesis chip on the daughter card of this processor board.

Fig 2. Because Java cannot readily handle serial ports, the final configuration for the experimental setup includes a host PC connected to the processor board through an Ethernet-to-RS-232 hookup.

While experimenting with a direct digital synthesizer (DDS) daughter board, we needed to be able to calculate a 40-bit “tuning word” for the Analog Devices AD9851 DDS chip and send it into the daughter board to set the output frequency. The Analog Devices Web site has an online Java Applet that allows you to compute the word tuning word, but it needed many input parameters and then we had to manually enter the calculated value into the daughter board.

We also found a Microsoft Visual Studio project for computing the tuning word, but it seemed unnecessarily complex for the simple operation to be performed. What we needed was a simple program to calculate the tuning word and then automatically load it into the DDS chip.

Computing the AD9851’s tuning word requires integer arithmetic computations using very large integers. The Java language includes a “class” of objects named “Big Integer.” Like its cousin the “Big Decimal” class, the “Big Integer” class and its methods (encapsulated functions) are designed to perform computations that maintain all of the digits of accuracy without being limited by the precision of the computer’s internal data storage formats.

For those not familiar with Java, it is a semi-compiled language. The compiler produces tokenized byte code that the Java Virtual Machine (JVM), a program that runs on each host computer, interprets in real time. The JVM is particular to the operating system and computer that it is running on.

However, Java source code is typically highly portable among platforms. Java is also a relatively easy language to get started with by using one of the many self-learning books or tools available.1 Java development tools are also free for download.2

As no other computer languages seem to be able to perform the integer operations and maintain all of the digits of accuracy without defining extraordinary and non-standard data types, we decided to create the program we needed in Java. The “Big Decimal” and “Big Integer” classes are not intended for applications that require high speed, but for the DDS tuning word computation we weren’t interested in speed, just accuracy.

\\[Editor’s note: ISO/ANSI C version 99 onward supports a 64-bit integer of type “long long” in both 32-bit and 64-bit systems (Windows/Unix). However, C++ does not support this integer type, and compiler support for “long long” varies.\\]

Experimental Setup

Our initial experiments utilized a Parallax Basic STAMP2 Board of Education development board,3 which has an onboard 5-V regulator and a prototyping area into which we plugged a DDS-60 daughter card that we obtained from the American QRP Club (Fig. 1).4 The DDS-60 daughter card contains an Analog Devices AD9851 DDS chip along with a 30-MHz reference oscillator, output filters, and signal conditioning.

We started out by computing the tuning word using the tool on the Analog Devices Web site.5 We then stored the bytes representing the 40-bit tuning word in a program on the STAMP2 processor that sent them into the daughter card to set the DDS output frequency. Examples for using STAMP or other processors to control the DDS-60 can be found on the AMQRP Web site. (We’ll share both of our programs if you send us an e-mail.6)

Conceptually, computation of the tuning word is a simple calculation involving the chip’s clock speed, the desired output frequency, and another big integer. One byte of the tuning word (Byte 0) contains a phase offset value and a control bit that selects whether or not the chip’s internal 6x clock multiplier is to be used. The remaining four bytes of the tuning word come from the computation:

TuningWord = DesiredFreqOut × 232 ÷ ClockAfterMultiplierApplied

where both frequencies are expressed in Hz.

For our setup the reference clock is 30 MHz and the 6x clock multiplier was in use, so the “ClockAfterMultiplierApplied” value is 180 MHz, or 180,000,000 Hz. We did not want to adjust the phase, so the first byte of the tuning word is the fixed value “01” (hex).

Rather than using the relatively complex applet on the Analog Devices Web site, we used a simple Java program running on a host PC to compute the remainder of the tuning word (Code Listing 1). If you were to test the program using 10 MHz as your desired frequency, the interaction would look like Code Listing 2.

Java Communications for Control

While computing the tuning word is relatively easy using Java, getting the tuning word from the host PC into the STAMP2 processor and hence the DDS daughter board proved a bit more difficult. Java does not directly support communications through serial ports, the only type available on the STAMP2.

A non-standard “Comm” package is available, but it has been dropped by the Java developers and seems to be receiving no maintenance attention. Using this non-standard package could prove to be problematic if you wanted to field a design that depended upon the package’s continued usability.

Java can, however, generate user datagram protocol (UDP) packets to be sent over an Ethernet connection to a networked serial port server device for injection into the DDS. This solution has the advantages of being more general, doesn’t depend on the discontinued “Comm” package, and can support greater distance and speed than a serial port solution.

Furthermore, as more laboratory equipment is fielded with Ethernet ports rather than serial ports, the Java application could be easily updated to bypass the networked serial port server and connect directly with the Ethernet-capable DDS device. To support Java control of the DDS, then, our test setup included a desktop PC, a laboratory Ethernet switch used to implement a standalone local-area network (LAN) segment, an IP/serial port server device, the STAMP development board, and the DDS-60 daughter card (Fig. 2).

The PC we used is a typical laptop PC found in any laboratory. Among other things, it has the Java Development Kit (jdk6) and the JGrasp integrated development environment used to develop the Java network-capable DDS control program. The IP switch is a typical 10/100 Ethernet switch, but could also have been a router. The Ethernet/Serial port server was a Neteon GW212 device.7

While this device has other capabilities that can be found in its user’s manual, in this application it serves to receive UDP packets, un-packetize, and send the data transparently out of its serial port. The Neteon GW212 is connected to the serial port of the STAMP processor board, which controls the DDS board.

The final Java control program,8 running on the host PC, asks the user to enter the desired output frequency, calculates the programming word, and sends it out as UDP packets through the GW212 to the STAMP processor. (To download the control program, see the online version of this article at www.electronicdesign.com.) When the STAMP processor has programmed the DDS daughter board, it sends an acknowledgement message back to the Java program on the host computer.

Both the Java control program and the GW212 configuration must use the same IP addressing and UDP port number information so the two programs can exchange UDP packets. For a thorough understanding of IP packets, addresses, and socket, see any one of the numerous available reference books.9

Code Listing 3 (lines 15 to 64) illustrates how the control program works. Most of the first lines, down through line 26, are setting up for IP communications. Line 22 defines the IP address of the destination device, in this case the Neteon GW212. Line 24 defines the port number of the socket that the GW212 listens on. Line 25 defines the port number of the socket that the host running this Java program listens on. Lines 30 thru 40 prompt the user for the desired frequency.

Lines 40 thru 49 compute the DDS tuning word, as described in the first listing. During calibration of the initial design, however, we found that there was a small frequency offset between the programmed and measured frequencies. The offset seemed to be proportional to the programmed frequency, so we made a slight adjustment to bigNumber in line 45 of the Java control program (the original value, 232, is commented out in line 44).

Packets encapsulate and carry bytes only, so the data that the control program passes to the Java packetization process DatagramPacket in line 63 must be an array of bytes. Line 50 uses the existing toByteArray() method of the BigInteger class to convert the BigInteger tuning word from line 48 into an array of bytes. The packet will consist of three letters, “Cmd,” followed by the first byte of the tuning word (defined to be 01). Bytes 4 through 7 are the bytes of the tuning word from line 50. The last two bytes represent a carriage return and line feed.

The array bytesToSend now passes to the packetization statements for transmission to the GW212’s IP address and port. Additional lines not shown receive and display the acknowledgement message the program gets back from the STAMP processor.

Other Programming Needed

The Java control program on the host PC isn’t the only program the design needs. The GW212 will also need to be programmed with the IP address and receive port number of the host PC as well as be set to the IP address and port number the Java control program expects, using the software and procedures that came with the GW212. The GW212’s IP address is 192.168.1.108, and its listening port is 4660 (from lines 22 and 24, respectively).

The entire function of the GW212 for this application, however, is to receive the packet from the host PC, send the bytes that the packet encapsulated out of the GW212’s RS-232 port, and forward the acknowledgement from the STAMP over the Ethernet back to the host computer. This is a built-in function of the device and does not need any user programming beyond the address and port configurations.

The STAMP2 processor also needs programming. Code listing 4 is an excerpt10 from the STAMPBASIC program11 that receives the un-packetized data from the GW212 and injects it into the DDS board.

Lines 1 through 7 form a continuous loop that waits for the three characters “Cmd” that are at the beginning of the packet the Java program sends out. When the STAMP2 program receives these three characters, it then accepts the five bytes of the DDS tuning word and the CR/LF characters. Line 3 shifts the five bytes (40 bits) serially out of processor pin 7 and into the DDS chip on the daughter board, using pin 8 as the clock.12

The HIGH-to-LOW toggle of STAMP pin 9 (Lines 4 and 5) signals the AD9851 DDS to use the new tuning word that was just loaded. Line 6 sends an acknowledgement message out of the STAMP RS-232 port to the GW212 for packetization and forwarding over the Ethernet to the host computer.

Conclusion

This method of using Java programs to control laboratory equipment over an Ethernet segment has several advantages. First, the BigInteger class of the Java language makes computing the DDS tuning word relatively easy. Second, one of Java’s strengths is relatively easy development of graphical user interfaces, so the control program can be made very easy to use.

Finally, packetizing the tuning word and sending it over an Ethernet segment allows control to occur over a much longer distance than a simple serial interface would allow. With legacy equipment that only has an RS-232 port, the use of devices such as the GW212 facilitates Ethernet control. (We also satisfactorily tested inserting an RS-232 to USB conversion device between the GW212 and a device with a USB port.) As more laboratory equipment becomes available with Ethernet ports, the Java-based networked control program should help facilitate full laboratory automation.

REFERENCES

1. Java Illuminated: An Active Learning Approach, Third Edition, Anderson and Franceschi

2. www.oracle.com/technetwork/java/javase/downloads/index.html

3. STAMP is a copyrighted line of PIC controllers from Parallax Inc. at www.parallax.com

4. www.amqrp.org/kits/dds60

5. www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9851/products/product.html

6. [email protected]

7. The Neteon GW212 device can be found at www.neteon.net

8. Downloadable file: Java Source Code for DDS Control Program.java, available with the online version of this article at www.electronicdesign.com

9. TCP/IP Sockets in Java, Practical Guide For Programmers by K.L. Calvert and M.J. Donahoo, Morgan Kaufman; and Java Network Programming by E.R. Harold, O’Reilly.

10. You can get the complete program from [email protected]

11. STAMPBASIC is a version of Basic that is used to program STAMP processors. It comes free with STAMP processors and is fully documented in its user manual.

12. See the assembly manual for the DDS-60 daughter board at www.amqrp.org/kits/dds60

Sponsored Recommendations

Understanding Thermal Challenges in EV Charging Applications

March 28, 2024
As EVs emerge as the dominant mode of transportation, factors such as battery range and quicker charging rates will play pivotal roles in the global economy.

Board-Mount DC/DC Converters in Medical Applications

March 27, 2024
AC/DC or board-mount DC/DC converters provide power for medical devices. This article explains why isolation might be needed and which safety standards apply.

Use Rugged Multiband Antennas to Solve the Mobile Connectivity Challenge

March 27, 2024
Selecting and using antennas for mobile applications requires attention to electrical, mechanical, and environmental characteristics: TE modules can help.

Out-of-the-box Cellular and Wi-Fi connectivity with AWS IoT ExpressLink

March 27, 2024
This demo shows how to enroll LTE-M and Wi-Fi evaluation boards with AWS IoT Core, set up a Connected Health Solution as well as AWS AT commands and AWS IoT ExpressLink security...

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!