Example program for EVAL-AD568x and EVAL-AD569x.
Dependencies: adi_console_menu platform_drivers
EVAL-AD568x-AD569x
This nanoDAC+ Mbed support software can be used as a starting point for developing your own firmware that targets Analog Devices nanoDAC+ products in your own environment. The software is configurable for your exact product within the nanoDAC+ family. See the user-guide for full instructions.
app/nanodac_console_app.c@8:f38c1afe205b, 2020-08-03 (annotated)
- Committer:
- mahphalke
- Date:
- Mon Aug 03 10:39:17 2020 +0000
- Revision:
- 8:f38c1afe205b
- Parent:
- 5:78877c8a97c8
- Child:
- 9:cce35eca2ab0
Corrected arduino pin mapping
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mahphalke | 5:78877c8a97c8 | 1 | /*! |
mahphalke | 5:78877c8a97c8 | 2 | ***************************************************************************** |
mahphalke | 5:78877c8a97c8 | 3 | @file: nanodac_console_app.c |
mahphalke | 5:78877c8a97c8 | 4 | |
mahphalke | 5:78877c8a97c8 | 5 | @brief: Implementation for the menu functions that handles the nanodac |
mahphalke | 5:78877c8a97c8 | 6 | functionality |
mahphalke | 5:78877c8a97c8 | 7 | |
mahphalke | 5:78877c8a97c8 | 8 | @details: This file is specific to nanodac console menu application handle. |
mahphalke | 5:78877c8a97c8 | 9 | The functions defined in this file performs the action |
mahphalke | 5:78877c8a97c8 | 10 | based on user selected console menu. |
mahphalke | 5:78877c8a97c8 | 11 | ----------------------------------------------------------------------------- |
mahphalke | 5:78877c8a97c8 | 12 | Copyright (c) 2020 Analog Devices, Inc. |
mahphalke | 5:78877c8a97c8 | 13 | All rights reserved. |
mahphalke | 5:78877c8a97c8 | 14 | |
mahphalke | 5:78877c8a97c8 | 15 | This software is proprietary to Analog Devices, Inc. and its licensors. |
mahphalke | 5:78877c8a97c8 | 16 | By using this software you agree to the terms of the associated |
mahphalke | 5:78877c8a97c8 | 17 | Analog Devices Software License Agreement. |
mahphalke | 5:78877c8a97c8 | 18 | *****************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 19 | |
mahphalke | 5:78877c8a97c8 | 20 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 21 | /***************************** Include Files **********************************/ |
mahphalke | 5:78877c8a97c8 | 22 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 23 | |
mahphalke | 5:78877c8a97c8 | 24 | #include <stdio.h> |
mahphalke | 5:78877c8a97c8 | 25 | #include <string.h> |
mahphalke | 5:78877c8a97c8 | 26 | #include <stdbool.h> |
mahphalke | 5:78877c8a97c8 | 27 | |
mahphalke | 5:78877c8a97c8 | 28 | #include "app_config.h" |
mahphalke | 5:78877c8a97c8 | 29 | |
mahphalke | 5:78877c8a97c8 | 30 | #include "ad5686.h" |
mahphalke | 5:78877c8a97c8 | 31 | #include "platform_support.h" |
mahphalke | 5:78877c8a97c8 | 32 | #include "platform_drivers.h" |
mahphalke | 5:78877c8a97c8 | 33 | #include "i2c_extra.h" |
mahphalke | 5:78877c8a97c8 | 34 | #include "spi_extra.h" |
mahphalke | 5:78877c8a97c8 | 35 | |
mahphalke | 5:78877c8a97c8 | 36 | #include "nanodac_console_app.h" |
mahphalke | 5:78877c8a97c8 | 37 | |
mahphalke | 5:78877c8a97c8 | 38 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 39 | /********************** Macros and Constants Definitions **********************/ |
mahphalke | 5:78877c8a97c8 | 40 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 41 | |
mahphalke | 5:78877c8a97c8 | 42 | #if !defined(I2C_SLAVE_ADDRESS) |
mahphalke | 5:78877c8a97c8 | 43 | #define I2C_SLAVE_ADDRESS 0 // For non I2C devices |
mahphalke | 5:78877c8a97c8 | 44 | #endif |
mahphalke | 5:78877c8a97c8 | 45 | |
mahphalke | 5:78877c8a97c8 | 46 | #define INTERNAL_VREF_VOLTAGE 2.5 |
mahphalke | 5:78877c8a97c8 | 47 | #define INTERNAL_VREF_SOURCE 0U |
mahphalke | 5:78877c8a97c8 | 48 | #define EXTERNAL_VREF_SOURCE 1U |
mahphalke | 5:78877c8a97c8 | 49 | |
mahphalke | 5:78877c8a97c8 | 50 | #define GAIN_LOW 1 |
mahphalke | 5:78877c8a97c8 | 51 | #define GAIN_HIGH 2 |
mahphalke | 5:78877c8a97c8 | 52 | |
mahphalke | 5:78877c8a97c8 | 53 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 54 | /********************** Variables and User Defined Data Types *****************/ |
mahphalke | 5:78877c8a97c8 | 55 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 56 | |
mahphalke | 5:78877c8a97c8 | 57 | // Pointer to a nanodac device structure |
mahphalke | 5:78877c8a97c8 | 58 | static struct ad5686_dev *nanodac_dev = NULL; |
mahphalke | 5:78877c8a97c8 | 59 | |
mahphalke | 5:78877c8a97c8 | 60 | // Current DAC channel (default value is channel 0) |
mahphalke | 5:78877c8a97c8 | 61 | static enum ad5686_dac_channels current_dac_channel = AD5686_CH_0; |
mahphalke | 5:78877c8a97c8 | 62 | |
mahphalke | 5:78877c8a97c8 | 63 | // Define the Vref source and voltage |
mahphalke | 5:78877c8a97c8 | 64 | #if !defined(EXT_VREF_SOURCE_ONLY) |
mahphalke | 5:78877c8a97c8 | 65 | // Default Vref voltage is 2.5v for internal reference source |
mahphalke | 5:78877c8a97c8 | 66 | static uint32_t vref_source = INTERNAL_VREF_SOURCE; |
mahphalke | 5:78877c8a97c8 | 67 | static float vref_voltage = INTERNAL_VREF_VOLTAGE; |
mahphalke | 5:78877c8a97c8 | 68 | #else |
mahphalke | 5:78877c8a97c8 | 69 | // Vref voltage for external reference source is user selectable |
mahphalke | 5:78877c8a97c8 | 70 | static uint32_t vref_source = EXTERNAL_VREF_SOURCE; |
mahphalke | 5:78877c8a97c8 | 71 | static float vref_voltage = 0; |
mahphalke | 5:78877c8a97c8 | 72 | #endif |
mahphalke | 5:78877c8a97c8 | 73 | |
mahphalke | 5:78877c8a97c8 | 74 | // Gain value (default is 1) |
mahphalke | 5:78877c8a97c8 | 75 | static uint32_t gain = GAIN_LOW; |
mahphalke | 5:78877c8a97c8 | 76 | |
mahphalke | 5:78877c8a97c8 | 77 | // LDAC pin state (default is High/Vlogic) |
mahphalke | 5:78877c8a97c8 | 78 | static uint32_t ldac_pin_state = GPIO_HIGH; |
mahphalke | 5:78877c8a97c8 | 79 | |
mahphalke | 5:78877c8a97c8 | 80 | // LDAC mask status (default is False/Disable) |
mahphalke | 5:78877c8a97c8 | 81 | static bool ldac_mask_status = false; |
mahphalke | 5:78877c8a97c8 | 82 | |
mahphalke | 5:78877c8a97c8 | 83 | |
mahphalke | 5:78877c8a97c8 | 84 | // Vref sources string |
mahphalke | 5:78877c8a97c8 | 85 | static const char *vref_source_str[] = { |
mahphalke | 5:78877c8a97c8 | 86 | "Internal", |
mahphalke | 5:78877c8a97c8 | 87 | "External" |
mahphalke | 5:78877c8a97c8 | 88 | }; |
mahphalke | 5:78877c8a97c8 | 89 | |
mahphalke | 5:78877c8a97c8 | 90 | // Operating mode string |
mahphalke | 5:78877c8a97c8 | 91 | static const char *operating_mode_str[] = { |
mahphalke | 5:78877c8a97c8 | 92 | "Normal Power-Up", |
mahphalke | 5:78877c8a97c8 | 93 | "1K to GND", |
mahphalke | 5:78877c8a97c8 | 94 | "100K to GND", |
mahphalke | 5:78877c8a97c8 | 95 | "Three State" |
mahphalke | 5:78877c8a97c8 | 96 | }; |
mahphalke | 5:78877c8a97c8 | 97 | |
mahphalke | 5:78877c8a97c8 | 98 | // Menu pre-declarations |
mahphalke | 5:78877c8a97c8 | 99 | extern console_menu dac_channel_select_menu; |
mahphalke | 5:78877c8a97c8 | 100 | extern console_menu vref_select_menu; |
mahphalke | 5:78877c8a97c8 | 101 | extern console_menu gain_select_menu; |
mahphalke | 5:78877c8a97c8 | 102 | extern console_menu dac_readback_select_menu; |
mahphalke | 5:78877c8a97c8 | 103 | extern console_menu ldac_mask_select_menu; |
mahphalke | 5:78877c8a97c8 | 104 | extern console_menu operating_mode_select_menu; |
mahphalke | 5:78877c8a97c8 | 105 | extern console_menu ldac_pin_select_menu; |
mahphalke | 5:78877c8a97c8 | 106 | |
mahphalke | 5:78877c8a97c8 | 107 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 108 | /************************ Functions Declarations ******************************/ |
mahphalke | 5:78877c8a97c8 | 109 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 110 | |
mahphalke | 5:78877c8a97c8 | 111 | static void gpio_power_up_configuration(void); |
mahphalke | 5:78877c8a97c8 | 112 | |
mahphalke | 5:78877c8a97c8 | 113 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 114 | /************************ Functions Definitions *******************************/ |
mahphalke | 5:78877c8a97c8 | 115 | /******************************************************************************/ |
mahphalke | 5:78877c8a97c8 | 116 | |
mahphalke | 5:78877c8a97c8 | 117 | /* @brief Initialize the nanodac device |
mahphalke | 5:78877c8a97c8 | 118 | * @param none |
mahphalke | 5:78877c8a97c8 | 119 | * @return SUCCESS(0), FAILURE(negative) |
mahphalke | 5:78877c8a97c8 | 120 | **/ |
mahphalke | 5:78877c8a97c8 | 121 | int32_t nanodac_app_initialize(void) |
mahphalke | 5:78877c8a97c8 | 122 | { |
mahphalke | 5:78877c8a97c8 | 123 | int32_t device_init_status; // Init status of device |
mahphalke | 5:78877c8a97c8 | 124 | |
mahphalke | 5:78877c8a97c8 | 125 | // Initialize the exra parameters for I2C initialization |
mahphalke | 5:78877c8a97c8 | 126 | mbed_i2c_init_param i2c_init_extra_params = { |
mahphalke | 5:78877c8a97c8 | 127 | .i2c_sda_pin = I2C_SDA, |
mahphalke | 5:78877c8a97c8 | 128 | .i2c_scl_pin = I2C_SCL |
mahphalke | 5:78877c8a97c8 | 129 | }; |
mahphalke | 5:78877c8a97c8 | 130 | |
mahphalke | 5:78877c8a97c8 | 131 | // Initialize the exra parameters for SPI initialization |
mahphalke | 5:78877c8a97c8 | 132 | mbed_spi_init_param spi_init_extra_params = { |
mahphalke | 5:78877c8a97c8 | 133 | .spi_miso_pin = SPI_MISO, |
mahphalke | 5:78877c8a97c8 | 134 | .spi_mosi_pin = SPI_MOSI, |
mahphalke | 5:78877c8a97c8 | 135 | .spi_clk_pin = SPI_SCK |
mahphalke | 5:78877c8a97c8 | 136 | }; |
mahphalke | 5:78877c8a97c8 | 137 | |
mahphalke | 5:78877c8a97c8 | 138 | // Initialize the device structure |
mahphalke | 5:78877c8a97c8 | 139 | struct ad5686_init_param nanodac_init_params = { |
mahphalke | 5:78877c8a97c8 | 140 | // i2c_init_param |
mahphalke | 5:78877c8a97c8 | 141 | { |
mahphalke | 5:78877c8a97c8 | 142 | 100000, // I2C max speed (Hz) |
mahphalke | 5:78877c8a97c8 | 143 | I2C_SLAVE_ADDRESS, // I2C slave address |
mahphalke | 5:78877c8a97c8 | 144 | &i2c_init_extra_params // I2C extra init parameters |
mahphalke | 5:78877c8a97c8 | 145 | }, |
mahphalke | 5:78877c8a97c8 | 146 | |
mahphalke | 5:78877c8a97c8 | 147 | // spi_init_param |
mahphalke | 5:78877c8a97c8 | 148 | { |
mahphalke | 5:78877c8a97c8 | 149 | 2000000, // SPI max speed (Hz) |
mahphalke | 8:f38c1afe205b | 150 | SPI_SS, // Chip select |
mahphalke | 5:78877c8a97c8 | 151 | SPI_MODE_2, // SPI Mode |
mahphalke | 5:78877c8a97c8 | 152 | &spi_init_extra_params // SPI extra init parameters |
mahphalke | 5:78877c8a97c8 | 153 | }, |
mahphalke | 5:78877c8a97c8 | 154 | |
mahphalke | 5:78877c8a97c8 | 155 | // gpio_init_param |
mahphalke | 5:78877c8a97c8 | 156 | { RESET_PIN, NULL }, // gpio_reset |
mahphalke | 5:78877c8a97c8 | 157 | { LDAC_PIN, NULL }, // gpio_ldac |
mahphalke | 5:78877c8a97c8 | 158 | { GAIN_PIN, NULL }, // gpio_gain |
mahphalke | 5:78877c8a97c8 | 159 | |
mahphalke | 5:78877c8a97c8 | 160 | ACTIVE_DEVICE // Active device |
mahphalke | 5:78877c8a97c8 | 161 | }; |
mahphalke | 5:78877c8a97c8 | 162 | |
mahphalke | 5:78877c8a97c8 | 163 | // Initialize the device |
mahphalke | 5:78877c8a97c8 | 164 | device_init_status = ad5686_init(&nanodac_dev, nanodac_init_params); |
mahphalke | 5:78877c8a97c8 | 165 | |
mahphalke | 5:78877c8a97c8 | 166 | // Configure the GPIOs specific to application upon power-up |
mahphalke | 5:78877c8a97c8 | 167 | gpio_power_up_configuration(); |
mahphalke | 5:78877c8a97c8 | 168 | |
mahphalke | 5:78877c8a97c8 | 169 | return device_init_status; |
mahphalke | 5:78877c8a97c8 | 170 | } |
mahphalke | 5:78877c8a97c8 | 171 | |
mahphalke | 5:78877c8a97c8 | 172 | |
mahphalke | 5:78877c8a97c8 | 173 | /*! |
mahphalke | 5:78877c8a97c8 | 174 | * @brief Set the power-up GPIO configurations |
mahphalke | 5:78877c8a97c8 | 175 | * @return None |
mahphalke | 5:78877c8a97c8 | 176 | */ |
mahphalke | 5:78877c8a97c8 | 177 | static void gpio_power_up_configuration(void) |
mahphalke | 5:78877c8a97c8 | 178 | { |
mahphalke | 5:78877c8a97c8 | 179 | // Set the directions for GPIO pins |
mahphalke | 5:78877c8a97c8 | 180 | (void)gpio_direction_output(nanodac_dev->gpio_gain, GPIO_OUT); |
mahphalke | 5:78877c8a97c8 | 181 | (void)gpio_direction_output(nanodac_dev->gpio_ldac, GPIO_OUT); |
mahphalke | 5:78877c8a97c8 | 182 | (void)gpio_direction_output(nanodac_dev->gpio_reset, GPIO_OUT); |
mahphalke | 5:78877c8a97c8 | 183 | |
mahphalke | 5:78877c8a97c8 | 184 | // Set the GPIO values |
mahphalke | 5:78877c8a97c8 | 185 | gpio_set_value(nanodac_dev->gpio_reset, GPIO_HIGH); |
mahphalke | 5:78877c8a97c8 | 186 | gpio_set_value(nanodac_dev->gpio_gain, GPIO_LOW); |
mahphalke | 5:78877c8a97c8 | 187 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
mahphalke | 5:78877c8a97c8 | 188 | } |
mahphalke | 5:78877c8a97c8 | 189 | |
mahphalke | 5:78877c8a97c8 | 190 | |
mahphalke | 5:78877c8a97c8 | 191 | /*! |
mahphalke | 5:78877c8a97c8 | 192 | * @brief Display the header info for menu |
mahphalke | 5:78877c8a97c8 | 193 | * @return None |
mahphalke | 5:78877c8a97c8 | 194 | */ |
mahphalke | 5:78877c8a97c8 | 195 | static void display_menu_header(void) |
mahphalke | 5:78877c8a97c8 | 196 | { |
mahphalke | 5:78877c8a97c8 | 197 | printf("\t%s (nanodac) | ", ACTIVE_DEVICE_NAME); |
mahphalke | 5:78877c8a97c8 | 198 | printf("Vref:%s (%.1fV) | ", vref_source_str[vref_source], vref_voltage); |
mahphalke | 5:78877c8a97c8 | 199 | printf("Gain:%ld"EOL, gain); |
mahphalke | 5:78877c8a97c8 | 200 | } |
mahphalke | 5:78877c8a97c8 | 201 | |
mahphalke | 5:78877c8a97c8 | 202 | |
mahphalke | 5:78877c8a97c8 | 203 | /*! |
mahphalke | 5:78877c8a97c8 | 204 | * @brief Display the footer info for menu |
mahphalke | 5:78877c8a97c8 | 205 | * @return None |
mahphalke | 5:78877c8a97c8 | 206 | */ |
mahphalke | 5:78877c8a97c8 | 207 | static void display_menu_footer(void) |
mahphalke | 5:78877c8a97c8 | 208 | { |
mahphalke | 5:78877c8a97c8 | 209 | // Display the device name |
mahphalke | 5:78877c8a97c8 | 210 | printf("\tActive Channel: %d | ", current_dac_channel); |
mahphalke | 5:78877c8a97c8 | 211 | printf("LDAC Pin: %ld | ", ldac_pin_state); |
mahphalke | 5:78877c8a97c8 | 212 | printf("LDAC Mask: %d"EOL, ldac_mask_status); |
mahphalke | 5:78877c8a97c8 | 213 | } |
mahphalke | 5:78877c8a97c8 | 214 | |
mahphalke | 5:78877c8a97c8 | 215 | |
mahphalke | 5:78877c8a97c8 | 216 | /*! |
mahphalke | 5:78877c8a97c8 | 217 | * @brief Handle the DAC channel selection menu |
mahphalke | 5:78877c8a97c8 | 218 | * @param uint32_t channel_id- Selected DAC channel number |
mahphalke | 5:78877c8a97c8 | 219 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 220 | */ |
mahphalke | 5:78877c8a97c8 | 221 | static int32_t menu_select_dac_channel(uint32_t channel_id) |
mahphalke | 5:78877c8a97c8 | 222 | { |
mahphalke | 5:78877c8a97c8 | 223 | // Store the dac channel for future read/write operations |
mahphalke | 5:78877c8a97c8 | 224 | current_dac_channel = (enum ad5686_dac_channels)channel_id; |
mahphalke | 5:78877c8a97c8 | 225 | |
mahphalke | 5:78877c8a97c8 | 226 | printf(EOL EOL"\tDAC Channel %ld is selected..."EOL, channel_id); |
mahphalke | 5:78877c8a97c8 | 227 | |
mahphalke | 5:78877c8a97c8 | 228 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 229 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 230 | } |
mahphalke | 5:78877c8a97c8 | 231 | |
mahphalke | 5:78877c8a97c8 | 232 | |
mahphalke | 5:78877c8a97c8 | 233 | /*! |
mahphalke | 5:78877c8a97c8 | 234 | * @brief Handle the menu to display DAC channel selection |
mahphalke | 5:78877c8a97c8 | 235 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 236 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 237 | */ |
mahphalke | 5:78877c8a97c8 | 238 | static int32_t menu_dac_channels(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 239 | { |
mahphalke | 5:78877c8a97c8 | 240 | // Display the dac channel selection menu |
mahphalke | 5:78877c8a97c8 | 241 | adi_do_console_menu(&dac_channel_select_menu); |
mahphalke | 5:78877c8a97c8 | 242 | |
mahphalke | 5:78877c8a97c8 | 243 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 244 | } |
mahphalke | 5:78877c8a97c8 | 245 | |
mahphalke | 5:78877c8a97c8 | 246 | |
mahphalke | 5:78877c8a97c8 | 247 | /*! |
mahphalke | 5:78877c8a97c8 | 248 | * @brief Handle the menu to write DAC input register |
mahphalke | 5:78877c8a97c8 | 249 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 250 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 251 | */ |
mahphalke | 5:78877c8a97c8 | 252 | static int32_t menu_write_to_input_register(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 253 | { |
mahphalke | 5:78877c8a97c8 | 254 | uint16_t dac_data_input; // Data to be written to DAC |
mahphalke | 5:78877c8a97c8 | 255 | |
mahphalke | 5:78877c8a97c8 | 256 | printf(EOL"\tEnter the Data/Code (in decimal): "); |
mahphalke | 5:78877c8a97c8 | 257 | dac_data_input = (uint16_t)adi_get_decimal_int(5); |
mahphalke | 5:78877c8a97c8 | 258 | |
mahphalke | 5:78877c8a97c8 | 259 | // Write DAC input register for current selected channel |
mahphalke | 5:78877c8a97c8 | 260 | ad5686_write_register(nanodac_dev, current_dac_channel, dac_data_input); |
mahphalke | 5:78877c8a97c8 | 261 | |
mahphalke | 5:78877c8a97c8 | 262 | printf(EOL EOL"\tData %d written to DAC input register..."EOL, dac_data_input); |
mahphalke | 5:78877c8a97c8 | 263 | |
mahphalke | 5:78877c8a97c8 | 264 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 265 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 266 | } |
mahphalke | 5:78877c8a97c8 | 267 | |
mahphalke | 5:78877c8a97c8 | 268 | |
mahphalke | 5:78877c8a97c8 | 269 | /*! |
mahphalke | 5:78877c8a97c8 | 270 | * @brief Handle the menu to update DAC register with value from input register |
mahphalke | 5:78877c8a97c8 | 271 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 272 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 273 | */ |
mahphalke | 5:78877c8a97c8 | 274 | static int32_t menu_update_dac_from_input(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 275 | { |
mahphalke | 5:78877c8a97c8 | 276 | // Update the DAC with input register data for current selected channel |
mahphalke | 5:78877c8a97c8 | 277 | ad5686_update_register(nanodac_dev, current_dac_channel); |
mahphalke | 5:78877c8a97c8 | 278 | |
mahphalke | 5:78877c8a97c8 | 279 | printf(EOL EOL"\tUpdated DAC register with contents of input register..."EOL); |
mahphalke | 5:78877c8a97c8 | 280 | |
mahphalke | 5:78877c8a97c8 | 281 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 282 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 283 | } |
mahphalke | 5:78877c8a97c8 | 284 | |
mahphalke | 5:78877c8a97c8 | 285 | |
mahphalke | 5:78877c8a97c8 | 286 | /*! |
mahphalke | 5:78877c8a97c8 | 287 | * @brief Handle the menu to update DAC register by asserting LDAC pin |
mahphalke | 5:78877c8a97c8 | 288 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 289 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 290 | */ |
mahphalke | 5:78877c8a97c8 | 291 | static int32_t menu_update_dac_by_ldac_assert(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 292 | { |
mahphalke | 5:78877c8a97c8 | 293 | // Update DAC registers by asserting LDAC pin High to Low |
mahphalke | 5:78877c8a97c8 | 294 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
mahphalke | 5:78877c8a97c8 | 295 | mdelay(1); |
mahphalke | 5:78877c8a97c8 | 296 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_LOW); |
mahphalke | 5:78877c8a97c8 | 297 | mdelay(1); |
mahphalke | 5:78877c8a97c8 | 298 | |
mahphalke | 5:78877c8a97c8 | 299 | // Restore the previous state of LDAC pin |
mahphalke | 5:78877c8a97c8 | 300 | if (ldac_pin_state == GPIO_HIGH) { |
mahphalke | 5:78877c8a97c8 | 301 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
mahphalke | 5:78877c8a97c8 | 302 | } |
mahphalke | 5:78877c8a97c8 | 303 | |
mahphalke | 5:78877c8a97c8 | 304 | printf(EOL EOL"\tUpdated DAC register with contents of input register..."EOL); |
mahphalke | 5:78877c8a97c8 | 305 | |
mahphalke | 5:78877c8a97c8 | 306 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 307 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 308 | } |
mahphalke | 5:78877c8a97c8 | 309 | |
mahphalke | 5:78877c8a97c8 | 310 | |
mahphalke | 5:78877c8a97c8 | 311 | /*! |
mahphalke | 5:78877c8a97c8 | 312 | * @brief Handle the menu to write and update DAC register directly |
mahphalke | 5:78877c8a97c8 | 313 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 314 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 315 | */ |
mahphalke | 5:78877c8a97c8 | 316 | static int32_t menu_write_and_update_dac(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 317 | { |
mahphalke | 5:78877c8a97c8 | 318 | uint16_t dac_data_input; // Data to be written to DAC |
mahphalke | 5:78877c8a97c8 | 319 | |
mahphalke | 5:78877c8a97c8 | 320 | printf(EOL"\tEnter the Data/Code (in decimal): "); |
mahphalke | 5:78877c8a97c8 | 321 | dac_data_input = (uint16_t)adi_get_decimal_int(5); |
mahphalke | 5:78877c8a97c8 | 322 | |
mahphalke | 5:78877c8a97c8 | 323 | // Update DAC data register for current selected channel |
mahphalke | 5:78877c8a97c8 | 324 | ad5686_write_update_register(nanodac_dev, current_dac_channel, dac_data_input); |
mahphalke | 5:78877c8a97c8 | 325 | |
mahphalke | 5:78877c8a97c8 | 326 | printf(EOL EOL"\tDAC updated with Data %d"EOL, dac_data_input); |
mahphalke | 5:78877c8a97c8 | 327 | |
mahphalke | 5:78877c8a97c8 | 328 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 329 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 330 | } |
mahphalke | 5:78877c8a97c8 | 331 | |
mahphalke | 5:78877c8a97c8 | 332 | |
mahphalke | 5:78877c8a97c8 | 333 | /*! |
mahphalke | 5:78877c8a97c8 | 334 | * @brief Handle the menu to select operating mode of DAC |
mahphalke | 5:78877c8a97c8 | 335 | * @param uint32_t operating_mode_input- User input operating mode |
mahphalke | 5:78877c8a97c8 | 336 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 337 | */ |
mahphalke | 5:78877c8a97c8 | 338 | static int32_t menu_select_operating_mode(uint32_t operating_mode_input) |
mahphalke | 5:78877c8a97c8 | 339 | { |
mahphalke | 5:78877c8a97c8 | 340 | // Select the operating mode of DAC |
mahphalke | 5:78877c8a97c8 | 341 | ad5686_power_mode(nanodac_dev, current_dac_channel, operating_mode_input); |
mahphalke | 5:78877c8a97c8 | 342 | |
mahphalke | 5:78877c8a97c8 | 343 | printf(EOL EOL"\tSelected operating mode as %s"EOL, |
mahphalke | 5:78877c8a97c8 | 344 | operating_mode_str[operating_mode_input]); |
mahphalke | 5:78877c8a97c8 | 345 | |
mahphalke | 5:78877c8a97c8 | 346 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 347 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 348 | } |
mahphalke | 5:78877c8a97c8 | 349 | |
mahphalke | 5:78877c8a97c8 | 350 | |
mahphalke | 5:78877c8a97c8 | 351 | /*! |
mahphalke | 5:78877c8a97c8 | 352 | * @brief Handle the menu to display operating modes of DAC |
mahphalke | 5:78877c8a97c8 | 353 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 354 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 355 | */ |
mahphalke | 5:78877c8a97c8 | 356 | static int32_t menu_dac_operating_modes(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 357 | { |
mahphalke | 5:78877c8a97c8 | 358 | // Display the operating mode select menu |
mahphalke | 5:78877c8a97c8 | 359 | adi_do_console_menu(&operating_mode_select_menu); |
mahphalke | 5:78877c8a97c8 | 360 | |
mahphalke | 5:78877c8a97c8 | 361 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 362 | } |
mahphalke | 5:78877c8a97c8 | 363 | |
mahphalke | 5:78877c8a97c8 | 364 | |
mahphalke | 5:78877c8a97c8 | 365 | /*! |
mahphalke | 5:78877c8a97c8 | 366 | * @brief Handle the menu to select the reference source for DAC |
mahphalke | 5:78877c8a97c8 | 367 | * @param uint32_t ref_source_input- user selected reference source |
mahphalke | 5:78877c8a97c8 | 368 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 369 | */ |
mahphalke | 5:78877c8a97c8 | 370 | static int32_t menu_select_vref_source(uint32_t ref_source_input) |
mahphalke | 5:78877c8a97c8 | 371 | { |
mahphalke | 5:78877c8a97c8 | 372 | float user_vref_value = INTERNAL_VREF_VOLTAGE; // user input reference |
mahphalke | 5:78877c8a97c8 | 373 | // voltage value |
mahphalke | 5:78877c8a97c8 | 374 | |
mahphalke | 5:78877c8a97c8 | 375 | if (ref_source_input == INTERNAL_VREF_SOURCE) { |
mahphalke | 5:78877c8a97c8 | 376 | // Enable the internal reference source |
mahphalke | 5:78877c8a97c8 | 377 | ad5686_internal_reference(nanodac_dev, AD5686_INTREF_EN); |
mahphalke | 5:78877c8a97c8 | 378 | vref_source = INTERNAL_VREF_SOURCE; |
mahphalke | 5:78877c8a97c8 | 379 | vref_voltage = INTERNAL_VREF_VOLTAGE; |
mahphalke | 5:78877c8a97c8 | 380 | |
mahphalke | 5:78877c8a97c8 | 381 | // Display the vref selections on console window |
mahphalke | 5:78877c8a97c8 | 382 | printf(EOL"\tVref Source: %s"EOL, vref_source_str[vref_source]); |
mahphalke | 5:78877c8a97c8 | 383 | printf("\tVref Voltage: %f"EOL, vref_voltage); |
mahphalke | 5:78877c8a97c8 | 384 | } else if (ref_source_input == EXTERNAL_VREF_SOURCE) { |
mahphalke | 5:78877c8a97c8 | 385 | printf(EOL EOL"\tEnter the external reference voltage"EOL); |
mahphalke | 5:78877c8a97c8 | 386 | user_vref_value = adi_get_decimal_float(5); |
mahphalke | 5:78877c8a97c8 | 387 | |
mahphalke | 5:78877c8a97c8 | 388 | // Disable the internal reference source |
mahphalke | 5:78877c8a97c8 | 389 | ad5686_internal_reference(nanodac_dev, AD5686_INTREF_DIS); |
mahphalke | 5:78877c8a97c8 | 390 | vref_source = EXTERNAL_VREF_SOURCE; |
mahphalke | 5:78877c8a97c8 | 391 | vref_voltage = user_vref_value; |
mahphalke | 5:78877c8a97c8 | 392 | |
mahphalke | 5:78877c8a97c8 | 393 | // Display the vref selections on console window |
mahphalke | 5:78877c8a97c8 | 394 | printf(EOL"\tVref Source: %s"EOL, vref_source_str[vref_source]); |
mahphalke | 5:78877c8a97c8 | 395 | printf("\tVref Voltage: %f"EOL, vref_voltage); |
mahphalke | 5:78877c8a97c8 | 396 | } else { |
mahphalke | 5:78877c8a97c8 | 397 | printf(EOL EOL"\tInvalid Vref Source selection"EOL); |
mahphalke | 5:78877c8a97c8 | 398 | } |
mahphalke | 5:78877c8a97c8 | 399 | |
mahphalke | 5:78877c8a97c8 | 400 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 401 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 402 | } |
mahphalke | 5:78877c8a97c8 | 403 | |
mahphalke | 5:78877c8a97c8 | 404 | |
mahphalke | 5:78877c8a97c8 | 405 | /*! |
mahphalke | 5:78877c8a97c8 | 406 | * @brief Handle the menu to display the reference source for DAC |
mahphalke | 5:78877c8a97c8 | 407 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 408 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 409 | */ |
mahphalke | 5:78877c8a97c8 | 410 | static int32_t menu_vref_sources(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 411 | { |
mahphalke | 5:78877c8a97c8 | 412 | // Display the Vref selection menu |
mahphalke | 5:78877c8a97c8 | 413 | adi_do_console_menu(&vref_select_menu); |
mahphalke | 5:78877c8a97c8 | 414 | |
mahphalke | 5:78877c8a97c8 | 415 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 416 | } |
mahphalke | 5:78877c8a97c8 | 417 | |
mahphalke | 5:78877c8a97c8 | 418 | |
mahphalke | 5:78877c8a97c8 | 419 | /*! |
mahphalke | 5:78877c8a97c8 | 420 | * @brief Handle the menu to readback DAC register for selected channel |
mahphalke | 5:78877c8a97c8 | 421 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 422 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 423 | */ |
mahphalke | 5:78877c8a97c8 | 424 | static int32_t menu_dac_readback(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 425 | { |
mahphalke | 5:78877c8a97c8 | 426 | uint16_t dac_data; // Readback DAC data |
mahphalke | 5:78877c8a97c8 | 427 | float output_voltage; // Output voltage of DAC channel |
mahphalke | 5:78877c8a97c8 | 428 | |
mahphalke | 5:78877c8a97c8 | 429 | // Readback data for current selected DAC channel |
mahphalke | 5:78877c8a97c8 | 430 | dac_data = ad5686_read_back_register(nanodac_dev, current_dac_channel); |
mahphalke | 5:78877c8a97c8 | 431 | |
mahphalke | 5:78877c8a97c8 | 432 | // Calculate equivalent output voltage |
mahphalke | 5:78877c8a97c8 | 433 | output_voltage = (vref_voltage * gain * ((float)dac_data / TOTAL_OUTPUT_CODES)); |
mahphalke | 5:78877c8a97c8 | 434 | |
mahphalke | 5:78877c8a97c8 | 435 | printf(EOL EOL"\tDAC Channel %d Data: %d"EOL, current_dac_channel, dac_data); |
mahphalke | 5:78877c8a97c8 | 436 | printf(EOL"\tVoltage: %.3f V"EOL EOL, output_voltage); |
mahphalke | 5:78877c8a97c8 | 437 | |
mahphalke | 5:78877c8a97c8 | 438 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 439 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 440 | } |
mahphalke | 5:78877c8a97c8 | 441 | |
mahphalke | 5:78877c8a97c8 | 442 | |
mahphalke | 5:78877c8a97c8 | 443 | /*! |
mahphalke | 5:78877c8a97c8 | 444 | * @brief Handle the menu to select LDACx mask (x:DAC channel) |
mahphalke | 5:78877c8a97c8 | 445 | * @param uint32_t mask_status- user input LDAC mask |
mahphalke | 5:78877c8a97c8 | 446 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 447 | */ |
mahphalke | 5:78877c8a97c8 | 448 | static int32_t menu_set_ldac_mask(uint32_t mask_status) |
mahphalke | 5:78877c8a97c8 | 449 | { |
mahphalke | 5:78877c8a97c8 | 450 | // Set the LDAC mask (0/1) |
mahphalke | 5:78877c8a97c8 | 451 | ad5686_ldac_mask(nanodac_dev, current_dac_channel, mask_status); |
mahphalke | 5:78877c8a97c8 | 452 | |
mahphalke | 5:78877c8a97c8 | 453 | ldac_mask_status = mask_status; |
mahphalke | 5:78877c8a97c8 | 454 | printf(EOL EOL"\tLDAC Mask for Channel %d: %ld"EOL, current_dac_channel, |
mahphalke | 5:78877c8a97c8 | 455 | mask_status); |
mahphalke | 5:78877c8a97c8 | 456 | |
mahphalke | 5:78877c8a97c8 | 457 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 458 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 459 | } |
mahphalke | 5:78877c8a97c8 | 460 | |
mahphalke | 5:78877c8a97c8 | 461 | |
mahphalke | 5:78877c8a97c8 | 462 | /*! |
mahphalke | 5:78877c8a97c8 | 463 | * @brief Handle the menu to display LDACx mask menu selections |
mahphalke | 5:78877c8a97c8 | 464 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 465 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 466 | */ |
mahphalke | 5:78877c8a97c8 | 467 | static int32_t menu_ldac_masks(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 468 | { |
mahphalke | 5:78877c8a97c8 | 469 | // Display the LDAC mask selection menu |
mahphalke | 5:78877c8a97c8 | 470 | adi_do_console_menu(&ldac_mask_select_menu); |
mahphalke | 5:78877c8a97c8 | 471 | |
mahphalke | 5:78877c8a97c8 | 472 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 473 | } |
mahphalke | 5:78877c8a97c8 | 474 | |
mahphalke | 5:78877c8a97c8 | 475 | |
mahphalke | 5:78877c8a97c8 | 476 | /*! |
mahphalke | 5:78877c8a97c8 | 477 | * @brief Handle the menu to set LDAC pin state |
mahphalke | 5:78877c8a97c8 | 478 | * @param uint32_t pin_state- user input pin state (HIGH/LOW) |
mahphalke | 5:78877c8a97c8 | 479 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 480 | */ |
mahphalke | 5:78877c8a97c8 | 481 | static int32_t menu_set_ldac_pin(uint32_t pin_state) |
mahphalke | 5:78877c8a97c8 | 482 | { |
mahphalke | 5:78877c8a97c8 | 483 | if (pin_state == GPIO_HIGH) { |
mahphalke | 5:78877c8a97c8 | 484 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_HIGH); |
mahphalke | 5:78877c8a97c8 | 485 | } else { |
mahphalke | 5:78877c8a97c8 | 486 | gpio_set_value(nanodac_dev->gpio_ldac, GPIO_LOW); |
mahphalke | 5:78877c8a97c8 | 487 | } |
mahphalke | 5:78877c8a97c8 | 488 | |
mahphalke | 5:78877c8a97c8 | 489 | ldac_pin_state = pin_state; |
mahphalke | 5:78877c8a97c8 | 490 | printf(EOL EOL"\tLDAC pin set to %ld"EOL, ldac_pin_state); |
mahphalke | 5:78877c8a97c8 | 491 | |
mahphalke | 5:78877c8a97c8 | 492 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 493 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 494 | } |
mahphalke | 5:78877c8a97c8 | 495 | |
mahphalke | 5:78877c8a97c8 | 496 | |
mahphalke | 5:78877c8a97c8 | 497 | /*! |
mahphalke | 5:78877c8a97c8 | 498 | * @brief Handle the menu to assert LDAC pin to update DAC |
mahphalke | 5:78877c8a97c8 | 499 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 500 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 501 | */ |
mahphalke | 5:78877c8a97c8 | 502 | static int32_t menu_select_ldac_pin_state(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 503 | { |
mahphalke | 5:78877c8a97c8 | 504 | // Display the LDAC pin selection menu |
mahphalke | 5:78877c8a97c8 | 505 | adi_do_console_menu(&ldac_pin_select_menu); |
mahphalke | 5:78877c8a97c8 | 506 | |
mahphalke | 5:78877c8a97c8 | 507 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 508 | } |
mahphalke | 5:78877c8a97c8 | 509 | |
mahphalke | 5:78877c8a97c8 | 510 | |
mahphalke | 5:78877c8a97c8 | 511 | /*! |
mahphalke | 5:78877c8a97c8 | 512 | * @brief Handle the menu to set the DAC gain |
mahphalke | 5:78877c8a97c8 | 513 | * @param uint32_t gain_input- Gain input value |
mahphalke | 5:78877c8a97c8 | 514 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 515 | */ |
mahphalke | 5:78877c8a97c8 | 516 | static int32_t menu_set_gain(uint32_t gain_input) |
mahphalke | 5:78877c8a97c8 | 517 | { |
mahphalke | 5:78877c8a97c8 | 518 | // Set the device gain |
mahphalke | 5:78877c8a97c8 | 519 | gain = gain_input; |
mahphalke | 5:78877c8a97c8 | 520 | |
mahphalke | 5:78877c8a97c8 | 521 | #if defined (SOFTWARE_CONTROLLED_GAIN) |
mahphalke | 5:78877c8a97c8 | 522 | ad5686_gain_mode(nanodac_dev, gain); |
mahphalke | 5:78877c8a97c8 | 523 | #else |
mahphalke | 5:78877c8a97c8 | 524 | if (gain == GAIN_LOW) { |
mahphalke | 5:78877c8a97c8 | 525 | gpio_set_value(nanodac_dev->gpio_gain, GPIO_LOW); |
mahphalke | 5:78877c8a97c8 | 526 | } else { |
mahphalke | 5:78877c8a97c8 | 527 | gpio_set_value(nanodac_dev->gpio_gain, GPIO_HIGH); |
mahphalke | 5:78877c8a97c8 | 528 | } |
mahphalke | 5:78877c8a97c8 | 529 | #endif |
mahphalke | 5:78877c8a97c8 | 530 | |
mahphalke | 5:78877c8a97c8 | 531 | printf(EOL EOL"\tGain set to %ld"EOL,gain); |
mahphalke | 5:78877c8a97c8 | 532 | |
mahphalke | 5:78877c8a97c8 | 533 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 534 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 535 | } |
mahphalke | 5:78877c8a97c8 | 536 | |
mahphalke | 5:78877c8a97c8 | 537 | |
mahphalke | 5:78877c8a97c8 | 538 | /*! |
mahphalke | 5:78877c8a97c8 | 539 | * @brief Handle the menu to display DAC gain selections |
mahphalke | 5:78877c8a97c8 | 540 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 541 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 542 | */ |
mahphalke | 5:78877c8a97c8 | 543 | static int32_t menu_gain_selection(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 544 | { |
mahphalke | 5:78877c8a97c8 | 545 | // Display the DAC gain selection menu |
mahphalke | 5:78877c8a97c8 | 546 | adi_do_console_menu(&gain_select_menu); |
mahphalke | 5:78877c8a97c8 | 547 | |
mahphalke | 5:78877c8a97c8 | 548 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 549 | } |
mahphalke | 5:78877c8a97c8 | 550 | |
mahphalke | 5:78877c8a97c8 | 551 | |
mahphalke | 5:78877c8a97c8 | 552 | /*! |
mahphalke | 5:78877c8a97c8 | 553 | * @brief Handle the menu to perform DAC software reset |
mahphalke | 5:78877c8a97c8 | 554 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 555 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 556 | */ |
mahphalke | 5:78877c8a97c8 | 557 | static int32_t menu_assert_software_reset(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 558 | { |
mahphalke | 5:78877c8a97c8 | 559 | // Do device software reset |
mahphalke | 5:78877c8a97c8 | 560 | ad5686_software_reset(nanodac_dev); |
mahphalke | 5:78877c8a97c8 | 561 | |
mahphalke | 5:78877c8a97c8 | 562 | printf(EOL"\tSoftware Reset Complete..."EOL); |
mahphalke | 5:78877c8a97c8 | 563 | |
mahphalke | 5:78877c8a97c8 | 564 | // Device reset disables the LDAC mask through hardware. |
mahphalke | 5:78877c8a97c8 | 565 | // This needs to be synched with software. |
mahphalke | 5:78877c8a97c8 | 566 | ldac_mask_status = false; |
mahphalke | 5:78877c8a97c8 | 567 | |
mahphalke | 5:78877c8a97c8 | 568 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 569 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 570 | } |
mahphalke | 5:78877c8a97c8 | 571 | |
mahphalke | 5:78877c8a97c8 | 572 | |
mahphalke | 5:78877c8a97c8 | 573 | /*! |
mahphalke | 5:78877c8a97c8 | 574 | * @brief Handle the menu to perform DAC hardware reset |
mahphalke | 5:78877c8a97c8 | 575 | * @param uint32_t menu_id- (Optional parameter) |
mahphalke | 5:78877c8a97c8 | 576 | * @return MENU_CONTINUE |
mahphalke | 5:78877c8a97c8 | 577 | */ |
mahphalke | 5:78877c8a97c8 | 578 | static int32_t menu_assert_hardware_reset(uint32_t menu_id) |
mahphalke | 5:78877c8a97c8 | 579 | { |
mahphalke | 5:78877c8a97c8 | 580 | // Do device hardware reset |
mahphalke | 5:78877c8a97c8 | 581 | gpio_set_value(nanodac_dev->gpio_reset, GPIO_LOW); |
mahphalke | 5:78877c8a97c8 | 582 | mdelay(1); |
mahphalke | 5:78877c8a97c8 | 583 | gpio_set_value(nanodac_dev->gpio_reset, GPIO_HIGH); |
mahphalke | 5:78877c8a97c8 | 584 | |
mahphalke | 5:78877c8a97c8 | 585 | printf(EOL"\tHardware Reset Complete..."EOL); |
mahphalke | 5:78877c8a97c8 | 586 | |
mahphalke | 5:78877c8a97c8 | 587 | // Device reset disables the LDAC mask through hardware. |
mahphalke | 5:78877c8a97c8 | 588 | // This needs to be synched with software. |
mahphalke | 5:78877c8a97c8 | 589 | ldac_mask_status = false; |
mahphalke | 5:78877c8a97c8 | 590 | |
mahphalke | 5:78877c8a97c8 | 591 | adi_press_any_key_to_continue(); |
mahphalke | 5:78877c8a97c8 | 592 | return MENU_CONTINUE; |
mahphalke | 5:78877c8a97c8 | 593 | } |
mahphalke | 5:78877c8a97c8 | 594 | |
mahphalke | 5:78877c8a97c8 | 595 | |
mahphalke | 5:78877c8a97c8 | 596 | // Operating mode menu for DAC |
mahphalke | 5:78877c8a97c8 | 597 | static console_menu_item operating_mode_select_items[] = { |
mahphalke | 5:78877c8a97c8 | 598 | { "Normal Power-Up", 'A', menu_select_operating_mode, AD5686_PWRM_NORMAL }, |
mahphalke | 5:78877c8a97c8 | 599 | |
mahphalke | 5:78877c8a97c8 | 600 | #if defined(_1K_TO_GND_POWER_DOWN) |
mahphalke | 5:78877c8a97c8 | 601 | { "1K to GND (Power-Down)", 'B', menu_select_operating_mode, AD5686_PWRM_1K }, |
mahphalke | 5:78877c8a97c8 | 602 | #endif |
mahphalke | 5:78877c8a97c8 | 603 | #if defined(_100K_TO_GND_POWER_DOWN) |
mahphalke | 5:78877c8a97c8 | 604 | { "100K to GND (Power-Down)", 'C', menu_select_operating_mode, AD5686_PWRM_100K }, |
mahphalke | 5:78877c8a97c8 | 605 | #endif |
mahphalke | 5:78877c8a97c8 | 606 | #if defined(THREE_STATE_POWER_DOWN) |
mahphalke | 5:78877c8a97c8 | 607 | { "Three-State (Power-Down)", 'D', menu_select_operating_mode, AD5686_PWRM_THREESTATE }, |
mahphalke | 5:78877c8a97c8 | 608 | #endif |
mahphalke | 5:78877c8a97c8 | 609 | }; |
mahphalke | 5:78877c8a97c8 | 610 | |
mahphalke | 5:78877c8a97c8 | 611 | console_menu operating_mode_select_menu = { |
mahphalke | 5:78877c8a97c8 | 612 | .title = "Select Operating Mode", |
mahphalke | 5:78877c8a97c8 | 613 | .items = operating_mode_select_items, |
mahphalke | 5:78877c8a97c8 | 614 | .itemCount = ARRAY_SIZE(operating_mode_select_items), |
mahphalke | 5:78877c8a97c8 | 615 | .headerItem = display_menu_header, |
mahphalke | 5:78877c8a97c8 | 616 | .footerItem = display_menu_footer, |
mahphalke | 5:78877c8a97c8 | 617 | .enableEscapeKey = true |
mahphalke | 5:78877c8a97c8 | 618 | }; |
mahphalke | 5:78877c8a97c8 | 619 | |
mahphalke | 5:78877c8a97c8 | 620 | |
mahphalke | 5:78877c8a97c8 | 621 | // LDAC pin set menu for DAC |
mahphalke | 5:78877c8a97c8 | 622 | static console_menu_item ldac_pin_select_items[] = { |
mahphalke | 5:78877c8a97c8 | 623 | { "High (VLogic)", 'H', menu_set_ldac_pin, GPIO_HIGH }, |
mahphalke | 5:78877c8a97c8 | 624 | { "Low (GND)", 'L', menu_set_ldac_pin, GPIO_LOW } |
mahphalke | 5:78877c8a97c8 | 625 | }; |
mahphalke | 5:78877c8a97c8 | 626 | |
mahphalke | 5:78877c8a97c8 | 627 | console_menu ldac_pin_select_menu = { |
mahphalke | 5:78877c8a97c8 | 628 | .title = "Select LDAC Mask", |
mahphalke | 5:78877c8a97c8 | 629 | .items = ldac_pin_select_items, |
mahphalke | 5:78877c8a97c8 | 630 | .itemCount = ARRAY_SIZE(ldac_pin_select_items), |
mahphalke | 5:78877c8a97c8 | 631 | .headerItem = display_menu_header, |
mahphalke | 5:78877c8a97c8 | 632 | .footerItem = display_menu_footer, |
mahphalke | 5:78877c8a97c8 | 633 | .enableEscapeKey = true |
mahphalke | 5:78877c8a97c8 | 634 | }; |
mahphalke | 5:78877c8a97c8 | 635 | |
mahphalke | 5:78877c8a97c8 | 636 | |
mahphalke | 5:78877c8a97c8 | 637 | // LDAC mask menu for DAC |
mahphalke | 5:78877c8a97c8 | 638 | static console_menu_item ldac_mask_select_items[] = { |
mahphalke | 5:78877c8a97c8 | 639 | { "Disable (LDAC Pin Controlled)", 'D', menu_set_ldac_mask, 0 }, |
mahphalke | 5:78877c8a97c8 | 640 | { "Enable (LDAC Pin Ignored)", 'E', menu_set_ldac_mask, 1 } |
mahphalke | 5:78877c8a97c8 | 641 | }; |
mahphalke | 5:78877c8a97c8 | 642 | |
mahphalke | 5:78877c8a97c8 | 643 | console_menu ldac_mask_select_menu = { |
mahphalke | 5:78877c8a97c8 | 644 | .title = "Select LDAC Mask", |
mahphalke | 5:78877c8a97c8 | 645 | .items = ldac_mask_select_items, |
mahphalke | 5:78877c8a97c8 | 646 | .itemCount = ARRAY_SIZE(ldac_mask_select_items), |
mahphalke | 5:78877c8a97c8 | 647 | .headerItem = display_menu_header, |
mahphalke | 5:78877c8a97c8 | 648 | .footerItem = display_menu_footer, |
mahphalke | 5:78877c8a97c8 | 649 | .enableEscapeKey = true |
mahphalke | 5:78877c8a97c8 | 650 | }; |
mahphalke | 5:78877c8a97c8 | 651 | |
mahphalke | 5:78877c8a97c8 | 652 | |
mahphalke | 5:78877c8a97c8 | 653 | // Gain select menu for DAC |
mahphalke | 5:78877c8a97c8 | 654 | static console_menu_item gain_select_items[] = { |
mahphalke | 5:78877c8a97c8 | 655 | { "Gain= 1 (Vout: 0-Vref)", '1', menu_set_gain, GAIN_LOW }, |
mahphalke | 5:78877c8a97c8 | 656 | { "Gain= 2 (Vout: 0-2*Vref)", '2', menu_set_gain, GAIN_HIGH } |
mahphalke | 5:78877c8a97c8 | 657 | }; |
mahphalke | 5:78877c8a97c8 | 658 | |
mahphalke | 5:78877c8a97c8 | 659 | console_menu gain_select_menu = { |
mahphalke | 5:78877c8a97c8 | 660 | .title = "Select Gain", |
mahphalke | 5:78877c8a97c8 | 661 | .items = gain_select_items, |
mahphalke | 5:78877c8a97c8 | 662 | .itemCount = ARRAY_SIZE(gain_select_items), |
mahphalke | 5:78877c8a97c8 | 663 | .headerItem = display_menu_header, |
mahphalke | 5:78877c8a97c8 | 664 | .footerItem = display_menu_footer, |
mahphalke | 5:78877c8a97c8 | 665 | .enableEscapeKey = true |
mahphalke | 5:78877c8a97c8 | 666 | }; |
mahphalke | 5:78877c8a97c8 | 667 | |
mahphalke | 5:78877c8a97c8 | 668 | |
mahphalke | 5:78877c8a97c8 | 669 | // Vref select menu for DAC |
mahphalke | 5:78877c8a97c8 | 670 | static console_menu_item vref_select_items[] = { |
mahphalke | 5:78877c8a97c8 | 671 | #if !defined(EXT_VREF_SOURCE_ONLY) |
mahphalke | 5:78877c8a97c8 | 672 | { "Internal Vref", 'I', menu_select_vref_source, INTERNAL_VREF_SOURCE }, |
mahphalke | 5:78877c8a97c8 | 673 | #endif |
mahphalke | 5:78877c8a97c8 | 674 | { "External Vref", 'E', menu_select_vref_source, EXTERNAL_VREF_SOURCE } |
mahphalke | 5:78877c8a97c8 | 675 | }; |
mahphalke | 5:78877c8a97c8 | 676 | |
mahphalke | 5:78877c8a97c8 | 677 | console_menu vref_select_menu = { |
mahphalke | 5:78877c8a97c8 | 678 | .title = "Select Vref Source", |
mahphalke | 5:78877c8a97c8 | 679 | .items = vref_select_items, |
mahphalke | 5:78877c8a97c8 | 680 | .itemCount = ARRAY_SIZE(vref_select_items), |
mahphalke | 5:78877c8a97c8 | 681 | .headerItem = display_menu_header, |
mahphalke | 5:78877c8a97c8 | 682 | .footerItem = display_menu_footer, |
mahphalke | 5:78877c8a97c8 | 683 | .enableEscapeKey = true |
mahphalke | 5:78877c8a97c8 | 684 | }; |
mahphalke | 5:78877c8a97c8 | 685 | |
mahphalke | 5:78877c8a97c8 | 686 | |
mahphalke | 5:78877c8a97c8 | 687 | // Channel selection menu for DAC |
mahphalke | 5:78877c8a97c8 | 688 | static console_menu_item dac_channel_select_items[] = { |
mahphalke | 5:78877c8a97c8 | 689 | { "Channel 0", 'A', menu_select_dac_channel, (uint32_t)AD5686_CH_0 }, |
mahphalke | 5:78877c8a97c8 | 690 | { "Channel 1", 'B', menu_select_dac_channel, (uint32_t)AD5686_CH_1 }, |
mahphalke | 5:78877c8a97c8 | 691 | #if DAC_CHANNEL_COUNT > 2 |
mahphalke | 5:78877c8a97c8 | 692 | { "Channel 2", 'C', menu_select_dac_channel, (uint32_t)AD5686_CH_2 }, |
mahphalke | 5:78877c8a97c8 | 693 | { "Channel 3", 'D', menu_select_dac_channel, (uint32_t)AD5686_CH_3 }, |
mahphalke | 5:78877c8a97c8 | 694 | #endif |
mahphalke | 5:78877c8a97c8 | 695 | #if DAC_CHANNEL_COUNT > 4 |
mahphalke | 5:78877c8a97c8 | 696 | { "Channel 4", 'E', menu_select_dac_channel, (uint32_t)AD5686_CH_4 }, |
mahphalke | 5:78877c8a97c8 | 697 | { "Channel 5", 'F', menu_select_dac_channel, (uint32_t)AD5686_CH_5 }, |
mahphalke | 5:78877c8a97c8 | 698 | { "Channel 6", 'G', menu_select_dac_channel, (uint32_t)AD5686_CH_6 }, |
mahphalke | 5:78877c8a97c8 | 699 | { "Channel 7", 'H', menu_select_dac_channel, (uint32_t)AD5686_CH_7 }, |
mahphalke | 5:78877c8a97c8 | 700 | #endif |
mahphalke | 5:78877c8a97c8 | 701 | #if DAC_CHANNEL_COUNT > 8 |
mahphalke | 5:78877c8a97c8 | 702 | { "Channel 8", 'I', menu_select_dac_channel, (uint32_t)AD5686_CH_8 }, |
mahphalke | 5:78877c8a97c8 | 703 | { "Channel 9", 'J', menu_select_dac_channel, (uint32_t)AD5686_CH_9 }, |
mahphalke | 5:78877c8a97c8 | 704 | { "Channel 10", 'K', menu_select_dac_channel, (uint32_t)AD5686_CH_10 }, |
mahphalke | 5:78877c8a97c8 | 705 | { "Channel 11", 'L', menu_select_dac_channel, (uint32_t)AD5686_CH_11 }, |
mahphalke | 5:78877c8a97c8 | 706 | { "Channel 12", 'M', menu_select_dac_channel, (uint32_t)AD5686_CH_12 }, |
mahphalke | 5:78877c8a97c8 | 707 | { "Channel 13", 'N', menu_select_dac_channel, (uint32_t)AD5686_CH_13 }, |
mahphalke | 5:78877c8a97c8 | 708 | { "Channel 14", 'O', menu_select_dac_channel, (uint32_t)AD5686_CH_14 }, |
mahphalke | 5:78877c8a97c8 | 709 | { "Channel 15", 'P', menu_select_dac_channel, (uint32_t)AD5686_CH_15 }, |
mahphalke | 5:78877c8a97c8 | 710 | #endif |
mahphalke | 5:78877c8a97c8 | 711 | }; |
mahphalke | 5:78877c8a97c8 | 712 | |
mahphalke | 5:78877c8a97c8 | 713 | console_menu dac_channel_select_menu = { |
mahphalke | 5:78877c8a97c8 | 714 | .title = "Select DAC Channel", |
mahphalke | 5:78877c8a97c8 | 715 | .items = dac_channel_select_items, |
mahphalke | 5:78877c8a97c8 | 716 | .itemCount = ARRAY_SIZE(dac_channel_select_items), |
mahphalke | 5:78877c8a97c8 | 717 | .headerItem = display_menu_header, |
mahphalke | 5:78877c8a97c8 | 718 | .footerItem = display_menu_footer, |
mahphalke | 5:78877c8a97c8 | 719 | .enableEscapeKey = true |
mahphalke | 5:78877c8a97c8 | 720 | }; |
mahphalke | 5:78877c8a97c8 | 721 | |
mahphalke | 5:78877c8a97c8 | 722 | |
mahphalke | 5:78877c8a97c8 | 723 | /* |
mahphalke | 5:78877c8a97c8 | 724 | * Definition of the Main Menu Items and menu itself |
mahphalke | 5:78877c8a97c8 | 725 | */ |
mahphalke | 5:78877c8a97c8 | 726 | static console_menu_item main_menu_items[] = { |
mahphalke | 5:78877c8a97c8 | 727 | #ifdef DISPLAY_DAC_CHANNEL_SELECT_MENU |
mahphalke | 5:78877c8a97c8 | 728 | { "Select DAC Channel", 'A', menu_dac_channels }, |
mahphalke | 5:78877c8a97c8 | 729 | {""}, |
mahphalke | 5:78877c8a97c8 | 730 | #endif |
mahphalke | 5:78877c8a97c8 | 731 | { "Write to Input Register (LDAC Dependent)", 'B',menu_write_to_input_register }, |
mahphalke | 5:78877c8a97c8 | 732 | {""}, |
mahphalke | 5:78877c8a97c8 | 733 | { "Update DAC from Input Register", 'C', menu_update_dac_from_input }, |
mahphalke | 5:78877c8a97c8 | 734 | {""}, |
mahphalke | 5:78877c8a97c8 | 735 | { "Update DAC by LDAC Assert (H->L)", 'D', menu_update_dac_by_ldac_assert }, |
mahphalke | 5:78877c8a97c8 | 736 | {""}, |
mahphalke | 5:78877c8a97c8 | 737 | { "Write and Update DAC (Direct Update)", 'E', menu_write_and_update_dac }, |
mahphalke | 5:78877c8a97c8 | 738 | {""}, |
mahphalke | 5:78877c8a97c8 | 739 | { "Read Back DAC Channel", 'F', menu_dac_readback }, |
mahphalke | 5:78877c8a97c8 | 740 | {""}, |
mahphalke | 5:78877c8a97c8 | 741 | #ifdef DISPLAY_LDAC_MASK_SELECT_MENU |
mahphalke | 5:78877c8a97c8 | 742 | { "Set LDAC# Mask", 'G', menu_ldac_masks }, |
mahphalke | 5:78877c8a97c8 | 743 | {""}, |
mahphalke | 5:78877c8a97c8 | 744 | #endif |
mahphalke | 5:78877c8a97c8 | 745 | { "Select LDAC Pin State", 'H', menu_select_ldac_pin_state }, |
mahphalke | 5:78877c8a97c8 | 746 | {""}, |
mahphalke | 5:78877c8a97c8 | 747 | { "Select Operating Mode", 'I', menu_dac_operating_modes }, |
mahphalke | 5:78877c8a97c8 | 748 | {""}, |
mahphalke | 5:78877c8a97c8 | 749 | { "Select Reference Source (Vref)", 'J', menu_vref_sources }, |
mahphalke | 5:78877c8a97c8 | 750 | {""}, |
mahphalke | 5:78877c8a97c8 | 751 | { "Set Gain", 'K', menu_gain_selection }, |
mahphalke | 5:78877c8a97c8 | 752 | {""}, |
mahphalke | 5:78877c8a97c8 | 753 | { "Assert Software Reset", 'L', menu_assert_software_reset }, |
mahphalke | 5:78877c8a97c8 | 754 | {""}, |
mahphalke | 5:78877c8a97c8 | 755 | { "Assert Hardware Reset", 'M', menu_assert_hardware_reset }, |
mahphalke | 5:78877c8a97c8 | 756 | {""}, |
mahphalke | 5:78877c8a97c8 | 757 | }; |
mahphalke | 5:78877c8a97c8 | 758 | |
mahphalke | 5:78877c8a97c8 | 759 | console_menu nanodac_main_menu = { |
mahphalke | 5:78877c8a97c8 | 760 | .title = "Main Menu", |
mahphalke | 5:78877c8a97c8 | 761 | .items = main_menu_items, |
mahphalke | 5:78877c8a97c8 | 762 | .itemCount = ARRAY_SIZE(main_menu_items), |
mahphalke | 5:78877c8a97c8 | 763 | .headerItem = display_menu_header, |
mahphalke | 5:78877c8a97c8 | 764 | .footerItem = display_menu_footer, |
mahphalke | 5:78877c8a97c8 | 765 | .enableEscapeKey = false |
mahphalke | 5:78877c8a97c8 | 766 | }; |