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