Example program for EVAL-AD9106 and EVAL-AD9102

Dependencies:   AD910x

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002     @file:   main.cpp
00003     
00004     @brief:  Main module for EVAL-AD910x application interface
00005 --------------------------------------------------------------------------------
00006     Copyright (c) 2021 Analog Devices, Inc.
00007     All rights reserved.
00008 
00009     This software is proprietary to Analog Devices, Inc. and its licensors.
00010     By using this software you agree to the terms of the associated
00011     Analog Devices Software License Agreement.
00012     
00013     20210120-LWSC-CTSLA
00014 *******************************************************************************/
00015 
00016 /*** Libraries ***/
00017 #include "mbed.h"
00018 #include "platform/mbed_thread.h"
00019 #include "config.h"
00020 #include "ad910x.h"
00021 
00022 /*** Defines for UART Protocol ***/
00023 #define BAUD_RATE       115200
00024 
00025 AD910x device( PA_15 );                 
00026 DigitalOut en_cvddx( PG_7, 0 );         ///DigitalOut instance for enable pin of on-board oscillator supply
00027 DigitalOut shdn_n_lt3472( PG_9, 0 );    ///DigitalOut instance for shutdown/enable pin of on-board amplifier supply
00028 
00029 /* Configure and instantiate UART protocol and baud rate */
00030 UnbufferedSerial pc( USBTX, USBRX, BAUD_RATE );
00031 
00032 /*** Function Declarations ***/
00033 void setup_device( void );
00034 void print_title( void );
00035 void print_prompt1( void );
00036 void print_prompt2( void );
00037 void print_menu( void );
00038 void play_example1( void );
00039 void play_example2( void );
00040 void play_example3( void );
00041 void play_example4( void );
00042 void play_example5( void );
00043 void play_example6( void );
00044 void print_prompt3( void );
00045 void stop_example( void );
00046 void print_prompt4( void );
00047 
00048 /*** Main Function ***/
00049 
00050 int main()
00051 {
00052     char ext_clk = 'y';
00053     char amp_out = 'n';
00054     char stop = 'n';
00055     char exit = 'n';
00056     char example = 1;
00057     uint8_t connected = 1;
00058     
00059     device.resetb = 1;
00060     device.triggerb = 1;
00061     setup_device();
00062     
00063     print_title();
00064     
00065     while( connected == 1 ){
00066         print_prompt1();
00067         while( pc.readable() == 0 );
00068         ext_clk = getchar();
00069         if ( ext_clk == 'y' ){
00070             en_cvddx = 0;
00071             printf("Please connect external clock source to J10.\n");
00072         } else {
00073             en_cvddx = 1;
00074             printf("On-board oscillator supply is enabled.\n");
00075         }
00076         thread_sleep_for(500);
00077         print_prompt2();
00078         while( pc.readable() == 0 );
00079         amp_out = getchar();
00080         if ( amp_out == 'y' ){
00081             shdn_n_lt3472 = 1;
00082             printf("On-board amplifier supply is enabled.\n");
00083         } else {
00084             shdn_n_lt3472 = 0;
00085         }
00086         print_menu();
00087         example = getchar();
00088         while( pc.readable() == 0 );
00089         printf("%c\n", example);
00090         switch (example) {
00091             case '1':
00092                 play_example1();
00093                 break;
00094 
00095             case '2':
00096                 play_example2();
00097                 break;
00098                 
00099             case '3':
00100                 play_example3();
00101                 break;
00102 
00103             case '4':
00104                 play_example4();
00105                 break;
00106             
00107             case '5':    
00108                 play_example5();
00109                 break;
00110                 
00111             case '6':
00112                 play_example6();
00113                 break;
00114                 
00115             default:
00116                 printf("\n****Invalid Entry****\n\n");
00117                 break;
00118         }
00119         print_prompt3();
00120         while( pc.readable() == 0 );
00121         while ( !(stop == 'y') ){
00122             stop = getchar();
00123         }
00124         stop_example();
00125         print_prompt4();
00126         while( pc.readable() == 0 );
00127         exit = getchar();
00128         if ( exit == 'y' ){
00129             connected = 0;
00130             printf("\nExiting program...\n");
00131         }else{
00132             stop = 'n';
00133         }
00134         
00135     }
00136     
00137     return 0;
00138 
00139 }
00140 
00141 /*** Function Definitions ***/
00142 
00143 /*Function to setup SPI communication*/
00144 void setup_device()
00145 {
00146     device.spi_init( WORD_LEN, POL, FREQ );
00147     device.AD910x_reg_reset();
00148 }
00149 
00150 /*Function to print the title block when program first starts*/
00151 void print_title()
00152 {
00153     printf("\n***********************************************************************\n");
00154     printf("* EVAL-%s Demonstration Program                                   *\n", ACTIVE_DEVICE);
00155     printf("*                                                                     *\n");
00156     printf("* This program demonstrates how to generate waveforms with the %s *\n", ACTIVE_DEVICE);
00157     printf("* using example register configurations in the datasheet.             *\n");
00158     printf("* This program is developed on Mbed OS version 6.                     *\n");
00159     printf("***********************************************************************\n");   
00160 }
00161 
00162 /*Function to print the first prompt/question to user to setup on-board oscillator supply*/
00163 void print_prompt1()
00164 {
00165     printf( "\nUsing external clock source?\n" );
00166     printf( "If yes, press y. If no, press any other key.\n" );
00167 }
00168 
00169 /*Function to print the next prompt/question to user to setup on-board amplifier supply*/
00170 void print_prompt2()
00171 {
00172     printf( "\nConnected DAC outputs to on-board amplifiers?\n" );
00173     printf( "If yes, press y. If no, press any other key.\n" );
00174 }
00175 
00176 /*Function to print summary of example AD910x configurations to play*/
00177 void print_menu()
00178 {
00179     printf("\nExample Summary\n");
00180     if ( ACTIVE_DEVICE == "AD9106" ){
00181         printf("   1 - 4 Gaussian Pulses with Different Start Delays and Digital Gain Settings\n");
00182         printf("   2 - 4 Pulses Generated from an SRAM Vector\n");
00183         printf("   3 - 4 Pulsed DDS-Generated Sine Waves with Different Start Delays and Digital Gain Settings\n");
00184         printf("   4 - Pulsed DDS-Generated Sine Wave and 3 Sawtooth Generator Waveforms\n");
00185         printf("   5 - Pulsed DDS-Generated Sine Waves Amplitude-Modulated by an SRAM Vector\n");
00186         printf("   6 - DDS-Generated Sine Wave and 3 Sawtooth Waveforms\n");
00187     }else if( ACTIVE_DEVICE == "AD9102" ){
00188         printf("   1 - Gaussian Pulse\n");
00189         printf("   2 - Pulse Generated from an SRAM Vector\n");
00190         printf("   3 - Pulsed DDS-Generated Sine Wave\n");
00191         printf("   4 - Sawtooth Waveform\n");
00192         printf("   5 - Pulsed DDS-Generated Sine Wave Amplitude-Modulated by an SRAM Vector\n");
00193         printf("   6 - DDS-Generated Sine Wave\n");
00194     }
00195     printf("Select an option: ");
00196 }
00197 
00198 /*Function to play example 1*/
00199 void play_example1()
00200 {
00201     if ( ACTIVE_DEVICE == "AD9106" ){
00202         printf("\n4 Gaussian Pulses with Different Start Delays and Digital Gain Settings\n");
00203         thread_sleep_for(500);
00204         device.AD910x_update_sram( example1_RAM_gaussian );
00205         device.AD910x_update_regs( AD9106_example1_regval );
00206     }else if( ACTIVE_DEVICE == "AD9102" ){
00207         printf("\nGaussian Pulse\n");
00208         thread_sleep_for(500);
00209         device.AD910x_update_sram( example1_RAM_gaussian );
00210         device.AD910x_update_regs( AD9102_example1_regval );
00211     }
00212     device.AD910x_start_pattern();
00213 }
00214 
00215 /*Function to play example 2*/
00216 void play_example2()
00217 {
00218     if ( ACTIVE_DEVICE == "AD9106" ){
00219         printf("\n4 Pulses Generated from an SRAM Vector\n");
00220         thread_sleep_for(500);
00221         device.AD910x_update_sram( example2_4096_ramp );
00222         device.AD910x_update_regs( AD9106_example2_regval );
00223     }else if( ACTIVE_DEVICE == "AD9102" ){
00224         printf("\nPulse Generated from an SRAM Vector\n");
00225         thread_sleep_for(500);
00226         device.AD910x_update_sram( example2_4096_ramp );
00227         device.AD910x_update_regs( AD9102_example2_regval );
00228     }
00229     device.AD910x_start_pattern();
00230 }
00231 
00232 /*Function to play example 3*/
00233 void play_example3()
00234 {
00235     if ( ACTIVE_DEVICE == "AD9106" ){
00236         printf("\n4 Pulsed DDS-Generated Sine Waves with Different Start Delays and Digital Gain Settings\n");
00237         thread_sleep_for(500);
00238         device.AD910x_update_regs( AD9106_example3_regval );
00239     }else if( ACTIVE_DEVICE == "AD9102" ){
00240         printf("\nPulsed DDS-Generated Sine Wave\n");
00241         thread_sleep_for(500);
00242         device.AD910x_update_regs( AD9102_example3_regval );
00243     }
00244     device.AD910x_start_pattern();       
00245 }
00246 
00247 /*Function to play example 4*/
00248 void play_example4()
00249 {
00250     if ( ACTIVE_DEVICE == "AD9106" ){
00251         printf("\nPulsed DDS-Generated Sine Wave and 3 Sawtooth Generator Waveforms\n");
00252         thread_sleep_for(500);
00253         device.AD910x_update_regs( AD9106_example4_regval );
00254     }else if( ACTIVE_DEVICE == "AD9102" ){
00255         printf("\nSawtooth Waveform\n");
00256         thread_sleep_for(500);
00257         device.AD910x_update_regs( AD9102_example4_regval );
00258     }
00259     device.AD910x_start_pattern();       
00260 }
00261 
00262 /*Function to play example 5*/
00263 void play_example5()
00264 {
00265     if ( ACTIVE_DEVICE == "AD9106" ){
00266         printf("\n4 Pulses Generated from an SRAM Vector\n");
00267         thread_sleep_for(500);
00268         device.AD910x_update_sram( example5_RAM_gaussian );
00269         device.AD910x_update_regs( AD9106_example5_regval );
00270     }else if ( ACTIVE_DEVICE == "AD9102"){
00271         printf("\nPulse Generated from an SRAM Vector\n");
00272         thread_sleep_for(500);
00273         device.AD910x_update_sram( example5_RAM_gaussian );
00274         device.AD910x_update_regs( AD9102_example5_regval );
00275     }
00276     device.AD910x_start_pattern();   
00277 }
00278 
00279 /*Function to play example 1*/
00280 void play_example6()
00281 {
00282     if ( ACTIVE_DEVICE == "AD9106" ){
00283         printf("\nDDS-Generated Sine Wave and 3 Sawtooth Waveforms\n");
00284         thread_sleep_for(500);
00285         device.AD910x_update_regs( AD9106_example6_regval );
00286     }else if( ACTIVE_DEVICE == "AD9102" ){
00287         printf("\nDDS-Generated Sine Wave\n");
00288         thread_sleep_for(500);
00289         device.AD910x_update_regs( AD9102_example6_regval );
00290     }
00291     device.AD910x_start_pattern();      
00292 }
00293 
00294 /*Function to print prompt/question to user to stop pattern*/
00295 void print_prompt3()
00296 {
00297     printf( "\nStop pattern?\n" );
00298     printf( "If yes, press y.\n" );
00299 }
00300 
00301 /*Function to stop pattern generation*/
00302 void stop_example()
00303 {
00304     device.AD910x_stop_pattern();
00305     printf( "Pattern stopped.\n" );
00306 }
00307 
00308 /*Function to print prompt/question to user to exit program*/
00309 void print_prompt4()
00310 {
00311     printf( "\nExit program?\n" );
00312     printf( "If yes, press y.\n" );
00313 }