Example program for EVAL-AD9106 and EVAL-AD9102

Dependencies:   AD910x

Revision:
1:b9d129e45c30
Parent:
0:3c9cc352dbfc
Child:
2:f20dbb194f12
diff -r 3c9cc352dbfc -r b9d129e45c30 main.cpp
--- a/main.cpp	Mon Jul 06 16:29:51 2020 +0000
+++ b/main.cpp	Wed Mar 03 02:18:23 2021 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019 Analog Devices, Inc.  All rights reserved.
+/* Copyright (c) 2021 Analog Devices, Inc.  All rights reserved.
 
 Redistribution and use in source and binary forms, with or without modification, 
 are permitted provided that the following conditions are met:
@@ -16,10 +16,10 @@
   - Neither the name of Analog Devices, Inc. nor the names of its contributors 
   may be used to endorse or promote products derived from this software without 
   specific prior written permission.
-  - The use of this software ma     y or may not infringe the patent rights of one or 
+  - The use of this software may or may not infringe the patent rights of one or 
   more patent holders.  This license does not release you from the requirement 
   that you obtain separate licenses from these patent holders to use this software.
-
+ 
 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND 
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 
 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 
@@ -32,94 +32,297 @@
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-2019-01-10-7CBSD SLA
+<Insert license number here.>
 
 */
 
-/***Libraries***/
-#include <stdio.h> /*Standard Library*/
-#include "mbed.h" /*mbed header file*/
+/*** Libraries ***/
+#include "mbed.h"
+#include "platform/mbed_thread.h"
+#include "config.h"
+#include "ad910x.h"
 
-/***Defines for UART Protocol***/
-#define BAUD_RATE                   115200                    /*Baud Rate*/
+/*** Defines for UART Protocol ***/
+#define BAUD_RATE       9600
+
+AD910x device( PA_15 );                 
+DigitalOut en_cvddx( PG_7, 0 );         ///< DigitalOut instance for enable pin of on-board oscillator supply
+DigitalOut shdn_n_lt3472( PG_9, 0 );    ///< DigitalOut instance for shutdown/enable pin of on-board amplifier supply
+
+/* Configure and instantiate UART protocol and baud rate */
+UnbufferedSerial pc( USBTX, USBRX, BAUD_RATE );
 
-/*Configure and instantiate UART protocol
-  and baud rate*/
-Serial port(USBTX, USBRX, BAUD_RATE);
-
-/***Function Declarations***/
+/*** Function Declarations ***/
+void setup_device( void );
+void print_title( void );
+void print_prompt1( void );
+void print_prompt2( void );
+void print_menu( void );
+void play_example1( void );
+void play_example2( void );
+void play_example3( void );
+void play_example4( void );
+void play_example5( void );
+void play_example6( void );
+void print_prompt3( void );
+void stop_example( void );
+void print_prompt4( void );
 
-/*Print Information about Program's purpose*/
-static void print_title(void);
-
-/*Print Instructions on how to use Program*/
-static void print_prompt(void);
+/*** Main Function ***/
 
 int main()
 {
-    uint8_t user_command; /*User input variable*/
-    uint8_t connected = 1; /*Initialize SPI*/
-
+    char ext_clk = 'y';
+    char amp_out = 'n';
+    char stop = 'n';
+    char exit = 'n';
+    char example = 1;
+    uint8_t connected = 1;
+    
+    device.resetb = 1;
+    device.triggerb = 1;
+    setup_device();
+    
     print_title();
+    
+    while( connected == 1 ){
+        print_prompt1();
+        ext_clk = getchar();
+        if ( ext_clk == 'y' ){
+            en_cvddx = 0;
+            printf("Please connect external clock source to J10.\n");
+        } else {
+            en_cvddx = 1;
+            printf("On-board oscillator supply is enabled.\n");
+        }
+        print_prompt2();
+        amp_out = getchar();
+        if ( amp_out == 'y' ){
+            shdn_n_lt3472 = 1;
+            printf("On-board amplifier supply is enabled.\n");
+        } else {
+            shdn_n_lt3472 = 0;
+        }
+        print_menu();
+        example = getchar();
+        printf("%c\n", example);
+        switch (example) {
+            case '1':
+                play_example1();
+                break;
 
-    while(connected == 1) {
-        print_prompt();
-        port.scanf("%2d", (int *) &user_command);
-        switch (user_command) {
-            case 1:
-                port.printf("Case 1\n\n");
+            case '2':
+                play_example2();
+                break;
+                
+            case '3':
+                play_example3();
                 break;
 
-            case 2:
-                port.printf("Case 2\n\n");
-                //menu_item_1_conversion_read(dev);
+            case '4':
+                play_example4();
                 break;
-
+            
+            case '5':    
+                play_example5();
+                break;
+                
+            case '6':
+                play_example6();
+                break;
+                
             default:
-                port.printf("   ***Illegal Entry****\n\n");
+                printf("\n****Invalid Entry****\n\n");
                 break;
+        }
+        print_prompt3();
+        while ( !(stop == 'y') ){
+            stop = getchar();
+        }
+        stop_example();
+        print_prompt4();
+        exit = getchar();
+        if ( exit == 'y' ){
+            connected = 0;
+            printf("\nExiting program...\n");
+        }
+        
+    }
+    
+    return 0;
+
+}
+
+/*** Function Definitions ***/
 
-        }
-    }
-    return 0;
+/*Function to setup SPI communication*/
+void setup_device()
+{
+    device.spi_init( WORD_LEN, POL, FREQ );
+    device.AD910x_reg_reset();
+}
+
+/*Function to print the title block when program first starts*/
+void print_title()
+{
+    printf("\n***********************************************************************\n");
+    printf("* EVAL-%S Demonstration Program                                   *\n", ACTIVE_DEVICE);
+    printf("*                                                                     *\n");
+    printf("* This program demonstrates how to generate waveforms with the %s *\n", ACTIVE_DEVICE);
+    printf("* using example register configurations in the datasheet.             *\n");
+    printf("* This program is developed using Mbed OS version 6.                  *\n");
+    printf("***********************************************************************\n");   
+}
+
+/*Function to print the first prompt/question to user to setup on-board oscillator supply*/
+void print_prompt1()
+{
+    printf( "\nUsing external clock source?\n" );
+    printf( "If yes, press y. If no, press any other key.\n" );
+}
+
+/*Function to print the next prompt/question to user to setup on-board amplifier supply*/
+void print_prompt2()
+{
+    printf( "\nConnected DAC outputs to on-board amplifiers?\n" );
+    printf( "If yes, press y. If no, press any other key.\n" );
 }
 
-/***Function Definitions***/
-
+/*Function to print summary of example AD910x configurations to play*/
+void print_menu()
+{
+    printf("\nExample Summary\n");
+    if ( ACTIVE_DEVICE == "AD9106" ){
+        printf("   1 - 4 Gaussian Pulses with Different Start Delays and Digital Gain Settings\n");
+        printf("   2 - 4 Pulses Generated from an SRAM Vector\n");
+        printf("   3 - 4 Pulsed DDS-Generated Sine Waves with Different Start Delays and Digital Gain Settings\n");
+        printf("   4 - Pulsed DDS-Generated Sine Wave and 3 Sawtooth Generator Waveforms\n");
+        printf("   5 - Pulsed DDS-Generated Sine Waves Amplitude-Modulated by an SRAM Vector\n");
+        printf("   6 - DDS-Generated Sine Wave and 3 Sawtooth Waveforms\n");
+    }else if( ACTIVE_DEVICE == "AD9102" ){
+        printf("   1 - Gaussian Pulse\n");
+        printf("   2 - Pulse Generated from an SRAM Vector\n");
+        printf("   3 - Pulsed DDS-Generated Sine Wave\n");
+        printf("   4 - Sawtooth Waveform\n");
+        printf("   5 - Pulsed DDS-Generated Sine Wave Amplitude-Modulated by an SRAM Vector\n");
+        printf("   6 - DDS-Generated Sine Wave\n");
+    }
+    printf("Select an option: ");
+}
 
-/*Function to print the title block when program first starts.
-  Parameters: None
-  Return Value: None*/
-void print_title()
+/*Function to play example 1*/
+void play_example1()
 {
-  port.printf("\n*****************************************************************\n");
-  port.printf("* EVAL-AD1234 Demonstration Program                             *\n");
-  port.printf("*                                                               *\n");
-  port.printf("* This program demonstrates how to measure strain gauge or      *\n");
-  port.printf("* other form of a Wheatstone bridge sensors with the AD1234     *\n");
-  port.printf("*                                                               *\n");
-  port.printf("*                                                               *\n");
-  port.printf("* Set the baud rate to 115200 and select the newline terminator.*\n");
-  port.printf("*                                                               *\n");
-  port.printf("*****************************************************************\n");
+    if ( ACTIVE_DEVICE == "AD9106" ){
+        printf("\n4 Gaussian Pulses with Different Start Delays and Digital Gain Settings\n");
+        thread_sleep_for(500);
+        device.AD910x_update_sram( example1_RAM_gaussian );
+        device.AD910x_update_regs( AD9106_example1_regval );
+    }else if( ACTIVE_DEVICE == "AD9102" ){
+        printf("\nGaussian Pulse\n");
+        thread_sleep_for(500);
+        device.AD910x_update_sram( example1_RAM_gaussian );
+        device.AD910x_update_regs( AD9102_example1_regval );
+    }
+    device.AD910x_start_pattern();
+}
+
+/*Function to play example 2*/
+void play_example2()
+{
+    if ( ACTIVE_DEVICE == "AD9106" ){
+        printf("\n4 Pulses Generated from an SRAM Vector\n");
+        thread_sleep_for(500);
+        device.AD910x_update_sram( example2_4096_ramp );
+        device.AD910x_update_regs( AD9106_example2_regval );
+    }else if( ACTIVE_DEVICE == "AD9102" ){
+        printf("\nPulse Generated from an SRAM Vector\n");
+        thread_sleep_for(500);
+        device.AD910x_update_sram( example2_4096_ramp );
+        device.AD910x_update_regs( AD9102_example2_regval );
+    }
+    device.AD910x_start_pattern();
 }
 
-/*Function to Print Command Summary
-  Parameters: None
-  Return Value: None */
-static void print_prompt() {
-    port.printf("Command Summary\n");
-    port.printf("   1 - Select ADC\n");
-    port.printf("   2 - Select Power Mode\n");
-    port.printf("   x - Put More Menu Items Here\n");       
+/*Function to play example 3*/
+void play_example3()
+{
+    if ( ACTIVE_DEVICE == "AD9106" ){
+        printf("\n4 Pulsed DDS-Generated Sine Waves with Different Start Delays and Digital Gain Settings\n");
+        thread_sleep_for(500);
+        device.AD910x_update_regs( AD9106_example3_regval );
+    }else if( ACTIVE_DEVICE == "AD9102" ){
+        printf("\nPulsed DDS-Generated Sine Wave\n");
+        thread_sleep_for(500);
+        device.AD910x_update_regs( AD9102_example3_regval );
+    }
+    device.AD910x_start_pattern();       
+}
+
+/*Function to play example 4*/
+void play_example4()
+{
+    if ( ACTIVE_DEVICE == "AD9106" ){
+        printf("\nPulsed DDS-Generated Sine Wave and 3 Sawtooth Generator Waveforms\n");
+        thread_sleep_for(500);
+        device.AD910x_update_regs( AD9106_example4_regval );
+    }else if( ACTIVE_DEVICE == "AD9102" ){
+        printf("\nSawtooth Waveform\n");
+        thread_sleep_for(500);
+        device.AD910x_update_regs( AD9102_example4_regval );
+    }
+    device.AD910x_start_pattern();       
 }
 
-void menu_1_function1()
+/*Function to play example 5*/
+void play_example5()
 {
-    port.printf("In function 1\n");
+    if ( ACTIVE_DEVICE == "AD9106" ){
+        printf("\n4 Pulses Generated from an SRAM Vector\n");
+        thread_sleep_for(500);
+        device.AD910x_update_sram( example5_RAM_gaussian );
+        device.AD910x_update_regs( AD9106_example5_regval );
+    }else if ( ACTIVE_DEVICE == "AD9102"){
+        printf("\nPulse Generated from an SRAM Vector\n");
+        thread_sleep_for(500);
+        device.AD910x_update_sram( example5_RAM_gaussian );
+        device.AD910x_update_regs( AD9102_example5_regval );
+    }
+    device.AD910x_start_pattern();   
 }
 
-void menu_2_function2()
+/*Function to play example 1*/
+void play_example6()
+{
+    if ( ACTIVE_DEVICE == "AD9106" ){
+        printf("\nDDS-Generated Sine Wave and 3 Sawtooth Waveforms\n");
+        thread_sleep_for(500);
+        device.AD910x_update_regs( AD9106_example6_regval );
+    }else if( ACTIVE_DEVICE == "AD9102" ){
+        printf("\nDDS-Generated Sine Wave\n");
+        thread_sleep_for(500);
+        device.AD910x_update_regs( AD9102_example6_regval );
+    }
+    device.AD910x_start_pattern();      
+}
+
+/*Function to print prompt/question to user to stop pattern*/
+void print_prompt3()
 {
-    port.printf("In function 2\n");
+    printf( "\nStop pattern?\n" );
+    printf( "If yes, press y.\n" );
 }
+
+/*Function to stop pattern generation*/
+void stop_example()
+{
+    device.AD910x_stop_pattern();
+    printf( "Pattern stopped.\n" );
+}
+
+/*Function to print prompt/question to user to exit program*/
+void print_prompt4()
+{
+    printf( "\nExit program?\n" );
+    printf( "If yes, press y.\n" );
+}
\ No newline at end of file