This is an forked repository to push changes related to no-OS repository adoption
Dependencies: adi_console_menu platform_drivers
app/ad717x_console_app.c@8:13ddfedfe923, 2021-08-03 (annotated)
- Committer:
- pmallick
- Date:
- Tue Aug 03 11:02:59 2021 +0530
- Revision:
- 8:13ddfedfe923
- Parent:
- 4:4592cc69bfa6
No-OS Adoption Changes:
* Updated the .lib files for adoption of no-OS repository as-is.
* Replaced 'platform_drivers.h' with required header files.
* Updated the copyright year.
Mbed OS update changes:
1) Added the mbed_app.json file with custom parameters.
2) Updated the mbed-os version to 6.8.0
Updated the readme file.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mahphalke | 1:48914f9593f1 | 1 | /*! |
mahphalke | 1:48914f9593f1 | 2 | ***************************************************************************** |
mahphalke | 1:48914f9593f1 | 3 | @file: ad717x_console_app.c |
mahphalke | 1:48914f9593f1 | 4 | |
mahphalke | 1:48914f9593f1 | 5 | @brief: Implementation of the menu functions which handles the |
mahphalke | 1:48914f9593f1 | 6 | functionality of AD717x and AD411x family of devices. |
mahphalke | 1:48914f9593f1 | 7 | |
mahphalke | 1:48914f9593f1 | 8 | @details: This file is specific to AD717x/AD411x console menu application handle. |
mahphalke | 1:48914f9593f1 | 9 | The functions defined in this file performs the action |
mahphalke | 1:48914f9593f1 | 10 | based on user selected console menu. |
mahphalke | 1:48914f9593f1 | 11 | ----------------------------------------------------------------------------- |
pmallick | 8:13ddfedfe923 | 12 | Copyright (c) 2020-2021 Analog Devices, Inc. |
mahphalke | 1:48914f9593f1 | 13 | All rights reserved. |
mahphalke | 1:48914f9593f1 | 14 | |
mahphalke | 1:48914f9593f1 | 15 | This software is proprietary to Analog Devices, Inc. and its licensors. |
mahphalke | 1:48914f9593f1 | 16 | By using this software you agree to the terms of the associated |
mahphalke | 1:48914f9593f1 | 17 | Analog Devices Software License Agreement. |
mahphalke | 1:48914f9593f1 | 18 | *****************************************************************************/ |
mahphalke | 1:48914f9593f1 | 19 | |
mahphalke | 1:48914f9593f1 | 20 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 21 | /***************************** Include Files **********************************/ |
mahphalke | 1:48914f9593f1 | 22 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 23 | |
mahphalke | 1:48914f9593f1 | 24 | #include <stdio.h> |
mahphalke | 1:48914f9593f1 | 25 | #include <string.h> |
mahphalke | 1:48914f9593f1 | 26 | #include <stdbool.h> |
mahphalke | 1:48914f9593f1 | 27 | #include <ctype.h> |
mahphalke | 1:48914f9593f1 | 28 | |
mahphalke | 1:48914f9593f1 | 29 | #include "app_config.h" |
mahphalke | 1:48914f9593f1 | 30 | |
mahphalke | 1:48914f9593f1 | 31 | #include "ad717x.h" |
mahphalke | 1:48914f9593f1 | 32 | #include "platform_support.h" |
pmallick | 8:13ddfedfe923 | 33 | #include "spi.h" |
mahphalke | 1:48914f9593f1 | 34 | #include "spi_extra.h" |
mahphalke | 1:48914f9593f1 | 35 | |
mahphalke | 1:48914f9593f1 | 36 | #include "ad717x_console_app.h" |
mahphalke | 1:48914f9593f1 | 37 | #include "ad717x_menu_defines.h" |
mahphalke | 1:48914f9593f1 | 38 | #include "ad717x_support.h" |
mahphalke | 1:48914f9593f1 | 39 | |
mahphalke | 1:48914f9593f1 | 40 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 41 | /********************** Macros and Constants Definitions **********************/ |
mahphalke | 1:48914f9593f1 | 42 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 43 | |
mahphalke | 1:48914f9593f1 | 44 | // Include the device register address map headers and device register map based |
mahphalke | 1:48914f9593f1 | 45 | // on the user selected device (default is AD4111) |
Mahesh Phalke |
4:4592cc69bfa6 | 46 | #if defined(DEV_AD4111) || defined(DEV_AD4112) || defined(DEV_AD4114) || \ |
Mahesh Phalke |
4:4592cc69bfa6 | 47 | defined(DEV_AD4115) |
mahphalke | 1:48914f9593f1 | 48 | #include <ad411x_regs.h> |
mahphalke | 1:48914f9593f1 | 49 | static ad717x_st_reg *ad717x_device_map = ad4111_regs; |
mahphalke | 1:48914f9593f1 | 50 | static uint8_t ad717x_reg_count = sizeof(ad4111_regs) / sizeof(ad4111_regs[0]); |
mahphalke | 1:48914f9593f1 | 51 | #elif defined(DEV_AD7172_2) |
mahphalke | 1:48914f9593f1 | 52 | #include <ad7172_2_regs.h> |
mahphalke | 1:48914f9593f1 | 53 | static ad717x_st_reg *ad717x_device_map = ad7172_2_regs; |
mahphalke | 1:48914f9593f1 | 54 | static uint8_t ad717x_reg_count = sizeof(ad7172_2_regs) / sizeof( |
mahphalke | 1:48914f9593f1 | 55 | ad7172_2_regs[0]); |
mahphalke | 1:48914f9593f1 | 56 | #elif defined(DEV_AD7172_4) |
mahphalke | 1:48914f9593f1 | 57 | #include <ad7172_4_regs.h> |
mahphalke | 1:48914f9593f1 | 58 | static ad717x_st_reg *ad717x_device_map = ad7172_4_regs; |
mahphalke | 1:48914f9593f1 | 59 | static uint8_t ad717x_reg_count = sizeof(ad7172_4_regs) / sizeof( |
mahphalke | 1:48914f9593f1 | 60 | ad7172_4_regs[0]); |
mahphalke | 1:48914f9593f1 | 61 | #elif defined(DEV_AD7173_8) |
mahphalke | 1:48914f9593f1 | 62 | #include <ad7173_8_regs.h> |
mahphalke | 1:48914f9593f1 | 63 | static ad717x_st_reg *ad717x_device_map = ad7173_8_regs; |
mahphalke | 1:48914f9593f1 | 64 | static uint8_t ad717x_reg_count = sizeof(ad7173_8_regs) / sizeof( |
mahphalke | 1:48914f9593f1 | 65 | ad7173_8_regs[0]); |
mahphalke | 1:48914f9593f1 | 66 | #elif defined(DEV_AD7175_2) |
mahphalke | 1:48914f9593f1 | 67 | #include <ad7175_2_regs.h> |
mahphalke | 1:48914f9593f1 | 68 | static ad717x_st_reg *ad717x_device_map = ad7175_2_regs; |
mahphalke | 1:48914f9593f1 | 69 | static uint8_t ad717x_reg_count = sizeof(ad7175_2_regs) / sizeof( |
mahphalke | 1:48914f9593f1 | 70 | ad7175_2_regs[0]); |
mahphalke | 1:48914f9593f1 | 71 | #elif defined(DEV_AD7175_8) |
mahphalke | 1:48914f9593f1 | 72 | #include <ad7175_8_regs.h> |
mahphalke | 1:48914f9593f1 | 73 | static ad717x_st_reg *ad717x_device_map = ad7175_8_regs; |
mahphalke | 1:48914f9593f1 | 74 | static uint8_t ad717x_reg_count = sizeof(ad7175_8_regs) / sizeof( |
mahphalke | 1:48914f9593f1 | 75 | ad7175_8_regs[0]); |
mahphalke | 1:48914f9593f1 | 76 | #elif defined(DEV_AD7176_2) |
mahphalke | 1:48914f9593f1 | 77 | #include <ad7176_2_regs.h> |
mahphalke | 1:48914f9593f1 | 78 | static ad717x_st_reg *ad717x_device_map = ad7176_2_regs; |
mahphalke | 1:48914f9593f1 | 79 | static uint8_t ad717x_reg_count = sizeof(ad7176_2_regs) / sizeof( |
mahphalke | 1:48914f9593f1 | 80 | ad7176_2_regs[0]); |
mahphalke | 1:48914f9593f1 | 81 | #else |
mahphalke | 1:48914f9593f1 | 82 | #include <ad411x_regs.h> |
mahphalke | 1:48914f9593f1 | 83 | static ad717x_st_reg *ad717x_device_map = ad4111_regs; |
mahphalke | 1:48914f9593f1 | 84 | static uint8_t ad717x_reg_count = sizeof(ad4111_regs) / sizeof(ad4111_regs[0]); |
mahphalke | 1:48914f9593f1 | 85 | #endif |
mahphalke | 1:48914f9593f1 | 86 | |
mahphalke | 1:48914f9593f1 | 87 | |
mahphalke | 1:48914f9593f1 | 88 | #define SHOW_ALL_CHANNELS false |
mahphalke | 1:48914f9593f1 | 89 | #define SHOW_ENABLED_CHANNELS true |
mahphalke | 1:48914f9593f1 | 90 | |
mahphalke | 1:48914f9593f1 | 91 | #define DISPLAY_DATA_TABULAR 0 |
mahphalke | 1:48914f9593f1 | 92 | #define DISPLAY_DATA_STREAM 1 |
mahphalke | 1:48914f9593f1 | 93 | |
mahphalke | 3:6c7324997606 | 94 | // Open wire detect ADC count threshold (eqv of 300mv for bipolar mode) |
mahphalke | 3:6c7324997606 | 95 | #define OPEN_WIRE_DETECT_THRESHOLD 100000 |
mahphalke | 3:6c7324997606 | 96 | |
mahphalke | 1:48914f9593f1 | 97 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 98 | /********************** Variables and User Defined Data Types *****************/ |
mahphalke | 1:48914f9593f1 | 99 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 100 | |
mahphalke | 1:48914f9593f1 | 101 | // Pointer to the struct representing the AD717x device |
mahphalke | 1:48914f9593f1 | 102 | static ad717x_dev *pad717x_dev = NULL; |
mahphalke | 1:48914f9593f1 | 103 | |
mahphalke | 1:48914f9593f1 | 104 | // Device setup |
mahphalke | 1:48914f9593f1 | 105 | static ad717x_setup_config device_setup; |
mahphalke | 1:48914f9593f1 | 106 | |
mahphalke | 1:48914f9593f1 | 107 | // User selected input (pair/positive/negative) |
mahphalke | 1:48914f9593f1 | 108 | static uint8_t input_to_select; |
mahphalke | 1:48914f9593f1 | 109 | |
mahphalke | 1:48914f9593f1 | 110 | // Last Sampled values for All ADC channels |
mahphalke | 1:48914f9593f1 | 111 | static uint32_t channel_samples[NUMBER_OF_CHANNELS] = { 0 }; |
mahphalke | 1:48914f9593f1 | 112 | |
mahphalke | 1:48914f9593f1 | 113 | // How many times a given channel is sampled in total for one sample run |
mahphalke | 1:48914f9593f1 | 114 | static uint32_t channel_samples_count[NUMBER_OF_CHANNELS] = { 0 }; |
mahphalke | 1:48914f9593f1 | 115 | |
mahphalke | 3:6c7324997606 | 116 | // Variables used for open wire detection functionality |
mahphalke | 3:6c7324997606 | 117 | static uint32_t analog_input_type; // Analog input type |
mahphalke | 3:6c7324997606 | 118 | static uint32_t channel_pair; // Channel pair for open wire detection |
mahphalke | 3:6c7324997606 | 119 | static int32_t open_wire_detect_sample_data[2]; // Sampled data for channel pair |
mahphalke | 3:6c7324997606 | 120 | |
mahphalke | 1:48914f9593f1 | 121 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 122 | /************************ Functions Declarations ******************************/ |
mahphalke | 1:48914f9593f1 | 123 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 124 | |
mahphalke | 1:48914f9593f1 | 125 | static bool was_escape_key_pressed(void); |
mahphalke | 1:48914f9593f1 | 126 | |
mahphalke | 1:48914f9593f1 | 127 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 128 | /************************ Functions Definitions *******************************/ |
mahphalke | 1:48914f9593f1 | 129 | /******************************************************************************/ |
mahphalke | 1:48914f9593f1 | 130 | |
mahphalke | 1:48914f9593f1 | 131 | /*! |
mahphalke | 1:48914f9593f1 | 132 | * @brief Initialize the AD717x device and associated low level peripherals |
mahphalke | 1:48914f9593f1 | 133 | * @return SUCCESS(0) Or FAILURE(negative) |
mahphalke | 1:48914f9593f1 | 134 | */ |
mahphalke | 1:48914f9593f1 | 135 | int32_t ad717x_app_initialize(void) |
mahphalke | 1:48914f9593f1 | 136 | { |
mahphalke | 1:48914f9593f1 | 137 | // Init SPI extra parameters structure |
mahphalke | 1:48914f9593f1 | 138 | mbed_spi_init_param spi_init_extra_params = { |
mahphalke | 1:48914f9593f1 | 139 | .spi_clk_pin = SPI_SCK, |
mahphalke | 1:48914f9593f1 | 140 | .spi_miso_pin = SPI_MISO, |
mahphalke | 1:48914f9593f1 | 141 | .spi_mosi_pin = SPI_MOSI |
mahphalke | 1:48914f9593f1 | 142 | }; |
mahphalke | 1:48914f9593f1 | 143 | |
mahphalke | 1:48914f9593f1 | 144 | // Used to create the ad717x device |
mahphalke | 1:48914f9593f1 | 145 | ad717x_init_param ad717x_init = { |
mahphalke | 1:48914f9593f1 | 146 | // spi_init_param type |
mahphalke | 1:48914f9593f1 | 147 | { |
pmallick | 8:13ddfedfe923 | 148 | .max_speed_hz = 2500000, // Max SPI Speed |
pmallick | 8:13ddfedfe923 | 149 | .chip_select = SPI_SS, // Chip Select pin |
pmallick | 8:13ddfedfe923 | 150 | .mode = SPI_MODE_3, // CPOL = 1, CPHA =1 |
pmallick | 8:13ddfedfe923 | 151 | .extra = &spi_init_extra_params // SPI extra configurations |
mahphalke | 1:48914f9593f1 | 152 | }, |
mahphalke | 1:48914f9593f1 | 153 | ad717x_device_map, // pointer to device register map |
mahphalke | 1:48914f9593f1 | 154 | ad717x_reg_count, // number of device registers |
mahphalke | 1:48914f9593f1 | 155 | }; |
mahphalke | 1:48914f9593f1 | 156 | |
mahphalke | 1:48914f9593f1 | 157 | // Initialze the device |
mahphalke | 1:48914f9593f1 | 158 | return (AD717X_Init(&pad717x_dev, ad717x_init)); |
mahphalke | 1:48914f9593f1 | 159 | } |
mahphalke | 1:48914f9593f1 | 160 | |
mahphalke | 1:48914f9593f1 | 161 | |
mahphalke | 1:48914f9593f1 | 162 | /*! |
mahphalke | 1:48914f9593f1 | 163 | * @brief determines if the Escape key was pressed |
mahphalke | 3:6c7324997606 | 164 | * @return key press status |
mahphalke | 1:48914f9593f1 | 165 | */ |
mahphalke | 1:48914f9593f1 | 166 | static bool was_escape_key_pressed(void) |
mahphalke | 1:48914f9593f1 | 167 | { |
mahphalke | 1:48914f9593f1 | 168 | char rxChar; |
mahphalke | 1:48914f9593f1 | 169 | bool wasPressed = false; |
mahphalke | 1:48914f9593f1 | 170 | |
mahphalke | 1:48914f9593f1 | 171 | // Check for Escape key pressed |
mahphalke | 1:48914f9593f1 | 172 | if ((rxChar = getchar_noblock()) > 0) { |
mahphalke | 1:48914f9593f1 | 173 | if (rxChar == ESCAPE_KEY_CODE) { |
mahphalke | 1:48914f9593f1 | 174 | wasPressed = true; |
mahphalke | 1:48914f9593f1 | 175 | } |
mahphalke | 1:48914f9593f1 | 176 | } |
mahphalke | 1:48914f9593f1 | 177 | |
mahphalke | 1:48914f9593f1 | 178 | return (wasPressed); |
mahphalke | 1:48914f9593f1 | 179 | } |
mahphalke | 1:48914f9593f1 | 180 | |
mahphalke | 1:48914f9593f1 | 181 | |
mahphalke | 1:48914f9593f1 | 182 | /* @brief Perform the channel selection |
mahphalke | 3:6c7324997606 | 183 | * @return Selected channel |
mahphalke | 1:48914f9593f1 | 184 | **/ |
mahphalke | 1:48914f9593f1 | 185 | static uint8_t get_channel_selection(void) |
mahphalke | 1:48914f9593f1 | 186 | { |
mahphalke | 1:48914f9593f1 | 187 | uint32_t current_channel = 0; |
mahphalke | 1:48914f9593f1 | 188 | bool current_selection_done = false; |
mahphalke | 1:48914f9593f1 | 189 | |
mahphalke | 1:48914f9593f1 | 190 | do { |
mahphalke | 1:48914f9593f1 | 191 | printf(EOL "\tEnter Channel Value <0-%d>: ", NUMBER_OF_CHANNELS-1); |
mahphalke | 1:48914f9593f1 | 192 | current_channel = adi_get_decimal_int(sizeof(current_channel)); |
mahphalke | 1:48914f9593f1 | 193 | |
mahphalke | 1:48914f9593f1 | 194 | if (current_channel < NUMBER_OF_CHANNELS) { |
mahphalke | 1:48914f9593f1 | 195 | current_selection_done = true; |
mahphalke | 1:48914f9593f1 | 196 | } else { |
mahphalke | 1:48914f9593f1 | 197 | printf(EOL "\tInvalid channel selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 198 | } |
mahphalke | 1:48914f9593f1 | 199 | } while (current_selection_done == false); |
mahphalke | 1:48914f9593f1 | 200 | |
mahphalke | 1:48914f9593f1 | 201 | return current_channel; |
mahphalke | 1:48914f9593f1 | 202 | } |
mahphalke | 1:48914f9593f1 | 203 | |
mahphalke | 1:48914f9593f1 | 204 | |
mahphalke | 1:48914f9593f1 | 205 | /* @brief Perform the setup selection |
mahphalke | 3:6c7324997606 | 206 | * @return Selected setup |
mahphalke | 1:48914f9593f1 | 207 | **/ |
mahphalke | 1:48914f9593f1 | 208 | static uint8_t get_setup_selection(void) |
mahphalke | 1:48914f9593f1 | 209 | { |
mahphalke | 1:48914f9593f1 | 210 | uint32_t current_setup = 0; |
mahphalke | 1:48914f9593f1 | 211 | bool current_selection_done = false; |
mahphalke | 1:48914f9593f1 | 212 | |
mahphalke | 1:48914f9593f1 | 213 | do { |
mahphalke | 1:48914f9593f1 | 214 | printf(EOL "\tEnter Setup Selection <0-%d>: ", NUMBER_OF_SETUPS-1); |
mahphalke | 1:48914f9593f1 | 215 | current_setup = adi_get_decimal_int(sizeof(current_setup)); |
mahphalke | 1:48914f9593f1 | 216 | |
mahphalke | 1:48914f9593f1 | 217 | if (current_setup < NUMBER_OF_SETUPS) { |
mahphalke | 1:48914f9593f1 | 218 | current_selection_done = true; |
mahphalke | 1:48914f9593f1 | 219 | } else { |
mahphalke | 1:48914f9593f1 | 220 | printf(EOL "\tInvalid setup selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 221 | } |
mahphalke | 1:48914f9593f1 | 222 | } while (current_selection_done == false); |
mahphalke | 1:48914f9593f1 | 223 | |
mahphalke | 1:48914f9593f1 | 224 | return current_setup; |
mahphalke | 1:48914f9593f1 | 225 | } |
mahphalke | 1:48914f9593f1 | 226 | |
mahphalke | 1:48914f9593f1 | 227 | |
mahphalke | 1:48914f9593f1 | 228 | /* @brief Assign setup to adc channel |
mahphalke | 3:6c7324997606 | 229 | * @param setup to be assigned |
mahphalke | 1:48914f9593f1 | 230 | **/ |
mahphalke | 1:48914f9593f1 | 231 | static void assign_setup_to_channel(uint8_t setup) |
mahphalke | 1:48914f9593f1 | 232 | { |
mahphalke | 1:48914f9593f1 | 233 | uint8_t current_channel; // channel to be assigned with setup |
mahphalke | 1:48914f9593f1 | 234 | ad717x_st_reg *device_chnmap_reg; // pointer to channel map register |
mahphalke | 1:48914f9593f1 | 235 | |
mahphalke | 1:48914f9593f1 | 236 | adi_clear_console(); |
mahphalke | 1:48914f9593f1 | 237 | |
mahphalke | 1:48914f9593f1 | 238 | // Get the channel selection |
mahphalke | 1:48914f9593f1 | 239 | current_channel = get_channel_selection(); |
mahphalke | 1:48914f9593f1 | 240 | |
mahphalke | 1:48914f9593f1 | 241 | // Get the pointer to channel map register structure |
mahphalke | 1:48914f9593f1 | 242 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 243 | AD717X_CHMAP0_REG + current_channel); |
mahphalke | 1:48914f9593f1 | 244 | |
mahphalke | 1:48914f9593f1 | 245 | // Load the setup value |
mahphalke | 1:48914f9593f1 | 246 | device_chnmap_reg->value = |
mahphalke | 1:48914f9593f1 | 247 | ((device_chnmap_reg->value & ~AD717X_CHMAP_REG_SETUP_SEL_MSK) | |
mahphalke | 1:48914f9593f1 | 248 | AD717X_CHMAP_REG_SETUP_SEL(setup)); |
mahphalke | 1:48914f9593f1 | 249 | |
mahphalke | 1:48914f9593f1 | 250 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 251 | AD717X_CHMAP0_REG + current_channel) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 252 | printf(EOL "\tError in setup assignment!!" EOL); |
mahphalke | 1:48914f9593f1 | 253 | } else { |
mahphalke | 1:48914f9593f1 | 254 | printf(EOL "\tSetup %d is assigned to channel %d successfully..." EOL, |
mahphalke | 1:48914f9593f1 | 255 | setup, |
mahphalke | 1:48914f9593f1 | 256 | current_channel); |
mahphalke | 1:48914f9593f1 | 257 | } |
mahphalke | 1:48914f9593f1 | 258 | |
mahphalke | 1:48914f9593f1 | 259 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 260 | } |
mahphalke | 1:48914f9593f1 | 261 | |
mahphalke | 1:48914f9593f1 | 262 | |
mahphalke | 1:48914f9593f1 | 263 | /* @brief Select adc channel to be assigned to setup |
mahphalke | 1:48914f9593f1 | 264 | * @return none |
mahphalke | 1:48914f9593f1 | 265 | **/ |
Mahesh Phalke |
4:4592cc69bfa6 | 266 | static char select_chn_assignment(void) |
mahphalke | 1:48914f9593f1 | 267 | { |
mahphalke | 1:48914f9593f1 | 268 | bool current_selection_done = false; |
mahphalke | 1:48914f9593f1 | 269 | char rx_char; |
mahphalke | 1:48914f9593f1 | 270 | |
mahphalke | 1:48914f9593f1 | 271 | do { |
mahphalke | 1:48914f9593f1 | 272 | printf(EOL EOL "\tDo you want to assign setup to a channel (y/n)?: "); |
mahphalke | 1:48914f9593f1 | 273 | rx_char = toupper(getchar()); |
mahphalke | 1:48914f9593f1 | 274 | |
mahphalke | 1:48914f9593f1 | 275 | if (rx_char == 'Y') { |
mahphalke | 1:48914f9593f1 | 276 | assign_setup_to_channel(device_setup.setup); |
mahphalke | 1:48914f9593f1 | 277 | current_selection_done = true; |
mahphalke | 1:48914f9593f1 | 278 | } else if (rx_char == 'N') { |
mahphalke | 1:48914f9593f1 | 279 | current_selection_done = true; |
mahphalke | 1:48914f9593f1 | 280 | } else { |
mahphalke | 1:48914f9593f1 | 281 | printf(EOL "\tInvalid entry!!"); |
mahphalke | 1:48914f9593f1 | 282 | } |
mahphalke | 1:48914f9593f1 | 283 | } while (current_selection_done == false); |
Mahesh Phalke |
4:4592cc69bfa6 | 284 | |
Mahesh Phalke |
4:4592cc69bfa6 | 285 | return rx_char; |
mahphalke | 1:48914f9593f1 | 286 | } |
mahphalke | 1:48914f9593f1 | 287 | |
mahphalke | 1:48914f9593f1 | 288 | |
mahphalke | 1:48914f9593f1 | 289 | /*! |
mahphalke | 1:48914f9593f1 | 290 | * @brief Display the header info for main menu |
mahphalke | 1:48914f9593f1 | 291 | * @return None |
mahphalke | 1:48914f9593f1 | 292 | */ |
mahphalke | 1:48914f9593f1 | 293 | void display_main_menu_header(void) |
mahphalke | 1:48914f9593f1 | 294 | { |
mahphalke | 1:48914f9593f1 | 295 | // Display the device name |
mahphalke | 1:48914f9593f1 | 296 | printf(EOL "\tDevice: %s" EOL, ACTIVE_DEVICE_NAME); |
mahphalke | 1:48914f9593f1 | 297 | } |
mahphalke | 1:48914f9593f1 | 298 | |
mahphalke | 1:48914f9593f1 | 299 | |
mahphalke | 1:48914f9593f1 | 300 | /*! |
mahphalke | 1:48914f9593f1 | 301 | * @brief Handle the menu to read device ID |
mahphalke | 3:6c7324997606 | 302 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 303 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 304 | */ |
mahphalke | 1:48914f9593f1 | 305 | int32_t menu_read_id(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 306 | { |
mahphalke | 1:48914f9593f1 | 307 | ad717x_st_reg *device_id_reg; // Pointer to register |
mahphalke | 1:48914f9593f1 | 308 | |
mahphalke | 1:48914f9593f1 | 309 | device_id_reg = AD717X_GetReg(pad717x_dev, AD717X_ID_REG); |
mahphalke | 1:48914f9593f1 | 310 | if (!device_id_reg) { |
mahphalke | 1:48914f9593f1 | 311 | printf(EOL EOL "\tError reading device ID!!" EOL); |
mahphalke | 1:48914f9593f1 | 312 | } else { |
mahphalke | 1:48914f9593f1 | 313 | if (AD717X_ReadRegister(pad717x_dev, AD717X_ID_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 314 | printf(EOL EOL "\tError reading device ID!!" EOL); |
mahphalke | 1:48914f9593f1 | 315 | } else { |
mahphalke | 1:48914f9593f1 | 316 | printf(EOL EOL "\tDevice ID: 0x%lx" EOL, device_id_reg->value); |
mahphalke | 1:48914f9593f1 | 317 | } |
mahphalke | 1:48914f9593f1 | 318 | } |
mahphalke | 1:48914f9593f1 | 319 | |
mahphalke | 1:48914f9593f1 | 320 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 321 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 322 | } |
mahphalke | 1:48914f9593f1 | 323 | |
mahphalke | 1:48914f9593f1 | 324 | |
mahphalke | 1:48914f9593f1 | 325 | /*! |
mahphalke | 1:48914f9593f1 | 326 | * @brief Handle the menu to read device status register |
mahphalke | 3:6c7324997606 | 327 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 328 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 329 | */ |
mahphalke | 1:48914f9593f1 | 330 | int32_t menu_read_status(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 331 | { |
mahphalke | 1:48914f9593f1 | 332 | ad717x_st_reg *device_status_reg; // Pointer to register |
mahphalke | 1:48914f9593f1 | 333 | |
mahphalke | 1:48914f9593f1 | 334 | device_status_reg = AD717X_GetReg(pad717x_dev, AD717X_STATUS_REG); |
mahphalke | 1:48914f9593f1 | 335 | if (!device_status_reg) { |
mahphalke | 1:48914f9593f1 | 336 | printf(EOL EOL "\tError reading status register!!" EOL); |
mahphalke | 1:48914f9593f1 | 337 | } else { |
mahphalke | 1:48914f9593f1 | 338 | if (AD717X_ReadRegister(pad717x_dev, AD717X_STATUS_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 339 | printf(EOL EOL "\tError reading status register!!" EOL); |
mahphalke | 1:48914f9593f1 | 340 | } else { |
mahphalke | 1:48914f9593f1 | 341 | printf(EOL EOL "\tStatus Register: 0x%lx" EOL, device_status_reg->value); |
mahphalke | 1:48914f9593f1 | 342 | } |
mahphalke | 1:48914f9593f1 | 343 | } |
mahphalke | 1:48914f9593f1 | 344 | |
mahphalke | 1:48914f9593f1 | 345 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 346 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 347 | } |
mahphalke | 1:48914f9593f1 | 348 | |
mahphalke | 1:48914f9593f1 | 349 | |
mahphalke | 1:48914f9593f1 | 350 | /* |
mahphalke | 1:48914f9593f1 | 351 | * @brief helper function get the bipolar setting for an ADC channel |
mahphalke | 1:48914f9593f1 | 352 | * |
mahphalke | 1:48914f9593f1 | 353 | * @param dev The device structure. |
mahphalke | 1:48914f9593f1 | 354 | * |
mahphalke | 1:48914f9593f1 | 355 | * @param channel ADC channel to get bipolar mode for. |
mahphalke | 1:48914f9593f1 | 356 | * |
mahphalke | 1:48914f9593f1 | 357 | * @return value of bipolar field in the setup for an ADC channel. |
mahphalke | 1:48914f9593f1 | 358 | */ |
mahphalke | 1:48914f9593f1 | 359 | static bool ad717x_get_channel_bipolar(ad717x_dev *dev, uint8_t channel) |
mahphalke | 1:48914f9593f1 | 360 | { |
mahphalke | 1:48914f9593f1 | 361 | ad717x_st_reg *device_setup_reg; // Pointer to device setup register |
mahphalke | 1:48914f9593f1 | 362 | ad717x_st_reg *device_chnmap_reg; // Pointer to device channelmap register |
mahphalke | 1:48914f9593f1 | 363 | uint8_t polarity; // Polarity status flag |
mahphalke | 1:48914f9593f1 | 364 | uint8_t setup; // Current setup |
mahphalke | 1:48914f9593f1 | 365 | |
mahphalke | 1:48914f9593f1 | 366 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + channel); |
mahphalke | 1:48914f9593f1 | 367 | (void)AD717X_ReadRegister(pad717x_dev, AD717X_CHMAP0_REG + channel); |
mahphalke | 1:48914f9593f1 | 368 | |
mahphalke | 1:48914f9593f1 | 369 | // Read the setup value for the current channel |
mahphalke | 1:48914f9593f1 | 370 | setup = AD717X_CHMAP_REG_SETUP_SEL_RD(device_chnmap_reg->value); |
mahphalke | 1:48914f9593f1 | 371 | |
mahphalke | 1:48914f9593f1 | 372 | device_setup_reg = AD717X_GetReg(pad717x_dev, AD717X_SETUPCON0_REG + setup); |
mahphalke | 1:48914f9593f1 | 373 | (void)AD717X_ReadRegister(pad717x_dev, AD717X_SETUPCON0_REG + setup); |
mahphalke | 1:48914f9593f1 | 374 | |
mahphalke | 1:48914f9593f1 | 375 | // Get the polarity bit for current setup |
mahphalke | 1:48914f9593f1 | 376 | polarity = AD717X_SETUP_CONF_REG_BI_UNIPOLAR_RD(device_setup_reg->value); |
mahphalke | 1:48914f9593f1 | 377 | |
mahphalke | 1:48914f9593f1 | 378 | if (polarity == BIPOLAR) { |
mahphalke | 1:48914f9593f1 | 379 | return true; |
mahphalke | 1:48914f9593f1 | 380 | } else { |
mahphalke | 1:48914f9593f1 | 381 | return false; |
mahphalke | 1:48914f9593f1 | 382 | } |
mahphalke | 1:48914f9593f1 | 383 | } |
mahphalke | 1:48914f9593f1 | 384 | |
mahphalke | 1:48914f9593f1 | 385 | |
mahphalke | 1:48914f9593f1 | 386 | /* |
mahphalke | 1:48914f9593f1 | 387 | * @brief converts ADC sample value to voltage based on gain setting |
mahphalke | 1:48914f9593f1 | 388 | * |
mahphalke | 1:48914f9593f1 | 389 | * @param dev The device structure. |
mahphalke | 1:48914f9593f1 | 390 | * |
mahphalke | 1:48914f9593f1 | 391 | * @param channel ADC channel to get Setup for. |
mahphalke | 1:48914f9593f1 | 392 | * |
mahphalke | 1:48914f9593f1 | 393 | * @param sample Raw ADC sample |
mahphalke | 1:48914f9593f1 | 394 | * |
mahphalke | 1:48914f9593f1 | 395 | * @return Sample ADC value converted to voltage. |
mahphalke | 1:48914f9593f1 | 396 | * |
mahphalke | 1:48914f9593f1 | 397 | * @note The conversion equation is implemented for simplicity, |
mahphalke | 1:48914f9593f1 | 398 | * not for accuracy or performance |
mahphalke | 1:48914f9593f1 | 399 | * |
mahphalke | 1:48914f9593f1 | 400 | */ |
mahphalke | 1:48914f9593f1 | 401 | static float ad717x_convert_sample_to_voltage(ad717x_dev *dev, |
mahphalke | 1:48914f9593f1 | 402 | uint8_t channel, |
mahphalke | 1:48914f9593f1 | 403 | uint32_t sample) |
mahphalke | 1:48914f9593f1 | 404 | { |
mahphalke | 1:48914f9593f1 | 405 | float converted_value; |
mahphalke | 1:48914f9593f1 | 406 | bool is_bipolar = ad717x_get_channel_bipolar(dev, channel); |
mahphalke | 1:48914f9593f1 | 407 | |
mahphalke | 1:48914f9593f1 | 408 | if (is_bipolar) { |
mahphalke | 1:48914f9593f1 | 409 | converted_value = (((float)sample / (1 << (ADC_RESOLUTION - 1))) - 1) * |
mahphalke | 1:48914f9593f1 | 410 | ADC_REF_VOLTAGE; |
mahphalke | 1:48914f9593f1 | 411 | } else { |
mahphalke | 1:48914f9593f1 | 412 | converted_value = (((float)sample * ADC_REF_VOLTAGE) / (1 << ADC_RESOLUTION)); |
mahphalke | 1:48914f9593f1 | 413 | } |
mahphalke | 1:48914f9593f1 | 414 | |
mahphalke | 1:48914f9593f1 | 415 | return (converted_value); |
mahphalke | 1:48914f9593f1 | 416 | } |
mahphalke | 1:48914f9593f1 | 417 | |
mahphalke | 1:48914f9593f1 | 418 | |
mahphalke | 1:48914f9593f1 | 419 | /*! |
mahphalke | 1:48914f9593f1 | 420 | * @brief displays the current sample value for a ADC channels |
mahphalke | 1:48914f9593f1 | 421 | * |
mahphalke | 1:48914f9593f1 | 422 | * @param showOnlyEnabledChannels only channels that are enabled are displayed |
mahphalke | 1:48914f9593f1 | 423 | * |
mahphalke | 1:48914f9593f1 | 424 | */ |
mahphalke | 1:48914f9593f1 | 425 | static void dislay_channel_samples(bool showOnlyEnabledChannels, |
mahphalke | 1:48914f9593f1 | 426 | uint8_t console_mode) |
mahphalke | 1:48914f9593f1 | 427 | { |
mahphalke | 1:48914f9593f1 | 428 | ad717x_st_reg *device_chnmap_reg; // Pointer to channel map register |
mahphalke | 1:48914f9593f1 | 429 | bool channel_printed = false; // Channel print status flag |
mahphalke | 1:48914f9593f1 | 430 | |
mahphalke | 1:48914f9593f1 | 431 | switch (console_mode) { |
mahphalke | 1:48914f9593f1 | 432 | case DISPLAY_DATA_TABULAR: |
mahphalke | 1:48914f9593f1 | 433 | printf("\tCh\tValue\t\tCount\t\tVoltage" EOL); |
mahphalke | 1:48914f9593f1 | 434 | for (uint8_t chn = 0; chn < NUMBER_OF_CHANNELS; chn++) { |
mahphalke | 1:48914f9593f1 | 435 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 436 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn); |
mahphalke | 1:48914f9593f1 | 437 | |
mahphalke | 1:48914f9593f1 | 438 | // if showing all channels, or channel is enabled |
mahphalke | 1:48914f9593f1 | 439 | if ((showOnlyEnabledChannels == false) |
mahphalke | 1:48914f9593f1 | 440 | || (device_chnmap_reg->value & AD717X_CHMAP_REG_CH_EN)) { |
mahphalke | 1:48914f9593f1 | 441 | printf("\t%-2d\t%-10ld\t%ld\t\t% .6f" EOL, |
mahphalke | 1:48914f9593f1 | 442 | chn, |
mahphalke | 1:48914f9593f1 | 443 | channel_samples[chn], |
mahphalke | 1:48914f9593f1 | 444 | channel_samples_count[chn], |
mahphalke | 1:48914f9593f1 | 445 | ad717x_convert_sample_to_voltage(pad717x_dev, chn, channel_samples[chn])); |
mahphalke | 1:48914f9593f1 | 446 | } |
mahphalke | 1:48914f9593f1 | 447 | } |
mahphalke | 1:48914f9593f1 | 448 | break; |
mahphalke | 1:48914f9593f1 | 449 | |
mahphalke | 1:48914f9593f1 | 450 | case DISPLAY_DATA_STREAM: |
mahphalke | 1:48914f9593f1 | 451 | // Output a CSV list of the sampled channels as voltages on a single line |
mahphalke | 1:48914f9593f1 | 452 | for (uint8_t chn = 0 ; chn < NUMBER_OF_CHANNELS; chn++) { |
mahphalke | 1:48914f9593f1 | 453 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 454 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn); |
mahphalke | 1:48914f9593f1 | 455 | |
mahphalke | 1:48914f9593f1 | 456 | // if showing all channels, or channel is enabled |
mahphalke | 1:48914f9593f1 | 457 | if ((showOnlyEnabledChannels == false) || |
mahphalke | 1:48914f9593f1 | 458 | (device_chnmap_reg->value & AD717X_CHMAP_REG_CH_EN)) { |
mahphalke | 1:48914f9593f1 | 459 | /* |
mahphalke | 1:48914f9593f1 | 460 | * add the comma before we output the next channel but |
mahphalke | 1:48914f9593f1 | 461 | * only if at least one channel has been printed |
mahphalke | 1:48914f9593f1 | 462 | */ |
mahphalke | 1:48914f9593f1 | 463 | if (channel_printed) { |
mahphalke | 1:48914f9593f1 | 464 | printf(", "); |
mahphalke | 1:48914f9593f1 | 465 | } |
mahphalke | 1:48914f9593f1 | 466 | |
mahphalke | 1:48914f9593f1 | 467 | printf("%.6f", ad717x_convert_sample_to_voltage(pad717x_dev, chn, |
mahphalke | 1:48914f9593f1 | 468 | channel_samples[chn])); |
mahphalke | 1:48914f9593f1 | 469 | |
mahphalke | 1:48914f9593f1 | 470 | channel_printed = true; |
mahphalke | 1:48914f9593f1 | 471 | } |
mahphalke | 1:48914f9593f1 | 472 | } |
mahphalke | 1:48914f9593f1 | 473 | printf(EOL); |
mahphalke | 1:48914f9593f1 | 474 | break; |
mahphalke | 1:48914f9593f1 | 475 | |
mahphalke | 1:48914f9593f1 | 476 | default: |
mahphalke | 1:48914f9593f1 | 477 | break; |
mahphalke | 1:48914f9593f1 | 478 | } |
mahphalke | 1:48914f9593f1 | 479 | } |
mahphalke | 1:48914f9593f1 | 480 | |
mahphalke | 1:48914f9593f1 | 481 | |
mahphalke | 1:48914f9593f1 | 482 | /*! |
mahphalke | 1:48914f9593f1 | 483 | * @brief resets the channelSampleCounts to zero |
mahphalke | 1:48914f9593f1 | 484 | * |
mahphalke | 1:48914f9593f1 | 485 | * @details |
mahphalke | 1:48914f9593f1 | 486 | */ |
mahphalke | 1:48914f9593f1 | 487 | static void clear_channel_samples(void) |
mahphalke | 1:48914f9593f1 | 488 | { |
mahphalke | 1:48914f9593f1 | 489 | for (uint8_t i = 0; i < NUMBER_OF_CHANNELS; i++) { |
mahphalke | 1:48914f9593f1 | 490 | channel_samples[i] = 0; |
mahphalke | 1:48914f9593f1 | 491 | channel_samples_count[i] = 0; |
mahphalke | 1:48914f9593f1 | 492 | } |
mahphalke | 1:48914f9593f1 | 493 | } |
mahphalke | 1:48914f9593f1 | 494 | |
mahphalke | 1:48914f9593f1 | 495 | |
mahphalke | 1:48914f9593f1 | 496 | /*! |
mahphalke | 1:48914f9593f1 | 497 | * @brief Continuously acquires samples in Continuous Conversion mode |
mahphalke | 1:48914f9593f1 | 498 | * |
mahphalke | 1:48914f9593f1 | 499 | * @details The ADC is run in continuous mode, and all samples are acquired |
mahphalke | 1:48914f9593f1 | 500 | * and assigned to the channel they come from. Escape key an be used |
mahphalke | 1:48914f9593f1 | 501 | * to exit the loop |
mahphalke | 1:48914f9593f1 | 502 | */ |
mahphalke | 1:48914f9593f1 | 503 | static int32_t do_continuous_conversion(uint8_t display_mode) |
mahphalke | 1:48914f9593f1 | 504 | { |
mahphalke | 1:48914f9593f1 | 505 | int32_t error_code; |
mahphalke | 1:48914f9593f1 | 506 | int32_t sample_data; |
mahphalke | 1:48914f9593f1 | 507 | ad717x_st_reg *device_mode_reg; |
mahphalke | 1:48914f9593f1 | 508 | ad717x_st_reg *device_chnmap_reg; |
mahphalke | 1:48914f9593f1 | 509 | ad717x_st_reg *device_status_reg; |
mahphalke | 1:48914f9593f1 | 510 | |
mahphalke | 1:48914f9593f1 | 511 | // Get the pointer to mode register |
mahphalke | 1:48914f9593f1 | 512 | device_mode_reg = AD717X_GetReg(pad717x_dev, AD717X_ADCMODE_REG); |
mahphalke | 1:48914f9593f1 | 513 | |
mahphalke | 1:48914f9593f1 | 514 | // Clear the ADC CTRL MODE bits, has the effect of selecting continuous mode |
mahphalke | 1:48914f9593f1 | 515 | device_mode_reg->value &= ~(AD717X_ADCMODE_REG_MODE(0xf)); |
mahphalke | 1:48914f9593f1 | 516 | |
mahphalke | 1:48914f9593f1 | 517 | if ((error_code = AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 518 | AD717X_ADCMODE_REG)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 519 | printf("Error (%ld) setting AD717x Continuous conversion mode." EOL, |
mahphalke | 1:48914f9593f1 | 520 | error_code); |
mahphalke | 1:48914f9593f1 | 521 | |
mahphalke | 1:48914f9593f1 | 522 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 523 | return (MENU_CONTINUE); |
mahphalke | 1:48914f9593f1 | 524 | } |
mahphalke | 1:48914f9593f1 | 525 | |
mahphalke | 1:48914f9593f1 | 526 | clear_channel_samples(); |
mahphalke | 1:48914f9593f1 | 527 | |
mahphalke | 1:48914f9593f1 | 528 | /* |
mahphalke | 1:48914f9593f1 | 529 | * If displaying data in stream form, want to output a channel header |
mahphalke | 1:48914f9593f1 | 530 | */ |
mahphalke | 1:48914f9593f1 | 531 | if (display_mode == DISPLAY_DATA_STREAM) { |
mahphalke | 1:48914f9593f1 | 532 | bool channel_printed = false; |
mahphalke | 1:48914f9593f1 | 533 | |
mahphalke | 1:48914f9593f1 | 534 | for (uint8_t chn = 0; chn < NUMBER_OF_CHANNELS; chn++) { |
mahphalke | 1:48914f9593f1 | 535 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 536 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn); |
mahphalke | 1:48914f9593f1 | 537 | |
mahphalke | 1:48914f9593f1 | 538 | // if showing all channels, or channel is enabled |
mahphalke | 1:48914f9593f1 | 539 | if (device_chnmap_reg->value & AD717X_CHMAP_REG_CH_EN) { |
mahphalke | 1:48914f9593f1 | 540 | /* |
mahphalke | 1:48914f9593f1 | 541 | * add the comma before we output the next channel but |
mahphalke | 1:48914f9593f1 | 542 | * only if at least one channel has been printed |
mahphalke | 1:48914f9593f1 | 543 | */ |
mahphalke | 1:48914f9593f1 | 544 | if (channel_printed) { |
mahphalke | 1:48914f9593f1 | 545 | printf(", "); |
mahphalke | 1:48914f9593f1 | 546 | } |
mahphalke | 1:48914f9593f1 | 547 | printf("%d", chn); |
mahphalke | 1:48914f9593f1 | 548 | } |
mahphalke | 1:48914f9593f1 | 549 | channel_printed = true; |
mahphalke | 1:48914f9593f1 | 550 | } |
mahphalke | 1:48914f9593f1 | 551 | printf(EOL); |
mahphalke | 1:48914f9593f1 | 552 | } |
mahphalke | 1:48914f9593f1 | 553 | |
mahphalke | 1:48914f9593f1 | 554 | // Continuously read the channels, and store sample values |
mahphalke | 1:48914f9593f1 | 555 | while (was_escape_key_pressed() != true) { |
mahphalke | 1:48914f9593f1 | 556 | if (display_mode == DISPLAY_DATA_TABULAR) { |
mahphalke | 1:48914f9593f1 | 557 | adi_clear_console(); |
mahphalke | 1:48914f9593f1 | 558 | printf("Running continuous conversion mode...\r\nPress Escape to stop" EOL EOL); |
mahphalke | 1:48914f9593f1 | 559 | } |
mahphalke | 1:48914f9593f1 | 560 | |
mahphalke | 1:48914f9593f1 | 561 | /* |
mahphalke | 1:48914f9593f1 | 562 | * this polls the status register READY/ bit to determine when conversion is done |
mahphalke | 1:48914f9593f1 | 563 | * this also ensures the STATUS register value is up to date and contains the |
mahphalke | 1:48914f9593f1 | 564 | * channel that was sampled as well. |
mahphalke | 1:48914f9593f1 | 565 | * Generally, no need to read STATUS separately, but for faster sampling |
mahphalke | 1:48914f9593f1 | 566 | * enabling the DATA_STATUS bit means that status is appended to ADC data read |
mahphalke | 1:48914f9593f1 | 567 | * so the channel being sampled is read back (and updated) as part of the same frame |
mahphalke | 1:48914f9593f1 | 568 | */ |
mahphalke | 1:48914f9593f1 | 569 | if ((error_code = AD717X_WaitForReady(pad717x_dev, 10000)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 570 | printf("Error/Timeout waiting for conversion ready %ld" EOL EOL, error_code); |
mahphalke | 1:48914f9593f1 | 571 | continue; |
mahphalke | 1:48914f9593f1 | 572 | } |
mahphalke | 1:48914f9593f1 | 573 | |
mahphalke | 1:48914f9593f1 | 574 | if ((error_code = AD717X_ReadData(pad717x_dev, &sample_data)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 575 | printf("Error reading ADC Data (%ld)." EOL, error_code); |
mahphalke | 1:48914f9593f1 | 576 | continue; |
mahphalke | 1:48914f9593f1 | 577 | } |
mahphalke | 1:48914f9593f1 | 578 | |
mahphalke | 1:48914f9593f1 | 579 | /* |
mahphalke | 1:48914f9593f1 | 580 | * No error, need to process the sample, what channel has been read? update that channelSample |
mahphalke | 1:48914f9593f1 | 581 | */ |
mahphalke | 1:48914f9593f1 | 582 | device_status_reg = AD717X_GetReg(pad717x_dev, AD717X_STATUS_REG); |
mahphalke | 1:48914f9593f1 | 583 | uint8_t channelRead = device_status_reg->value & 0x0000000F; |
mahphalke | 1:48914f9593f1 | 584 | |
mahphalke | 1:48914f9593f1 | 585 | if (channelRead < NUMBER_OF_CHANNELS) { |
mahphalke | 1:48914f9593f1 | 586 | channel_samples[channelRead] = sample_data; |
mahphalke | 1:48914f9593f1 | 587 | channel_samples_count[channelRead]++; |
mahphalke | 1:48914f9593f1 | 588 | } else { |
mahphalke | 1:48914f9593f1 | 589 | printf("Channel Read was %d, which is not < %d" EOL, |
mahphalke | 1:48914f9593f1 | 590 | channelRead, |
mahphalke | 1:48914f9593f1 | 591 | NUMBER_OF_CHANNELS); |
mahphalke | 1:48914f9593f1 | 592 | } |
mahphalke | 1:48914f9593f1 | 593 | |
mahphalke | 1:48914f9593f1 | 594 | dislay_channel_samples(SHOW_ENABLED_CHANNELS, display_mode); |
mahphalke | 1:48914f9593f1 | 595 | } |
mahphalke | 1:48914f9593f1 | 596 | |
mahphalke | 1:48914f9593f1 | 597 | // All done, ADC put into standby mode |
mahphalke | 1:48914f9593f1 | 598 | device_mode_reg->value = |
mahphalke | 1:48914f9593f1 | 599 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 600 | AD717X_ADCMODE_REG_MODE(STANDBY_MODE)); |
mahphalke | 1:48914f9593f1 | 601 | |
mahphalke | 1:48914f9593f1 | 602 | if ((error_code = AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 603 | AD717X_ADCMODE_REG)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 604 | printf("Error (%ld) setting ADC into standby mode." EOL, error_code); |
mahphalke | 1:48914f9593f1 | 605 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 606 | } |
mahphalke | 1:48914f9593f1 | 607 | |
mahphalke | 1:48914f9593f1 | 608 | return (MENU_CONTINUE); |
mahphalke | 1:48914f9593f1 | 609 | } |
mahphalke | 1:48914f9593f1 | 610 | |
mahphalke | 1:48914f9593f1 | 611 | |
mahphalke | 1:48914f9593f1 | 612 | /*! |
mahphalke | 1:48914f9593f1 | 613 | * @brief Samples all enabled channels and displays in tabular form |
mahphalke | 1:48914f9593f1 | 614 | * |
mahphalke | 1:48914f9593f1 | 615 | * @details |
mahphalke | 1:48914f9593f1 | 616 | */ |
mahphalke | 1:48914f9593f1 | 617 | int32_t menu_continuous_conversion_tabular(uint32_t channel_id) |
mahphalke | 1:48914f9593f1 | 618 | { |
mahphalke | 1:48914f9593f1 | 619 | do_continuous_conversion(DISPLAY_DATA_TABULAR); |
mahphalke | 1:48914f9593f1 | 620 | |
mahphalke | 1:48914f9593f1 | 621 | adi_clear_console(); |
mahphalke | 1:48914f9593f1 | 622 | printf("Continuous Conversion completed..." EOL EOL); |
mahphalke | 1:48914f9593f1 | 623 | dislay_channel_samples(SHOW_ALL_CHANNELS, DISPLAY_DATA_TABULAR); |
mahphalke | 1:48914f9593f1 | 624 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 625 | |
mahphalke | 1:48914f9593f1 | 626 | return (MENU_CONTINUE); |
mahphalke | 1:48914f9593f1 | 627 | } |
mahphalke | 1:48914f9593f1 | 628 | |
mahphalke | 1:48914f9593f1 | 629 | |
mahphalke | 1:48914f9593f1 | 630 | /*! |
mahphalke | 1:48914f9593f1 | 631 | * @brief Samples all enabled channels and displays on the console |
mahphalke | 1:48914f9593f1 | 632 | * |
mahphalke | 1:48914f9593f1 | 633 | * @details |
mahphalke | 1:48914f9593f1 | 634 | */ |
mahphalke | 1:48914f9593f1 | 635 | int32_t menu_continuous_conversion_stream(uint32_t channel_id) |
mahphalke | 1:48914f9593f1 | 636 | { |
mahphalke | 1:48914f9593f1 | 637 | do_continuous_conversion(DISPLAY_DATA_STREAM); |
mahphalke | 1:48914f9593f1 | 638 | printf("Continuous Conversion completed..." EOL EOL); |
mahphalke | 1:48914f9593f1 | 639 | |
mahphalke | 1:48914f9593f1 | 640 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 641 | return (MENU_CONTINUE); |
mahphalke | 1:48914f9593f1 | 642 | } |
mahphalke | 1:48914f9593f1 | 643 | |
mahphalke | 1:48914f9593f1 | 644 | |
mahphalke | 1:48914f9593f1 | 645 | /*! |
mahphalke | 1:48914f9593f1 | 646 | * @brief Samples all enabled channels once in Single Conversion mode |
mahphalke | 1:48914f9593f1 | 647 | * |
mahphalke | 1:48914f9593f1 | 648 | * @details This stores all channels that are enabled in a bitmask, and then |
mahphalke | 1:48914f9593f1 | 649 | * runs the ADC in single conversion mode, which acquires one channel |
mahphalke | 1:48914f9593f1 | 650 | * of data at a time. After capture, that channel is disabled, and |
mahphalke | 1:48914f9593f1 | 651 | * single conversion run again, until no channels are enabled. |
mahphalke | 1:48914f9593f1 | 652 | * The original enable state of each channel is then restored. |
mahphalke | 1:48914f9593f1 | 653 | */ |
mahphalke | 1:48914f9593f1 | 654 | int32_t menu_single_conversion(uint32_t channel_id) |
mahphalke | 1:48914f9593f1 | 655 | { |
mahphalke | 1:48914f9593f1 | 656 | int32_t error_code; |
mahphalke | 1:48914f9593f1 | 657 | uint16_t channel_enable_mask = 0; |
mahphalke | 1:48914f9593f1 | 658 | uint8_t channel_count = 0; |
mahphalke | 1:48914f9593f1 | 659 | int32_t sample_data; |
mahphalke | 1:48914f9593f1 | 660 | ad717x_st_reg *device_chnmap_reg; |
mahphalke | 1:48914f9593f1 | 661 | ad717x_st_reg *device_mode_reg; |
mahphalke | 1:48914f9593f1 | 662 | ad717x_st_reg *device_status_reg; |
mahphalke | 1:48914f9593f1 | 663 | |
mahphalke | 1:48914f9593f1 | 664 | // Need to store which channels are enabled in this config so it can be restored |
mahphalke | 1:48914f9593f1 | 665 | for (uint8_t chn = 0 ; chn < NUMBER_OF_CHANNELS; chn++) { |
mahphalke | 1:48914f9593f1 | 666 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 667 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn); |
mahphalke | 1:48914f9593f1 | 668 | |
mahphalke | 1:48914f9593f1 | 669 | if (device_chnmap_reg->value & AD717X_CHMAP_REG_CH_EN) { |
mahphalke | 1:48914f9593f1 | 670 | channel_enable_mask |= (1 << chn); |
mahphalke | 1:48914f9593f1 | 671 | channel_count++; |
mahphalke | 1:48914f9593f1 | 672 | } |
mahphalke | 1:48914f9593f1 | 673 | } |
mahphalke | 1:48914f9593f1 | 674 | |
mahphalke | 1:48914f9593f1 | 675 | clear_channel_samples(); |
mahphalke | 1:48914f9593f1 | 676 | |
mahphalke | 1:48914f9593f1 | 677 | adi_clear_console(); |
mahphalke | 1:48914f9593f1 | 678 | printf("Running Single conversion mode...\r\nPress Escape to stop" EOL EOL); |
mahphalke | 1:48914f9593f1 | 679 | |
mahphalke | 1:48914f9593f1 | 680 | // Get the pointer to mode register |
mahphalke | 1:48914f9593f1 | 681 | device_mode_reg = AD717X_GetReg(pad717x_dev, AD717X_ADCMODE_REG); |
mahphalke | 1:48914f9593f1 | 682 | |
mahphalke | 1:48914f9593f1 | 683 | // Clear the ADC CTRL MODE bits, selecting continuous mode |
mahphalke | 1:48914f9593f1 | 684 | device_mode_reg->value = |
mahphalke | 1:48914f9593f1 | 685 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 686 | AD717X_ADCMODE_REG_MODE(CONTINUOUS_CONVERSION)); |
mahphalke | 1:48914f9593f1 | 687 | |
mahphalke | 1:48914f9593f1 | 688 | // read the channels, and store sample values |
mahphalke | 1:48914f9593f1 | 689 | for(uint8_t loopCount = 0 ; ((was_escape_key_pressed() != true) |
mahphalke | 1:48914f9593f1 | 690 | && (loopCount < channel_count)) ; loopCount++) { |
mahphalke | 1:48914f9593f1 | 691 | |
mahphalke | 1:48914f9593f1 | 692 | device_mode_reg->value = |
mahphalke | 1:48914f9593f1 | 693 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 694 | AD717X_ADCMODE_REG_MODE(SINGLE_CONVERISION)); |
mahphalke | 1:48914f9593f1 | 695 | |
mahphalke | 1:48914f9593f1 | 696 | if ((error_code = AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 697 | AD717X_ADCMODE_REG)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 698 | printf("Error (%ld) setting AD717x Single conversion mode." EOL, error_code); |
mahphalke | 1:48914f9593f1 | 699 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 700 | continue; |
mahphalke | 1:48914f9593f1 | 701 | } |
mahphalke | 1:48914f9593f1 | 702 | |
mahphalke | 1:48914f9593f1 | 703 | /* |
mahphalke | 1:48914f9593f1 | 704 | * this polls the status register READY/ bit to determine when conversion is done |
mahphalke | 1:48914f9593f1 | 705 | * this also ensures the STATUS register value is up to date and contains the |
mahphalke | 1:48914f9593f1 | 706 | * channel that was sampled as well. No need to read STATUS separately |
mahphalke | 1:48914f9593f1 | 707 | */ |
mahphalke | 1:48914f9593f1 | 708 | if ((error_code = AD717X_WaitForReady(pad717x_dev, 10000)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 709 | printf("Error/Timeout waiting for conversion ready %ld" EOL, error_code); |
mahphalke | 1:48914f9593f1 | 710 | continue; |
mahphalke | 1:48914f9593f1 | 711 | } |
mahphalke | 1:48914f9593f1 | 712 | |
mahphalke | 1:48914f9593f1 | 713 | if ((error_code = AD717X_ReadData(pad717x_dev, &sample_data)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 714 | printf("Error reading ADC Data (%ld)." EOL, error_code); |
mahphalke | 1:48914f9593f1 | 715 | continue; |
mahphalke | 1:48914f9593f1 | 716 | } |
mahphalke | 1:48914f9593f1 | 717 | |
mahphalke | 1:48914f9593f1 | 718 | /* |
mahphalke | 1:48914f9593f1 | 719 | * No error, need to process the sample, what channel has been read? update that channelSample |
mahphalke | 1:48914f9593f1 | 720 | */ |
mahphalke | 1:48914f9593f1 | 721 | device_status_reg = AD717X_GetReg(pad717x_dev, AD717X_STATUS_REG); |
mahphalke | 1:48914f9593f1 | 722 | uint8_t channelRead = device_status_reg->value & 0x0000000F; |
mahphalke | 1:48914f9593f1 | 723 | |
mahphalke | 1:48914f9593f1 | 724 | if (channelRead < NUMBER_OF_CHANNELS) { |
mahphalke | 1:48914f9593f1 | 725 | channel_samples[channelRead] = sample_data; |
mahphalke | 1:48914f9593f1 | 726 | channel_samples_count[channelRead]++; |
mahphalke | 1:48914f9593f1 | 727 | |
mahphalke | 1:48914f9593f1 | 728 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 729 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + channelRead); |
mahphalke | 1:48914f9593f1 | 730 | |
mahphalke | 1:48914f9593f1 | 731 | /* also need to clear the channel enable bit so the next single conversion cycle will sample the next channel */ |
mahphalke | 1:48914f9593f1 | 732 | device_chnmap_reg->value &= (~AD717X_CHMAP_REG_CH_EN); |
mahphalke | 1:48914f9593f1 | 733 | if ((error_code = AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 734 | AD717X_CHMAP0_REG + channelRead)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 735 | printf("Error (%ld) Clearing channel %d Enable bit." EOL, |
mahphalke | 1:48914f9593f1 | 736 | error_code, |
mahphalke | 1:48914f9593f1 | 737 | channelRead); |
mahphalke | 1:48914f9593f1 | 738 | |
mahphalke | 1:48914f9593f1 | 739 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 740 | continue; |
mahphalke | 1:48914f9593f1 | 741 | } |
mahphalke | 1:48914f9593f1 | 742 | } else { |
mahphalke | 1:48914f9593f1 | 743 | printf("Channel Read was %d, which is not < AD717x_CHANNEL_COUNT" EOL, |
mahphalke | 1:48914f9593f1 | 744 | channelRead); |
mahphalke | 1:48914f9593f1 | 745 | } |
mahphalke | 1:48914f9593f1 | 746 | } |
mahphalke | 1:48914f9593f1 | 747 | |
mahphalke | 1:48914f9593f1 | 748 | // All done, ADC put into standby mode |
mahphalke | 1:48914f9593f1 | 749 | device_mode_reg->value = |
mahphalke | 1:48914f9593f1 | 750 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 751 | AD717X_ADCMODE_REG_MODE(STANDBY_MODE)); |
mahphalke | 1:48914f9593f1 | 752 | |
mahphalke | 1:48914f9593f1 | 753 | // Need to restore the channels that were disabled during acquisition |
mahphalke | 1:48914f9593f1 | 754 | for(uint8_t chn = 0 ; chn < NUMBER_OF_CHANNELS ; chn++) { |
mahphalke | 1:48914f9593f1 | 755 | if (channel_enable_mask & (1 << chn)) { |
mahphalke | 1:48914f9593f1 | 756 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 757 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn); |
mahphalke | 1:48914f9593f1 | 758 | |
mahphalke | 1:48914f9593f1 | 759 | device_chnmap_reg->value |= AD717X_CHMAP_REG_CH_EN; |
mahphalke | 1:48914f9593f1 | 760 | |
mahphalke | 1:48914f9593f1 | 761 | if ((error_code = AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 762 | AD717X_CHMAP0_REG + chn)) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 763 | printf("Error (%ld) Setting channel %d Enable bit" EOL EOL, error_code, chn); |
mahphalke | 1:48914f9593f1 | 764 | |
mahphalke | 1:48914f9593f1 | 765 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 766 | return (MENU_CONTINUE); |
mahphalke | 1:48914f9593f1 | 767 | } |
mahphalke | 1:48914f9593f1 | 768 | } |
mahphalke | 1:48914f9593f1 | 769 | } |
mahphalke | 1:48914f9593f1 | 770 | |
mahphalke | 1:48914f9593f1 | 771 | printf("Single Conversion completed..." EOL EOL); |
mahphalke | 1:48914f9593f1 | 772 | dislay_channel_samples(SHOW_ENABLED_CHANNELS, DISPLAY_DATA_TABULAR); |
mahphalke | 1:48914f9593f1 | 773 | |
mahphalke | 1:48914f9593f1 | 774 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 775 | return (MENU_CONTINUE); |
mahphalke | 1:48914f9593f1 | 776 | } |
mahphalke | 1:48914f9593f1 | 777 | |
mahphalke | 1:48914f9593f1 | 778 | |
mahphalke | 1:48914f9593f1 | 779 | /*! |
mahphalke | 1:48914f9593f1 | 780 | * @brief Handle the menu to sample the channels |
mahphalke | 3:6c7324997606 | 781 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 782 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 783 | */ |
mahphalke | 1:48914f9593f1 | 784 | int32_t menu_sample_channels(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 785 | { |
mahphalke | 1:48914f9593f1 | 786 | return adi_do_console_menu(&acquisition_menu); |
mahphalke | 1:48914f9593f1 | 787 | } |
mahphalke | 1:48914f9593f1 | 788 | |
mahphalke | 1:48914f9593f1 | 789 | |
mahphalke | 1:48914f9593f1 | 790 | /* @brief Enable or disable adc channels |
mahphalke | 3:6c7324997606 | 791 | * @param channel ENABLE/DISABLE action |
mahphalke | 1:48914f9593f1 | 792 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 793 | **/ |
mahphalke | 1:48914f9593f1 | 794 | int32_t menu_channels_enable_disable(uint32_t action) |
mahphalke | 1:48914f9593f1 | 795 | { |
mahphalke | 1:48914f9593f1 | 796 | char rx_char; // received character from the serial port |
mahphalke | 1:48914f9593f1 | 797 | uint8_t current_channel; // channel to be enabled |
mahphalke | 1:48914f9593f1 | 798 | ad717x_st_reg *device_chnmap_reg; // Pointer to channel map register |
mahphalke | 1:48914f9593f1 | 799 | |
mahphalke | 1:48914f9593f1 | 800 | do { |
mahphalke | 1:48914f9593f1 | 801 | // Get the channel selection |
mahphalke | 1:48914f9593f1 | 802 | current_channel = get_channel_selection(); |
mahphalke | 1:48914f9593f1 | 803 | |
mahphalke | 1:48914f9593f1 | 804 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 805 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 806 | AD717X_CHMAP0_REG + current_channel); |
mahphalke | 1:48914f9593f1 | 807 | |
mahphalke | 1:48914f9593f1 | 808 | if (action == SELECT_ENABLE) { |
mahphalke | 1:48914f9593f1 | 809 | // Enable the selected channel |
mahphalke | 1:48914f9593f1 | 810 | device_chnmap_reg->value |= AD717X_CHMAP_REG_CH_EN; |
mahphalke | 1:48914f9593f1 | 811 | printf("\tChannel %d is Enabled ", current_channel); |
mahphalke | 1:48914f9593f1 | 812 | } else { |
mahphalke | 1:48914f9593f1 | 813 | // Disable the selected channel |
mahphalke | 1:48914f9593f1 | 814 | device_chnmap_reg->value &= (~AD717X_CHMAP_REG_CH_EN); |
mahphalke | 1:48914f9593f1 | 815 | printf("\tChannel %d is Disabled ", current_channel); |
mahphalke | 1:48914f9593f1 | 816 | } |
mahphalke | 1:48914f9593f1 | 817 | |
mahphalke | 1:48914f9593f1 | 818 | // Write to ADC channel register |
mahphalke | 1:48914f9593f1 | 819 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 820 | AD717X_CHMAP0_REG + current_channel) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 821 | printf("\tError in channel Enable/Disable!!" EOL); |
mahphalke | 1:48914f9593f1 | 822 | break; |
mahphalke | 1:48914f9593f1 | 823 | } |
mahphalke | 1:48914f9593f1 | 824 | |
mahphalke | 1:48914f9593f1 | 825 | printf(EOL EOL "\tDo you want to continue (y/n)?: "); |
mahphalke | 1:48914f9593f1 | 826 | rx_char = toupper(getchar()); |
mahphalke | 1:48914f9593f1 | 827 | |
mahphalke | 1:48914f9593f1 | 828 | if ((rx_char != 'N') && (rx_char != 'Y')) { |
mahphalke | 1:48914f9593f1 | 829 | printf("Invalid entry!!" EOL); |
mahphalke | 1:48914f9593f1 | 830 | } else { |
mahphalke | 1:48914f9593f1 | 831 | // Print the entered character back on console window (serial port) |
mahphalke | 1:48914f9593f1 | 832 | printf("%c" EOL, rx_char); |
mahphalke | 1:48914f9593f1 | 833 | } |
mahphalke | 1:48914f9593f1 | 834 | } while (rx_char != 'N'); |
mahphalke | 1:48914f9593f1 | 835 | |
mahphalke | 1:48914f9593f1 | 836 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 837 | } |
mahphalke | 1:48914f9593f1 | 838 | |
mahphalke | 1:48914f9593f1 | 839 | |
mahphalke | 1:48914f9593f1 | 840 | /*! |
mahphalke | 1:48914f9593f1 | 841 | * @brief Display the menu to enable/disable channel selection |
mahphalke | 3:6c7324997606 | 842 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 843 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 844 | */ |
mahphalke | 1:48914f9593f1 | 845 | int32_t menu_chn_enable_disable_display(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 846 | { |
mahphalke | 1:48914f9593f1 | 847 | return adi_do_console_menu(&chn_enable_disable_menu); |
mahphalke | 1:48914f9593f1 | 848 | } |
mahphalke | 1:48914f9593f1 | 849 | |
mahphalke | 1:48914f9593f1 | 850 | |
mahphalke | 1:48914f9593f1 | 851 | /*! |
mahphalke | 1:48914f9593f1 | 852 | * @brief Handle the menu to connect input to channel |
mahphalke | 3:6c7324997606 | 853 | * @param analog input to be connected |
mahphalke | 1:48914f9593f1 | 854 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 855 | */ |
mahphalke | 1:48914f9593f1 | 856 | int32_t menu_analog_input_connect(uint32_t user_analog_input) |
mahphalke | 1:48914f9593f1 | 857 | { |
mahphalke | 1:48914f9593f1 | 858 | uint8_t current_channel; // current channel |
mahphalke | 1:48914f9593f1 | 859 | ad717x_st_reg *device_chnmap_reg; // Pointer to channel map register |
mahphalke | 1:48914f9593f1 | 860 | |
mahphalke | 1:48914f9593f1 | 861 | adi_clear_console(); |
mahphalke | 1:48914f9593f1 | 862 | |
mahphalke | 1:48914f9593f1 | 863 | // Get the channel selection |
mahphalke | 1:48914f9593f1 | 864 | current_channel = get_channel_selection(); |
mahphalke | 1:48914f9593f1 | 865 | |
mahphalke | 1:48914f9593f1 | 866 | if (input_to_select == POS_ANALOG_INP_SELECT) { |
mahphalke | 1:48914f9593f1 | 867 | printf(EOL "\tSelect Positive Analog Input" EOL); |
mahphalke | 1:48914f9593f1 | 868 | device_setup.pos_analog_input = user_analog_input; |
mahphalke | 1:48914f9593f1 | 869 | } else if (input_to_select == NEG_ANALOG_INP_SELECT) { |
mahphalke | 1:48914f9593f1 | 870 | printf(EOL "\tSelect Negative Analog Input" EOL); |
mahphalke | 1:48914f9593f1 | 871 | device_setup.neg_analog_input = user_analog_input; |
mahphalke | 1:48914f9593f1 | 872 | } else { |
mahphalke | 1:48914f9593f1 | 873 | device_setup.pos_analog_input = AD717X_CHMAP_REG_AINPOS_RD(user_analog_input); |
mahphalke | 1:48914f9593f1 | 874 | device_setup.neg_analog_input = AD717X_CHMAP_REG_AINNEG_RD(user_analog_input); |
mahphalke | 1:48914f9593f1 | 875 | } |
mahphalke | 1:48914f9593f1 | 876 | |
mahphalke | 1:48914f9593f1 | 877 | // Get the pointer to channel map register structure |
mahphalke | 1:48914f9593f1 | 878 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 879 | AD717X_CHMAP0_REG + current_channel); |
mahphalke | 1:48914f9593f1 | 880 | |
Mahesh Phalke |
4:4592cc69bfa6 | 881 | #if defined(DEV_AD4111) || defined(DEV_AD4112) || defined(DEV_AD4114) || \ |
Mahesh Phalke |
4:4592cc69bfa6 | 882 | defined(DEV_AD4115) |
mahphalke | 1:48914f9593f1 | 883 | // Select analog input pair |
mahphalke | 1:48914f9593f1 | 884 | device_chnmap_reg->value = |
mahphalke | 1:48914f9593f1 | 885 | ((device_chnmap_reg->value & ~AD4111_CHMAP_REG_INPUT_MSK) | |
mahphalke | 1:48914f9593f1 | 886 | AD4111_CHMAP_REG_INPUT(user_analog_input)); |
mahphalke | 1:48914f9593f1 | 887 | #elif |
mahphalke | 1:48914f9593f1 | 888 | // Select positive analog input |
mahphalke | 1:48914f9593f1 | 889 | device_chnmap_reg->value = |
mahphalke | 1:48914f9593f1 | 890 | ((device_chnmap_reg->value & ~AD717X_CHMAP_REG_AINPOS_MSK) | |
mahphalke | 1:48914f9593f1 | 891 | AD717X_CHMAP_REG_AINPOS(device_setup.pos_analog_input)); |
mahphalke | 1:48914f9593f1 | 892 | |
mahphalke | 1:48914f9593f1 | 893 | // Select negative analog input |
mahphalke | 1:48914f9593f1 | 894 | device_chnmap_reg->value = |
mahphalke | 1:48914f9593f1 | 895 | ((device_chnmap_reg->value & ~AD717X_CHMAP_REG_AINNEG_MSK) | |
mahphalke | 1:48914f9593f1 | 896 | AD717X_CHMAP_REG_AINNEG(device_setup.neg_analog_input)); |
mahphalke | 1:48914f9593f1 | 897 | #endif |
mahphalke | 1:48914f9593f1 | 898 | |
mahphalke | 1:48914f9593f1 | 899 | // Write to ADC channel register |
mahphalke | 1:48914f9593f1 | 900 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 901 | AD717X_CHMAP0_REG + current_channel) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 902 | printf(EOL "\tError in analog input connection!!" EOL); |
mahphalke | 1:48914f9593f1 | 903 | } else { |
mahphalke | 1:48914f9593f1 | 904 | printf(EOL "\t%s is connected to INP+ and %s is connectd to INP- for channel %d" |
mahphalke | 1:48914f9593f1 | 905 | EOL |
mahphalke | 1:48914f9593f1 | 906 | EOL, |
mahphalke | 1:48914f9593f1 | 907 | input_pin_map[device_setup.pos_analog_input], |
mahphalke | 1:48914f9593f1 | 908 | input_pin_map[device_setup.neg_analog_input], |
mahphalke | 1:48914f9593f1 | 909 | current_channel); |
mahphalke | 1:48914f9593f1 | 910 | } |
mahphalke | 1:48914f9593f1 | 911 | |
mahphalke | 1:48914f9593f1 | 912 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 913 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 914 | } |
mahphalke | 1:48914f9593f1 | 915 | |
mahphalke | 1:48914f9593f1 | 916 | |
mahphalke | 1:48914f9593f1 | 917 | /*! |
mahphalke | 1:48914f9593f1 | 918 | * @brief Display the menu selections to connect analog input pins to a channel |
mahphalke | 3:6c7324997606 | 919 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 920 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 921 | */ |
mahphalke | 1:48914f9593f1 | 922 | int32_t menu_input_chn_connect_display(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 923 | { |
Mahesh Phalke |
4:4592cc69bfa6 | 924 | #if defined(DEV_AD4111) || defined(DEV_AD4112) || defined(DEV_AD4114) || \ |
Mahesh Phalke |
4:4592cc69bfa6 | 925 | defined(DEV_AD4115) |
mahphalke | 1:48914f9593f1 | 926 | input_to_select = ANALOG_INP_PAIR_SELECT; |
mahphalke | 1:48914f9593f1 | 927 | adi_do_console_menu(&analog_input_connect_menu); |
mahphalke | 1:48914f9593f1 | 928 | #else |
mahphalke | 1:48914f9593f1 | 929 | input_to_select = POS_ANALOG_INP_SELECT; |
mahphalke | 1:48914f9593f1 | 930 | adi_do_console_menu(&analog_input_connect_menu); |
mahphalke | 1:48914f9593f1 | 931 | |
mahphalke | 1:48914f9593f1 | 932 | input_to_select = NEG_ANALOG_INP_SELECT; |
mahphalke | 1:48914f9593f1 | 933 | adi_do_console_menu(&analog_input_connect_menu); |
mahphalke | 1:48914f9593f1 | 934 | #endif |
mahphalke | 1:48914f9593f1 | 935 | |
mahphalke | 1:48914f9593f1 | 936 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 937 | } |
mahphalke | 1:48914f9593f1 | 938 | |
mahphalke | 1:48914f9593f1 | 939 | |
mahphalke | 1:48914f9593f1 | 940 | /*! |
mahphalke | 1:48914f9593f1 | 941 | * @brief Handle the menu to select the filter type |
mahphalke | 3:6c7324997606 | 942 | * @param user selected filter type |
mahphalke | 1:48914f9593f1 | 943 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 944 | */ |
mahphalke | 1:48914f9593f1 | 945 | int32_t menu_filter_select(uint32_t user_input_filter_type) |
mahphalke | 1:48914f9593f1 | 946 | { |
mahphalke | 1:48914f9593f1 | 947 | ad717x_st_reg *device_filter_config_reg; // Pointer to filter config register |
mahphalke | 1:48914f9593f1 | 948 | |
mahphalke | 1:48914f9593f1 | 949 | // Get the pointer to filter config register structure |
mahphalke | 1:48914f9593f1 | 950 | device_filter_config_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 951 | AD717X_FILTCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 952 | |
mahphalke | 1:48914f9593f1 | 953 | device_setup.filter = user_input_filter_type; |
mahphalke | 1:48914f9593f1 | 954 | |
mahphalke | 1:48914f9593f1 | 955 | device_filter_config_reg->value = |
mahphalke | 1:48914f9593f1 | 956 | ((device_filter_config_reg->value & ~AD717X_FILT_CONF_REG_ORDER_MSK) | |
mahphalke | 1:48914f9593f1 | 957 | AD717X_FILT_CONF_REG_ORDER(device_setup.filter)); |
mahphalke | 1:48914f9593f1 | 958 | |
mahphalke | 1:48914f9593f1 | 959 | if (device_setup.filter == SINC3_FILTER) { |
mahphalke | 1:48914f9593f1 | 960 | device_filter_config_reg->value |= AD717X_FILT_CONF_REG_SINC3_MAP; |
mahphalke | 1:48914f9593f1 | 961 | } else { |
mahphalke | 1:48914f9593f1 | 962 | device_filter_config_reg->value &= (~AD717X_FILT_CONF_REG_SINC3_MAP); |
mahphalke | 1:48914f9593f1 | 963 | } |
mahphalke | 1:48914f9593f1 | 964 | |
mahphalke | 1:48914f9593f1 | 965 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 966 | AD717X_FILTCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 967 | printf(EOL "\tError in Filter Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 968 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 969 | } |
mahphalke | 1:48914f9593f1 | 970 | |
mahphalke | 1:48914f9593f1 | 971 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 972 | } |
mahphalke | 1:48914f9593f1 | 973 | |
mahphalke | 1:48914f9593f1 | 974 | |
mahphalke | 1:48914f9593f1 | 975 | /*! |
mahphalke | 1:48914f9593f1 | 976 | * @brief Handle the menu to enable/disable the post filter |
mahphalke | 3:6c7324997606 | 977 | * @param user selected action |
mahphalke | 1:48914f9593f1 | 978 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 979 | */ |
mahphalke | 1:48914f9593f1 | 980 | int32_t menu_postfiler_enable_disable(uint32_t user_action) |
mahphalke | 1:48914f9593f1 | 981 | { |
mahphalke | 1:48914f9593f1 | 982 | ad717x_st_reg *device_filter_config_reg; // Pointer to filter config register |
mahphalke | 1:48914f9593f1 | 983 | |
mahphalke | 1:48914f9593f1 | 984 | // Get the pointer to filter config register structure |
mahphalke | 1:48914f9593f1 | 985 | device_filter_config_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 986 | AD717X_FILTCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 987 | |
mahphalke | 1:48914f9593f1 | 988 | if (user_action == SELECT_ENABLE) { |
mahphalke | 1:48914f9593f1 | 989 | device_setup.post_filter_enabled = SELECT_ENABLE; |
mahphalke | 1:48914f9593f1 | 990 | device_filter_config_reg->value |= AD717X_FILT_CONF_REG_ENHFILTEN; |
mahphalke | 1:48914f9593f1 | 991 | } else { |
mahphalke | 1:48914f9593f1 | 992 | device_setup.post_filter_enabled = SELECT_DISBLE; |
mahphalke | 1:48914f9593f1 | 993 | device_filter_config_reg->value &= (~AD717X_FILT_CONF_REG_ENHFILTEN); |
mahphalke | 1:48914f9593f1 | 994 | } |
mahphalke | 1:48914f9593f1 | 995 | |
mahphalke | 1:48914f9593f1 | 996 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 997 | AD717X_FILTCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 998 | printf(EOL "\tError in Enabling/Disabling Postfilter!!" EOL); |
mahphalke | 1:48914f9593f1 | 999 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1000 | } |
mahphalke | 1:48914f9593f1 | 1001 | |
mahphalke | 1:48914f9593f1 | 1002 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 1003 | } |
mahphalke | 1:48914f9593f1 | 1004 | |
mahphalke | 1:48914f9593f1 | 1005 | |
mahphalke | 1:48914f9593f1 | 1006 | /*! |
mahphalke | 1:48914f9593f1 | 1007 | * @brief Handle the menu to select the post filter |
mahphalke | 3:6c7324997606 | 1008 | * @param user selected post filter type |
mahphalke | 1:48914f9593f1 | 1009 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 1010 | */ |
mahphalke | 1:48914f9593f1 | 1011 | int32_t menu_postfiler_select(uint32_t user_input_post_filter_type) |
mahphalke | 1:48914f9593f1 | 1012 | { |
mahphalke | 1:48914f9593f1 | 1013 | ad717x_st_reg *device_filter_config_reg; // Pointer to filter config register |
mahphalke | 1:48914f9593f1 | 1014 | |
mahphalke | 1:48914f9593f1 | 1015 | // Get the pointer to filter config register structure |
mahphalke | 1:48914f9593f1 | 1016 | device_filter_config_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1017 | AD717X_FILTCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 1018 | |
mahphalke | 1:48914f9593f1 | 1019 | device_setup.postfilter = user_input_post_filter_type; |
mahphalke | 1:48914f9593f1 | 1020 | |
mahphalke | 1:48914f9593f1 | 1021 | device_filter_config_reg->value = |
mahphalke | 1:48914f9593f1 | 1022 | ((device_filter_config_reg->value & ~AD717X_FILT_CONF_REG_ENHFILT_MSK) | |
mahphalke | 1:48914f9593f1 | 1023 | AD717X_FILT_CONF_REG_ENHFILT(device_setup.postfilter)); |
mahphalke | 1:48914f9593f1 | 1024 | |
mahphalke | 1:48914f9593f1 | 1025 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1026 | AD717X_FILTCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1027 | printf(EOL "\tError in Post-Filter Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 1028 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1029 | } |
mahphalke | 1:48914f9593f1 | 1030 | |
mahphalke | 1:48914f9593f1 | 1031 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 1032 | } |
mahphalke | 1:48914f9593f1 | 1033 | |
mahphalke | 1:48914f9593f1 | 1034 | |
mahphalke | 1:48914f9593f1 | 1035 | /*! |
mahphalke | 1:48914f9593f1 | 1036 | * @brief Handle the menu to select the ODR value |
mahphalke | 3:6c7324997606 | 1037 | * @param user selected ODR |
mahphalke | 1:48914f9593f1 | 1038 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 1039 | */ |
mahphalke | 1:48914f9593f1 | 1040 | int32_t menu_odr_select(uint32_t user_input_odr_val) |
mahphalke | 1:48914f9593f1 | 1041 | { |
mahphalke | 1:48914f9593f1 | 1042 | ad717x_st_reg *device_filter_config_reg; // Pointer to filter config register |
mahphalke | 1:48914f9593f1 | 1043 | |
mahphalke | 1:48914f9593f1 | 1044 | // Get the pointer to filter config register structure |
mahphalke | 1:48914f9593f1 | 1045 | device_filter_config_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1046 | AD717X_FILTCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 1047 | |
mahphalke | 1:48914f9593f1 | 1048 | device_setup.odr_bits = user_input_odr_val; |
mahphalke | 1:48914f9593f1 | 1049 | |
mahphalke | 1:48914f9593f1 | 1050 | device_filter_config_reg->value = |
mahphalke | 1:48914f9593f1 | 1051 | ((device_filter_config_reg->value & ~AD717X_FILT_CONF_REG_ODR_MSK) | |
mahphalke | 1:48914f9593f1 | 1052 | AD717X_FILT_CONF_REG_ODR(device_setup.odr_bits)); |
mahphalke | 1:48914f9593f1 | 1053 | |
mahphalke | 1:48914f9593f1 | 1054 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1055 | AD717X_FILTCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1056 | printf(EOL "\tError in ODR Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 1057 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1058 | } |
mahphalke | 1:48914f9593f1 | 1059 | |
mahphalke | 1:48914f9593f1 | 1060 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 1061 | } |
mahphalke | 1:48914f9593f1 | 1062 | |
mahphalke | 1:48914f9593f1 | 1063 | |
mahphalke | 1:48914f9593f1 | 1064 | /*! |
mahphalke | 1:48914f9593f1 | 1065 | * @brief Handle the menu to select the polarity |
mahphalke | 3:6c7324997606 | 1066 | * @param user selected polarity |
mahphalke | 1:48914f9593f1 | 1067 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 1068 | */ |
mahphalke | 1:48914f9593f1 | 1069 | int32_t menu_polarity_select(uint32_t user_input_polarity) |
mahphalke | 1:48914f9593f1 | 1070 | { |
mahphalke | 1:48914f9593f1 | 1071 | ad717x_st_reg *device_setup_control_reg; // Pointer to setup control register |
mahphalke | 1:48914f9593f1 | 1072 | |
mahphalke | 1:48914f9593f1 | 1073 | // Get the pointer to setup control register structure |
mahphalke | 1:48914f9593f1 | 1074 | device_setup_control_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1075 | AD717X_SETUPCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 1076 | |
mahphalke | 1:48914f9593f1 | 1077 | if (user_input_polarity == BIPOLAR) { |
mahphalke | 1:48914f9593f1 | 1078 | device_setup.polarity = BIPOLAR; |
mahphalke | 1:48914f9593f1 | 1079 | device_setup_control_reg->value |= AD717X_SETUP_CONF_REG_BI_UNIPOLAR; |
mahphalke | 1:48914f9593f1 | 1080 | } else { |
mahphalke | 1:48914f9593f1 | 1081 | device_setup.polarity = UNIPOLAR; |
mahphalke | 1:48914f9593f1 | 1082 | device_setup_control_reg->value &= (~AD717X_SETUP_CONF_REG_BI_UNIPOLAR); |
mahphalke | 1:48914f9593f1 | 1083 | } |
mahphalke | 1:48914f9593f1 | 1084 | |
mahphalke | 1:48914f9593f1 | 1085 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1086 | AD717X_SETUPCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1087 | printf(EOL "\tError in Polarity Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 1088 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1089 | } |
mahphalke | 1:48914f9593f1 | 1090 | |
mahphalke | 1:48914f9593f1 | 1091 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 1092 | } |
mahphalke | 1:48914f9593f1 | 1093 | |
mahphalke | 1:48914f9593f1 | 1094 | |
mahphalke | 1:48914f9593f1 | 1095 | /*! |
mahphalke | 1:48914f9593f1 | 1096 | * @brief Handle the menu to select the reference source |
mahphalke | 3:6c7324997606 | 1097 | * @param user selected reference source |
mahphalke | 1:48914f9593f1 | 1098 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 1099 | */ |
mahphalke | 1:48914f9593f1 | 1100 | int32_t menu_reference_source_select(uint32_t user_input_reference) |
mahphalke | 1:48914f9593f1 | 1101 | { |
mahphalke | 1:48914f9593f1 | 1102 | ad717x_st_reg *device_setup_control_reg; // Pointer to setup control register |
mahphalke | 1:48914f9593f1 | 1103 | ad717x_st_reg *device_mode_reg; // Pointer to adc mode register |
mahphalke | 1:48914f9593f1 | 1104 | |
mahphalke | 1:48914f9593f1 | 1105 | device_setup.reference = user_input_reference; |
mahphalke | 1:48914f9593f1 | 1106 | |
mahphalke | 1:48914f9593f1 | 1107 | // Get the pointer to device mode register structure |
mahphalke | 1:48914f9593f1 | 1108 | device_mode_reg = AD717X_GetReg(pad717x_dev, AD717X_ADCMODE_REG); |
mahphalke | 1:48914f9593f1 | 1109 | |
mahphalke | 1:48914f9593f1 | 1110 | if (device_setup.reference == INTERNAL) { |
mahphalke | 1:48914f9593f1 | 1111 | device_mode_reg->value |= AD717X_ADCMODE_REG_REF_EN; |
mahphalke | 1:48914f9593f1 | 1112 | } else { |
mahphalke | 1:48914f9593f1 | 1113 | device_mode_reg->value &= (~AD717X_ADCMODE_REG_REF_EN); |
mahphalke | 1:48914f9593f1 | 1114 | } |
mahphalke | 1:48914f9593f1 | 1115 | |
mahphalke | 1:48914f9593f1 | 1116 | if (AD717X_WriteRegister(pad717x_dev, AD717X_ADCMODE_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1117 | printf(EOL "\tError in Polarity Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 1118 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1119 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1120 | } |
mahphalke | 1:48914f9593f1 | 1121 | |
mahphalke | 1:48914f9593f1 | 1122 | // Get the pointer to setup control register structure |
mahphalke | 1:48914f9593f1 | 1123 | device_setup_control_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1124 | AD717X_SETUPCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 1125 | |
mahphalke | 1:48914f9593f1 | 1126 | device_setup_control_reg->value = |
mahphalke | 1:48914f9593f1 | 1127 | ((device_setup_control_reg->value & ~AD717X_SETUP_CONF_REG_REF_SEL_MSK) | |
mahphalke | 1:48914f9593f1 | 1128 | AD717X_SETUP_CONF_REG_REF_SEL(device_setup.reference)); |
mahphalke | 1:48914f9593f1 | 1129 | |
mahphalke | 1:48914f9593f1 | 1130 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1131 | AD717X_SETUPCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1132 | printf(EOL "\tError in Polarity Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 1133 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1134 | } |
mahphalke | 1:48914f9593f1 | 1135 | |
mahphalke | 1:48914f9593f1 | 1136 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 1137 | } |
mahphalke | 1:48914f9593f1 | 1138 | |
mahphalke | 1:48914f9593f1 | 1139 | |
mahphalke | 1:48914f9593f1 | 1140 | /*! |
mahphalke | 1:48914f9593f1 | 1141 | * @brief Handle the menu to enable/disable the reference buffers |
mahphalke | 3:6c7324997606 | 1142 | * @param user selected action |
mahphalke | 1:48914f9593f1 | 1143 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 1144 | */ |
mahphalke | 1:48914f9593f1 | 1145 | int32_t menu_ref_buffer_enable_disable(uint32_t user_action) |
mahphalke | 1:48914f9593f1 | 1146 | { |
mahphalke | 1:48914f9593f1 | 1147 | ad717x_st_reg *device_setup_control_reg; // Pointer to setup control register |
mahphalke | 1:48914f9593f1 | 1148 | |
mahphalke | 1:48914f9593f1 | 1149 | // Get the pointer to setup control register structure |
mahphalke | 1:48914f9593f1 | 1150 | device_setup_control_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1151 | AD717X_SETUPCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 1152 | |
mahphalke | 1:48914f9593f1 | 1153 | device_setup.reference_buffers = user_action; |
mahphalke | 1:48914f9593f1 | 1154 | |
mahphalke | 1:48914f9593f1 | 1155 | if (user_action == SELECT_ENABLE) { |
mahphalke | 1:48914f9593f1 | 1156 | // Enable ref buffers (+ve/-ve) |
mahphalke | 1:48914f9593f1 | 1157 | device_setup_control_reg->value |= |
mahphalke | 1:48914f9593f1 | 1158 | (AD717X_SETUP_CONF_REG_REFBUF_P | |
mahphalke | 1:48914f9593f1 | 1159 | AD717X_SETUP_CONF_REG_REFBUF_N); |
mahphalke | 1:48914f9593f1 | 1160 | } else { |
mahphalke | 1:48914f9593f1 | 1161 | // Disable ref buffers (+ve/-ve) |
mahphalke | 1:48914f9593f1 | 1162 | device_setup_control_reg->value &= |
mahphalke | 1:48914f9593f1 | 1163 | (~(AD717X_SETUP_CONF_REG_REFBUF_P | |
mahphalke | 1:48914f9593f1 | 1164 | AD717X_SETUP_CONF_REG_REFBUF_N)); |
mahphalke | 1:48914f9593f1 | 1165 | } |
mahphalke | 1:48914f9593f1 | 1166 | |
mahphalke | 1:48914f9593f1 | 1167 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1168 | AD717X_SETUPCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1169 | printf(EOL "\tError in Reference Buffer Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 1170 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1171 | } |
mahphalke | 1:48914f9593f1 | 1172 | |
mahphalke | 1:48914f9593f1 | 1173 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 1174 | } |
mahphalke | 1:48914f9593f1 | 1175 | |
mahphalke | 1:48914f9593f1 | 1176 | |
mahphalke | 1:48914f9593f1 | 1177 | /*! |
mahphalke | 1:48914f9593f1 | 1178 | * @brief Handle the menu to enable/disable the input buffers |
mahphalke | 3:6c7324997606 | 1179 | * @param user selected action |
mahphalke | 1:48914f9593f1 | 1180 | * @return MENU_DONE |
mahphalke | 1:48914f9593f1 | 1181 | */ |
mahphalke | 1:48914f9593f1 | 1182 | int32_t menu_input_buffer_enable_disable(uint32_t user_action) |
mahphalke | 1:48914f9593f1 | 1183 | { |
mahphalke | 1:48914f9593f1 | 1184 | ad717x_st_reg *device_setup_control_reg; // Pointer to setup control register |
mahphalke | 1:48914f9593f1 | 1185 | |
mahphalke | 1:48914f9593f1 | 1186 | // Get the pointer to setup control register structure |
mahphalke | 1:48914f9593f1 | 1187 | device_setup_control_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1188 | AD717X_SETUPCON0_REG + device_setup.setup); |
mahphalke | 1:48914f9593f1 | 1189 | |
mahphalke | 1:48914f9593f1 | 1190 | device_setup.input_buffers = user_action; |
mahphalke | 1:48914f9593f1 | 1191 | |
mahphalke | 1:48914f9593f1 | 1192 | if (user_action == SELECT_ENABLE) { |
mahphalke | 1:48914f9593f1 | 1193 | // Enable ref buffers (+ve/-ve) |
mahphalke | 1:48914f9593f1 | 1194 | device_setup_control_reg->value |= |
mahphalke | 1:48914f9593f1 | 1195 | (AD717X_SETUP_CONF_REG_AINBUF_P | |
mahphalke | 1:48914f9593f1 | 1196 | AD717X_SETUP_CONF_REG_AINBUF_N); |
mahphalke | 1:48914f9593f1 | 1197 | } else { |
mahphalke | 1:48914f9593f1 | 1198 | // Disable input buffers (+ve/-ve) |
mahphalke | 1:48914f9593f1 | 1199 | device_setup_control_reg->value &= |
mahphalke | 1:48914f9593f1 | 1200 | (~(AD717X_SETUP_CONF_REG_AINBUF_P | |
mahphalke | 1:48914f9593f1 | 1201 | AD717X_SETUP_CONF_REG_AINBUF_N)); |
mahphalke | 1:48914f9593f1 | 1202 | } |
mahphalke | 1:48914f9593f1 | 1203 | |
mahphalke | 1:48914f9593f1 | 1204 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1205 | AD717X_SETUPCON0_REG + device_setup.setup) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1206 | printf(EOL "\tError in Reference Buffer Selection!!" EOL); |
mahphalke | 1:48914f9593f1 | 1207 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1208 | } |
mahphalke | 1:48914f9593f1 | 1209 | |
mahphalke | 1:48914f9593f1 | 1210 | return MENU_DONE; |
mahphalke | 1:48914f9593f1 | 1211 | } |
mahphalke | 1:48914f9593f1 | 1212 | |
mahphalke | 1:48914f9593f1 | 1213 | |
mahphalke | 1:48914f9593f1 | 1214 | /*! |
mahphalke | 1:48914f9593f1 | 1215 | * @brief Handle the menu to configure and assign the device setup |
mahphalke | 3:6c7324997606 | 1216 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 1217 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 1218 | */ |
mahphalke | 1:48914f9593f1 | 1219 | int32_t menu_config_and_assign_setup(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 1220 | { |
mahphalke | 1:48914f9593f1 | 1221 | float filter_odr; // filter ODR value |
Mahesh Phalke |
4:4592cc69bfa6 | 1222 | char rx_char; |
mahphalke | 1:48914f9593f1 | 1223 | |
mahphalke | 1:48914f9593f1 | 1224 | adi_clear_console(); |
mahphalke | 1:48914f9593f1 | 1225 | |
mahphalke | 1:48914f9593f1 | 1226 | // Get the current setup selection |
mahphalke | 1:48914f9593f1 | 1227 | device_setup.setup = get_setup_selection(); |
mahphalke | 1:48914f9593f1 | 1228 | |
mahphalke | 1:48914f9593f1 | 1229 | // Select the filter type |
mahphalke | 1:48914f9593f1 | 1230 | adi_do_console_menu(&filter_select_menu); |
mahphalke | 1:48914f9593f1 | 1231 | |
mahphalke | 1:48914f9593f1 | 1232 | if (device_setup.filter == SINC5_SINC1_FILTER) { |
mahphalke | 1:48914f9593f1 | 1233 | // Select the post filter parameters |
mahphalke | 1:48914f9593f1 | 1234 | adi_do_console_menu(&postfilter_enable_disable_menu); |
mahphalke | 1:48914f9593f1 | 1235 | |
mahphalke | 1:48914f9593f1 | 1236 | if (device_setup.post_filter_enabled == SELECT_ENABLE) { |
mahphalke | 1:48914f9593f1 | 1237 | // Select the post filter type |
mahphalke | 1:48914f9593f1 | 1238 | adi_do_console_menu(&postfilter_select_menu); |
mahphalke | 1:48914f9593f1 | 1239 | } |
mahphalke | 1:48914f9593f1 | 1240 | |
mahphalke | 1:48914f9593f1 | 1241 | // Select the SINC+SINC1 filter ODR |
mahphalke | 1:48914f9593f1 | 1242 | adi_do_console_menu(&sinc5_1_data_rate_select_menu); |
mahphalke | 1:48914f9593f1 | 1243 | filter_odr = sinc5_sinc1_odr_map[device_setup.odr_bits]; |
mahphalke | 1:48914f9593f1 | 1244 | } else { |
mahphalke | 1:48914f9593f1 | 1245 | // Select the SINC3 filter ODR |
mahphalke | 1:48914f9593f1 | 1246 | adi_do_console_menu(&sinc3_data_rate_select_menu); |
mahphalke | 1:48914f9593f1 | 1247 | filter_odr = sinc3_odr_map[device_setup.odr_bits]; |
mahphalke | 1:48914f9593f1 | 1248 | } |
mahphalke | 1:48914f9593f1 | 1249 | |
mahphalke | 1:48914f9593f1 | 1250 | // Select the polarity |
mahphalke | 1:48914f9593f1 | 1251 | adi_do_console_menu(&polarity_select_menu); |
mahphalke | 1:48914f9593f1 | 1252 | |
mahphalke | 1:48914f9593f1 | 1253 | // Select the reference source |
mahphalke | 1:48914f9593f1 | 1254 | adi_do_console_menu(&reference_select_menu); |
mahphalke | 1:48914f9593f1 | 1255 | |
mahphalke | 1:48914f9593f1 | 1256 | // Select the reference buffer |
mahphalke | 1:48914f9593f1 | 1257 | adi_do_console_menu(&ref_buffer_enable_disable_menu); |
mahphalke | 1:48914f9593f1 | 1258 | |
mahphalke | 1:48914f9593f1 | 1259 | // Select the input buffer |
mahphalke | 1:48914f9593f1 | 1260 | adi_do_console_menu(&input_buffer_enable_disable_menu); |
mahphalke | 1:48914f9593f1 | 1261 | |
mahphalke | 1:48914f9593f1 | 1262 | // Print selections |
mahphalke | 1:48914f9593f1 | 1263 | printf(EOL EOL "\tSetup %ld is configured successfully =>" EOL, |
mahphalke | 1:48914f9593f1 | 1264 | device_setup.setup); |
mahphalke | 1:48914f9593f1 | 1265 | printf(EOL "\tFilter Type: %s", filter_name[device_setup.filter]); |
mahphalke | 1:48914f9593f1 | 1266 | |
mahphalke | 1:48914f9593f1 | 1267 | if (device_setup.filter == SINC5_SINC1_FILTER |
mahphalke | 1:48914f9593f1 | 1268 | && device_setup.post_filter_enabled) { |
mahphalke | 1:48914f9593f1 | 1269 | printf("\r\n\tPost Filter Type: %s", postfilter_name[device_setup.postfilter]); |
mahphalke | 1:48914f9593f1 | 1270 | } |
mahphalke | 1:48914f9593f1 | 1271 | |
mahphalke | 1:48914f9593f1 | 1272 | printf(EOL "\tData Rate: %f", filter_odr); |
mahphalke | 1:48914f9593f1 | 1273 | printf(EOL "\tPolarity: %s", polarity_status[device_setup.polarity]); |
mahphalke | 1:48914f9593f1 | 1274 | printf(EOL "\tReference: %s", reference_name[device_setup.reference]); |
mahphalke | 1:48914f9593f1 | 1275 | printf(EOL "\tReference Buffers: %s", |
mahphalke | 1:48914f9593f1 | 1276 | enable_disable_status[device_setup.reference_buffers]); |
mahphalke | 1:48914f9593f1 | 1277 | printf(EOL "\tInput Buffers: %s", |
mahphalke | 1:48914f9593f1 | 1278 | enable_disable_status[device_setup.input_buffers]); |
mahphalke | 1:48914f9593f1 | 1279 | printf(EOL); |
mahphalke | 1:48914f9593f1 | 1280 | |
Mahesh Phalke |
4:4592cc69bfa6 | 1281 | /* Allow user to assign setup to multiple channels*/ |
Mahesh Phalke |
4:4592cc69bfa6 | 1282 | do { |
Mahesh Phalke |
4:4592cc69bfa6 | 1283 | // Select and assign the channel |
Mahesh Phalke |
4:4592cc69bfa6 | 1284 | rx_char = select_chn_assignment(); |
Mahesh Phalke |
4:4592cc69bfa6 | 1285 | } while (rx_char != 'N'); |
mahphalke | 1:48914f9593f1 | 1286 | |
mahphalke | 1:48914f9593f1 | 1287 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1288 | } |
mahphalke | 1:48914f9593f1 | 1289 | |
mahphalke | 1:48914f9593f1 | 1290 | |
mahphalke | 1:48914f9593f1 | 1291 | /* @brief Get the data rate based on data rate FS value and vice a versa |
mahphalke | 3:6c7324997606 | 1292 | * @param Filter Type |
mahphalke | 3:6c7324997606 | 1293 | * @param Filter data rate register value/bits |
mahphalke | 3:6c7324997606 | 1294 | * @return Actual Data Rate |
mahphalke | 1:48914f9593f1 | 1295 | **/ |
mahphalke | 1:48914f9593f1 | 1296 | static float get_data_rate(uint32_t filter, uint32_t odr_reg_val) |
mahphalke | 1:48914f9593f1 | 1297 | { |
mahphalke | 1:48914f9593f1 | 1298 | float data_rate; // filter data rate |
mahphalke | 1:48914f9593f1 | 1299 | |
mahphalke | 1:48914f9593f1 | 1300 | if (filter == SINC5_SINC1_FILTER) { |
mahphalke | 1:48914f9593f1 | 1301 | data_rate = sinc5_sinc1_odr_map[odr_reg_val]; |
mahphalke | 1:48914f9593f1 | 1302 | } else { |
mahphalke | 1:48914f9593f1 | 1303 | data_rate = sinc3_odr_map[odr_reg_val]; |
mahphalke | 1:48914f9593f1 | 1304 | } |
mahphalke | 1:48914f9593f1 | 1305 | |
mahphalke | 1:48914f9593f1 | 1306 | return data_rate; |
mahphalke | 1:48914f9593f1 | 1307 | } |
mahphalke | 1:48914f9593f1 | 1308 | |
mahphalke | 1:48914f9593f1 | 1309 | |
mahphalke | 1:48914f9593f1 | 1310 | /*! |
mahphalke | 1:48914f9593f1 | 1311 | * @brief Handle the menu to display device setup |
mahphalke | 3:6c7324997606 | 1312 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 1313 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 1314 | */ |
mahphalke | 1:48914f9593f1 | 1315 | int32_t menu_display_setup(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 1316 | { |
mahphalke | 1:48914f9593f1 | 1317 | float filter_data_rate; // Filter data rate in SPS |
mahphalke | 1:48914f9593f1 | 1318 | uint8_t setup_cnt; // setup counter |
mahphalke | 1:48914f9593f1 | 1319 | uint8_t chn_cnt; // channel counter |
mahphalke | 1:48914f9593f1 | 1320 | ad717x_st_reg *device_chnmap_reg; // Pointer to channel map register |
mahphalke | 1:48914f9593f1 | 1321 | ad717x_st_reg *device_setupcon_reg; // Pointer to setup control register |
mahphalke | 1:48914f9593f1 | 1322 | ad717x_st_reg *device_filtercon_reg; // Pointer to filter control register |
mahphalke | 1:48914f9593f1 | 1323 | |
mahphalke | 1:48914f9593f1 | 1324 | printf(EOL); |
mahphalke | 1:48914f9593f1 | 1325 | printf("\t---------------------------------------" EOL); |
mahphalke | 1:48914f9593f1 | 1326 | printf("\tChannel# | Status | Setup | INP0 | INP1" EOL); |
mahphalke | 1:48914f9593f1 | 1327 | printf("\t---------------------------------------" EOL); |
mahphalke | 1:48914f9593f1 | 1328 | |
mahphalke | 1:48914f9593f1 | 1329 | for (chn_cnt = 0; chn_cnt < NUMBER_OF_CHANNELS; chn_cnt++) { |
mahphalke | 1:48914f9593f1 | 1330 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 1331 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt); |
mahphalke | 1:48914f9593f1 | 1332 | if (AD717X_ReadRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1333 | printf(EOL "Error reading setup!!" EOL); |
mahphalke | 1:48914f9593f1 | 1334 | break; |
mahphalke | 1:48914f9593f1 | 1335 | } |
mahphalke | 1:48914f9593f1 | 1336 | |
mahphalke | 1:48914f9593f1 | 1337 | // Extract the channel parameters from device register read value |
mahphalke | 1:48914f9593f1 | 1338 | device_setup.channel_enabled = AD717X_CHMAP_REG_CH_EN_RD( |
mahphalke | 1:48914f9593f1 | 1339 | device_chnmap_reg->value); |
mahphalke | 1:48914f9593f1 | 1340 | device_setup.setup_assigned = AD717X_CHMAP_REG_SETUP_SEL_RD( |
mahphalke | 1:48914f9593f1 | 1341 | device_chnmap_reg->value); |
mahphalke | 1:48914f9593f1 | 1342 | device_setup.pos_analog_input = AD717X_CHMAP_REG_AINPOS_RD( |
mahphalke | 1:48914f9593f1 | 1343 | device_chnmap_reg->value); |
mahphalke | 1:48914f9593f1 | 1344 | device_setup.neg_analog_input = AD717X_CHMAP_REG_AINNEG_RD( |
mahphalke | 1:48914f9593f1 | 1345 | device_chnmap_reg->value); |
mahphalke | 1:48914f9593f1 | 1346 | |
mahphalke | 1:48914f9593f1 | 1347 | // Channel# | Status | Setup | INP0 | INP1 |
mahphalke | 1:48914f9593f1 | 1348 | printf("\t%4d %13s %4ld %8s %6s" EOL, |
mahphalke | 1:48914f9593f1 | 1349 | chn_cnt, |
mahphalke | 1:48914f9593f1 | 1350 | enable_disable_status[device_setup.channel_enabled], |
mahphalke | 1:48914f9593f1 | 1351 | device_setup.setup_assigned, |
mahphalke | 1:48914f9593f1 | 1352 | input_pin_map[device_setup.pos_analog_input], |
mahphalke | 1:48914f9593f1 | 1353 | input_pin_map[device_setup.neg_analog_input]); |
mahphalke | 1:48914f9593f1 | 1354 | } |
mahphalke | 1:48914f9593f1 | 1355 | |
mahphalke | 1:48914f9593f1 | 1356 | printf(EOL); |
mahphalke | 1:48914f9593f1 | 1357 | printf("\t-------------------------------------------------------------------------------------------------------------" |
mahphalke | 1:48914f9593f1 | 1358 | EOL); |
mahphalke | 1:48914f9593f1 | 1359 | printf("\tSetup# | Filter | Post Filter | Data Rate | INPBUF+ | INPBUF- | REFBUF+ | REFBUF- | Polarity | Ref Source" |
mahphalke | 1:48914f9593f1 | 1360 | EOL); |
mahphalke | 1:48914f9593f1 | 1361 | printf("\t-------------------------------------------------------------------------------------------------------------" |
mahphalke | 1:48914f9593f1 | 1362 | EOL); |
mahphalke | 1:48914f9593f1 | 1363 | |
mahphalke | 1:48914f9593f1 | 1364 | for (setup_cnt = 0; setup_cnt < NUMBER_OF_SETUPS; setup_cnt++) { |
mahphalke | 1:48914f9593f1 | 1365 | // Get the pointer to filter control register |
mahphalke | 1:48914f9593f1 | 1366 | device_filtercon_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1367 | AD717X_FILTCON0_REG + setup_cnt); |
mahphalke | 1:48914f9593f1 | 1368 | if (AD717X_ReadRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1369 | AD717X_FILTCON0_REG + setup_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1370 | printf("\r\nError reading setup!!\r\n"); |
mahphalke | 1:48914f9593f1 | 1371 | break; |
mahphalke | 1:48914f9593f1 | 1372 | } |
mahphalke | 1:48914f9593f1 | 1373 | |
mahphalke | 1:48914f9593f1 | 1374 | /* Extract the setup parameters from device register read value */ |
mahphalke | 1:48914f9593f1 | 1375 | device_setup.filter = AD717X_FILT_CONF_REG_ORDER_RD( |
mahphalke | 1:48914f9593f1 | 1376 | device_filtercon_reg->value); |
mahphalke | 1:48914f9593f1 | 1377 | device_setup.odr_bits = AD717X_FILT_CONF_REG_ODR_RD( |
mahphalke | 1:48914f9593f1 | 1378 | device_filtercon_reg->value); |
mahphalke | 1:48914f9593f1 | 1379 | device_setup.post_filter_enabled = AD717X_FILT_CONF_REG_ENHFILTEN_RD( |
mahphalke | 1:48914f9593f1 | 1380 | device_filtercon_reg->value); |
mahphalke | 1:48914f9593f1 | 1381 | device_setup.postfilter = AD717X_FILT_CONF_REG_ENHFILT_RD( |
mahphalke | 1:48914f9593f1 | 1382 | device_filtercon_reg->value); |
mahphalke | 1:48914f9593f1 | 1383 | |
mahphalke | 1:48914f9593f1 | 1384 | if (device_setup.filter == SINC3_FILTER) { |
mahphalke | 1:48914f9593f1 | 1385 | // Post filter unavailable for SINC3 type filter |
mahphalke | 1:48914f9593f1 | 1386 | device_setup.post_filter_enabled = SELECT_DISBLE; |
mahphalke | 1:48914f9593f1 | 1387 | device_setup.postfilter = POST_FILTER_NA; |
mahphalke | 1:48914f9593f1 | 1388 | } |
mahphalke | 1:48914f9593f1 | 1389 | |
mahphalke | 1:48914f9593f1 | 1390 | // Get the pointer to setup control register |
mahphalke | 1:48914f9593f1 | 1391 | device_setupcon_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1392 | AD717X_SETUPCON0_REG + setup_cnt); |
mahphalke | 1:48914f9593f1 | 1393 | if (AD717X_ReadRegister(pad717x_dev, |
mahphalke | 1:48914f9593f1 | 1394 | AD717X_SETUPCON0_REG + setup_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1395 | printf("\r\nError reading setup!!\r\n"); |
mahphalke | 1:48914f9593f1 | 1396 | break; |
mahphalke | 1:48914f9593f1 | 1397 | } |
mahphalke | 1:48914f9593f1 | 1398 | |
Mahesh Phalke |
4:4592cc69bfa6 | 1399 | #if defined(DEV_AD4111) || defined(DEV_AD4112) || defined(DEV_AD4114) || \ |
Mahesh Phalke |
4:4592cc69bfa6 | 1400 | defined(DEV_AD4115) |
mahphalke | 1:48914f9593f1 | 1401 | device_setup.input_buffers = |
mahphalke | 1:48914f9593f1 | 1402 | AD4111_SETUP_CONF_REG_AIN_BUF_RD(device_setupcon_reg->value); |
mahphalke | 1:48914f9593f1 | 1403 | device_setup.reference_buffers = |
mahphalke | 1:48914f9593f1 | 1404 | (AD4111_SETUP_CONF_REG_REFPOS_BUF_RD(device_setupcon_reg->value) << 1 | |
mahphalke | 1:48914f9593f1 | 1405 | AD4111_SETUP_CONF_REG_REFNEG_BUF_RD(device_setupcon_reg->value)); |
mahphalke | 1:48914f9593f1 | 1406 | #elif defined(DEV_AD7172_2) || defined(DEV_AD7172_4) || defined(DEV_AD7175_8) |
mahphalke | 1:48914f9593f1 | 1407 | device_setup.input_buffers = |
mahphalke | 1:48914f9593f1 | 1408 | (AD717X_SETUP_CONF_REG_AINBUF_P_RD(device_setupcon_reg->value) << 1) | |
mahphalke | 1:48914f9593f1 | 1409 | (AD717X_SETUP_CONF_REG_AINBUF_N_RD(device_setupcon_reg->value)); |
mahphalke | 1:48914f9593f1 | 1410 | |
mahphalke | 1:48914f9593f1 | 1411 | device_setup.reference_buffers = |
mahphalke | 1:48914f9593f1 | 1412 | (AD717X_SETUP_CONF_REG_REFBUF_P_RD(device_setupcon_reg->value) << 1) | |
mahphalke | 1:48914f9593f1 | 1413 | (AD717X_SETUP_CONF_REG_REFBUF_N_RD(device_setupcon_reg->value)); |
mahphalke | 1:48914f9593f1 | 1414 | #elif defined(DEV_AD7173_8) |
mahphalke | 1:48914f9593f1 | 1415 | device_setup.input_buffers = |
mahphalke | 1:48914f9593f1 | 1416 | AD717X_SETUP_CONF_REG_AIN_BUF_RD(device_setupcon_reg->value); |
mahphalke | 1:48914f9593f1 | 1417 | device_setup.reference_buffers = |
mahphalke | 1:48914f9593f1 | 1418 | AD717X_SETUP_CONF_REG_REF_BUF_RD(device_setupcon_reg->value); |
mahphalke | 1:48914f9593f1 | 1419 | #endif |
mahphalke | 1:48914f9593f1 | 1420 | |
mahphalke | 1:48914f9593f1 | 1421 | device_setup.polarity = AD717X_SETUP_CONF_REG_BI_UNIPOLAR_RD( |
mahphalke | 1:48914f9593f1 | 1422 | device_setupcon_reg->value); |
mahphalke | 1:48914f9593f1 | 1423 | device_setup.reference = AD717X_SETUP_CONF_REG_REF_SEL_RD( |
mahphalke | 1:48914f9593f1 | 1424 | device_setupcon_reg->value); |
mahphalke | 1:48914f9593f1 | 1425 | |
mahphalke | 1:48914f9593f1 | 1426 | // Get the actual data rate based on the filter selection |
mahphalke | 1:48914f9593f1 | 1427 | filter_data_rate = get_data_rate(device_setup.filter, |
mahphalke | 1:48914f9593f1 | 1428 | device_setup.odr_bits); |
mahphalke | 1:48914f9593f1 | 1429 | |
mahphalke | 1:48914f9593f1 | 1430 | // Setup# | Filter | Post Filter | Data Rate | INPBUF+ | INPBUF- | REFBUF+ | REFBUF- | Polarity | Ref Source |
mahphalke | 1:48914f9593f1 | 1431 | printf("\t%4d %11s %8s(%6s) %10.2f %9s %9s %9s %9s %10s %10s" EOL, |
mahphalke | 1:48914f9593f1 | 1432 | setup_cnt, |
mahphalke | 1:48914f9593f1 | 1433 | filter_name[device_setup.filter], |
mahphalke | 1:48914f9593f1 | 1434 | postfilter_name[device_setup.postfilter], |
mahphalke | 1:48914f9593f1 | 1435 | enable_disable_status[device_setup.post_filter_enabled], |
mahphalke | 1:48914f9593f1 | 1436 | filter_data_rate, |
mahphalke | 1:48914f9593f1 | 1437 | enable_disable_status[(device_setup.input_buffers >> 1) & 0x01], |
mahphalke | 1:48914f9593f1 | 1438 | enable_disable_status[(device_setup.input_buffers & 0x01)], |
mahphalke | 1:48914f9593f1 | 1439 | enable_disable_status[(device_setup.reference_buffers >> 1) & 0x01], |
mahphalke | 1:48914f9593f1 | 1440 | enable_disable_status[device_setup.reference_buffers & 0x01], |
mahphalke | 1:48914f9593f1 | 1441 | polarity_status[device_setup.polarity], |
mahphalke | 1:48914f9593f1 | 1442 | reference_name[device_setup.reference]); |
mahphalke | 1:48914f9593f1 | 1443 | } |
mahphalke | 1:48914f9593f1 | 1444 | |
mahphalke | 1:48914f9593f1 | 1445 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1446 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1447 | } |
mahphalke | 1:48914f9593f1 | 1448 | |
mahphalke | 1:48914f9593f1 | 1449 | |
mahphalke | 1:48914f9593f1 | 1450 | /*! |
mahphalke | 1:48914f9593f1 | 1451 | * @brief Handle the menu to read die temperature of device |
mahphalke | 3:6c7324997606 | 1452 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 1453 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 1454 | */ |
mahphalke | 1:48914f9593f1 | 1455 | int32_t menu_read_temperature(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 1456 | { |
mahphalke | 1:48914f9593f1 | 1457 | uint8_t chn_cnt; // current channel |
mahphalke | 1:48914f9593f1 | 1458 | uint16_t chn_mask = 0; // channels enable mask |
mahphalke | 1:48914f9593f1 | 1459 | ad717x_st_reg *device_mode_reg; // Pointer to device mode register |
mahphalke | 1:48914f9593f1 | 1460 | ad717x_st_reg *device_chnmap_reg; // Pointer to channel map register |
mahphalke | 1:48914f9593f1 | 1461 | ad717x_st_reg *device_setup_control_reg; // Pointer to setup control register |
mahphalke | 1:48914f9593f1 | 1462 | int32_t sample_data; // ADC sample result |
mahphalke | 1:48914f9593f1 | 1463 | float temperature = 0.00; // Temperature in Celcius |
mahphalke | 1:48914f9593f1 | 1464 | float conversion_result; // raw sample data to voltage conversion result |
mahphalke | 1:48914f9593f1 | 1465 | int32_t prev_adc_reg_values[3]; // Holds the previous register values |
mahphalke | 1:48914f9593f1 | 1466 | bool temperature_read_error; // Temperature read error status |
mahphalke | 1:48914f9593f1 | 1467 | |
mahphalke | 1:48914f9593f1 | 1468 | temperature_read_error = false; |
mahphalke | 1:48914f9593f1 | 1469 | |
mahphalke | 1:48914f9593f1 | 1470 | // Disable the other enabled channels to read temperature from only 0th channel |
mahphalke | 1:48914f9593f1 | 1471 | for (chn_cnt = 1; chn_cnt < NUMBER_OF_CHANNELS; chn_cnt++) { |
mahphalke | 1:48914f9593f1 | 1472 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 1473 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt); |
mahphalke | 1:48914f9593f1 | 1474 | if (AD717X_ReadRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1475 | temperature_read_error = true; |
mahphalke | 1:48914f9593f1 | 1476 | break; |
mahphalke | 1:48914f9593f1 | 1477 | } |
mahphalke | 1:48914f9593f1 | 1478 | |
mahphalke | 1:48914f9593f1 | 1479 | if (device_chnmap_reg->value & AD717X_CHMAP_REG_CH_EN) { |
mahphalke | 1:48914f9593f1 | 1480 | // Save enabled channel |
mahphalke | 1:48914f9593f1 | 1481 | chn_mask |= (1 << chn_cnt); |
mahphalke | 1:48914f9593f1 | 1482 | |
mahphalke | 1:48914f9593f1 | 1483 | // Disable the curent channel |
mahphalke | 1:48914f9593f1 | 1484 | device_chnmap_reg->value &= (~AD717X_CHMAP_REG_CH_EN); |
mahphalke | 1:48914f9593f1 | 1485 | |
mahphalke | 1:48914f9593f1 | 1486 | // Write to ADC channel register |
mahphalke | 1:48914f9593f1 | 1487 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1488 | temperature_read_error = true; |
mahphalke | 1:48914f9593f1 | 1489 | break; |
mahphalke | 1:48914f9593f1 | 1490 | } |
mahphalke | 1:48914f9593f1 | 1491 | } |
mahphalke | 1:48914f9593f1 | 1492 | } |
mahphalke | 1:48914f9593f1 | 1493 | |
mahphalke | 1:48914f9593f1 | 1494 | if (temperature_read_error == false) { |
mahphalke | 1:48914f9593f1 | 1495 | // Get the pointer to device registers |
mahphalke | 1:48914f9593f1 | 1496 | device_mode_reg = AD717X_GetReg(pad717x_dev, AD717X_ADCMODE_REG); |
mahphalke | 1:48914f9593f1 | 1497 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG); |
mahphalke | 1:48914f9593f1 | 1498 | device_setup_control_reg = AD717X_GetReg(pad717x_dev, AD717X_SETUPCON0_REG); |
mahphalke | 1:48914f9593f1 | 1499 | |
mahphalke | 1:48914f9593f1 | 1500 | // Save the previous values of below registers in order to not disturb |
mahphalke | 1:48914f9593f1 | 1501 | // the user configured setup. |
mahphalke | 1:48914f9593f1 | 1502 | // *Note: This step is not required for someone who intended to just |
mahphalke | 1:48914f9593f1 | 1503 | // read temperature. It is an application specific functionality. |
mahphalke | 1:48914f9593f1 | 1504 | prev_adc_reg_values[0] = device_mode_reg->value; |
mahphalke | 1:48914f9593f1 | 1505 | prev_adc_reg_values[1] = device_chnmap_reg->value; |
mahphalke | 1:48914f9593f1 | 1506 | prev_adc_reg_values[2] = device_setup_control_reg->value; |
mahphalke | 1:48914f9593f1 | 1507 | |
mahphalke | 1:48914f9593f1 | 1508 | // Configure the channel map 0 register |
mahphalke | 1:48914f9593f1 | 1509 | // AINP = Temp + , AINM = Temp - , Setup = 0, CHN Enabled = True |
mahphalke | 1:48914f9593f1 | 1510 | device_chnmap_reg->value = |
mahphalke | 1:48914f9593f1 | 1511 | (AD717X_CHMAP_REG_AINPOS(TEMP_SENSOR_POS_INP_BITS) | |
mahphalke | 1:48914f9593f1 | 1512 | AD717X_CHMAP_REG_AINNEG(TEMP_SENSOR_NEG_INP_BITS) | |
mahphalke | 1:48914f9593f1 | 1513 | AD717X_CHMAP_REG_SETUP_SEL(0) | |
mahphalke | 1:48914f9593f1 | 1514 | AD717X_CHMAP_REG_CH_EN); |
mahphalke | 1:48914f9593f1 | 1515 | |
mahphalke | 1:48914f9593f1 | 1516 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1517 | printf(EOL EOL "\tError Reading Temperature!!"); |
mahphalke | 1:48914f9593f1 | 1518 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1519 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1520 | } |
mahphalke | 1:48914f9593f1 | 1521 | |
mahphalke | 1:48914f9593f1 | 1522 | // Configure the setup control 0 register |
mahphalke | 1:48914f9593f1 | 1523 | // Polarity: Bipolar, Input Buffers: Enable, Ref: Internal |
mahphalke | 1:48914f9593f1 | 1524 | device_setup_control_reg->value = |
mahphalke | 1:48914f9593f1 | 1525 | (AD717X_SETUP_CONF_REG_BI_UNIPOLAR | |
mahphalke | 1:48914f9593f1 | 1526 | AD717X_SETUP_CONF_REG_AINBUF_P | |
mahphalke | 1:48914f9593f1 | 1527 | AD717X_SETUP_CONF_REG_AINBUF_N | |
mahphalke | 1:48914f9593f1 | 1528 | AD717X_SETUP_CONF_REG_REF_SEL(INTERNAL)); |
mahphalke | 1:48914f9593f1 | 1529 | |
mahphalke | 1:48914f9593f1 | 1530 | if (AD717X_WriteRegister(pad717x_dev, AD717X_SETUPCON0_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1531 | printf(EOL EOL "\tError Reading Temperature!!"); |
mahphalke | 1:48914f9593f1 | 1532 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1533 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1534 | } |
mahphalke | 1:48914f9593f1 | 1535 | |
mahphalke | 1:48914f9593f1 | 1536 | // Configure the device mode register |
mahphalke | 3:6c7324997606 | 1537 | // Internal Ref: Enable, Mode: Single Conversion |
mahphalke | 1:48914f9593f1 | 1538 | device_mode_reg->value |= AD717X_ADCMODE_REG_REF_EN; |
mahphalke | 1:48914f9593f1 | 1539 | device_mode_reg->value = |
mahphalke | 1:48914f9593f1 | 1540 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 1541 | AD717X_ADCMODE_REG_MODE(SINGLE_CONVERISION)); |
mahphalke | 1:48914f9593f1 | 1542 | |
mahphalke | 1:48914f9593f1 | 1543 | if (AD717X_WriteRegister(pad717x_dev, AD717X_ADCMODE_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1544 | printf(EOL EOL "\tError Reading Temperature!!"); |
mahphalke | 1:48914f9593f1 | 1545 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1546 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1547 | } |
mahphalke | 1:48914f9593f1 | 1548 | |
mahphalke | 1:48914f9593f1 | 1549 | for (uint8_t samples = 0; samples < 2; samples++) { |
mahphalke | 1:48914f9593f1 | 1550 | // Wait for conversion to complete, then obtain sample |
mahphalke | 1:48914f9593f1 | 1551 | AD717X_WaitForReady(pad717x_dev, 10000); |
mahphalke | 1:48914f9593f1 | 1552 | |
mahphalke | 1:48914f9593f1 | 1553 | if (AD717X_ReadData(pad717x_dev, &sample_data) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1554 | temperature_read_error = true; |
mahphalke | 1:48914f9593f1 | 1555 | break; |
mahphalke | 1:48914f9593f1 | 1556 | } |
mahphalke | 1:48914f9593f1 | 1557 | } |
mahphalke | 1:48914f9593f1 | 1558 | |
mahphalke | 1:48914f9593f1 | 1559 | if (temperature_read_error == false) { |
mahphalke | 1:48914f9593f1 | 1560 | conversion_result = (((float)sample_data / (1 << (ADC_RESOLUTION - 1))) - 1) * |
mahphalke | 1:48914f9593f1 | 1561 | ADC_REF_VOLTAGE; |
mahphalke | 1:48914f9593f1 | 1562 | |
mahphalke | 1:48914f9593f1 | 1563 | // Calculate the temparture in degree celcius (sensitivity: 477uV/K) |
mahphalke | 1:48914f9593f1 | 1564 | // *Below equation is referred from the device datasheet |
mahphalke | 1:48914f9593f1 | 1565 | temperature = ((float)conversion_result / 0.000477) - 273.15; |
mahphalke | 1:48914f9593f1 | 1566 | |
mahphalke | 1:48914f9593f1 | 1567 | // All done, restore previous state of device registers |
mahphalke | 1:48914f9593f1 | 1568 | // *Note: This step is not required for someone who intended to just |
mahphalke | 1:48914f9593f1 | 1569 | // read temperature. It is an application specific functionality. |
mahphalke | 1:48914f9593f1 | 1570 | device_mode_reg->value = prev_adc_reg_values[0]; |
mahphalke | 1:48914f9593f1 | 1571 | (void)AD717X_WriteRegister(pad717x_dev, AD717X_ADCMODE_REG); |
mahphalke | 1:48914f9593f1 | 1572 | |
mahphalke | 1:48914f9593f1 | 1573 | device_chnmap_reg->value = prev_adc_reg_values[1]; |
mahphalke | 1:48914f9593f1 | 1574 | (void)AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG); |
mahphalke | 1:48914f9593f1 | 1575 | |
mahphalke | 1:48914f9593f1 | 1576 | device_setup_control_reg->value = prev_adc_reg_values[2]; |
mahphalke | 1:48914f9593f1 | 1577 | (void)AD717X_WriteRegister(pad717x_dev, AD717X_SETUPCON0_REG); |
mahphalke | 1:48914f9593f1 | 1578 | |
mahphalke | 1:48914f9593f1 | 1579 | // Need to restore the channels those were disabled during temperaure read |
mahphalke | 1:48914f9593f1 | 1580 | for (uint8_t i = 0 ; i < NUMBER_OF_CHANNELS ; i++) { |
mahphalke | 1:48914f9593f1 | 1581 | if (chn_mask & (1 << i)) { |
mahphalke | 1:48914f9593f1 | 1582 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 1583 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + i); |
mahphalke | 1:48914f9593f1 | 1584 | device_chnmap_reg->value |= AD717X_CHMAP_REG_CH_EN; |
mahphalke | 1:48914f9593f1 | 1585 | |
mahphalke | 1:48914f9593f1 | 1586 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + i) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1587 | // continue with other channels |
mahphalke | 1:48914f9593f1 | 1588 | } |
mahphalke | 1:48914f9593f1 | 1589 | } |
mahphalke | 1:48914f9593f1 | 1590 | } |
mahphalke | 1:48914f9593f1 | 1591 | } |
mahphalke | 1:48914f9593f1 | 1592 | } |
mahphalke | 1:48914f9593f1 | 1593 | |
mahphalke | 1:48914f9593f1 | 1594 | if (temperature_read_error == false) { |
mahphalke | 1:48914f9593f1 | 1595 | printf(EOL EOL "\tTemperature: %.2f Celcius", temperature); |
mahphalke | 1:48914f9593f1 | 1596 | } else { |
mahphalke | 1:48914f9593f1 | 1597 | printf(EOL EOL "\tError Reading Temperature!!"); |
mahphalke | 1:48914f9593f1 | 1598 | } |
mahphalke | 1:48914f9593f1 | 1599 | |
mahphalke | 1:48914f9593f1 | 1600 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1601 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1602 | } |
mahphalke | 1:48914f9593f1 | 1603 | |
mahphalke | 1:48914f9593f1 | 1604 | |
mahphalke | 1:48914f9593f1 | 1605 | /*! |
mahphalke | 1:48914f9593f1 | 1606 | * @brief Handle the menu to calibrate the device |
mahphalke | 3:6c7324997606 | 1607 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 1608 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 1609 | */ |
mahphalke | 1:48914f9593f1 | 1610 | int32_t menu_calibrate_adc(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 1611 | { |
mahphalke | 1:48914f9593f1 | 1612 | uint8_t chn_cnt; // Current channel |
mahphalke | 1:48914f9593f1 | 1613 | uint16_t chn_mask = 0; // Channel enable mask |
mahphalke | 1:48914f9593f1 | 1614 | ad717x_st_reg *device_chnmap_reg; // Pointer to channel map register |
mahphalke | 1:48914f9593f1 | 1615 | ad717x_st_reg *device_mode_reg; // Pointer to device mode register |
mahphalke | 1:48914f9593f1 | 1616 | bool calibration_error; // Calibration error flag |
mahphalke | 1:48914f9593f1 | 1617 | |
mahphalke | 1:48914f9593f1 | 1618 | calibration_error = false; |
mahphalke | 1:48914f9593f1 | 1619 | |
mahphalke | 1:48914f9593f1 | 1620 | for (chn_cnt = 0; chn_cnt < NUMBER_OF_CHANNELS; chn_cnt++) { |
mahphalke | 1:48914f9593f1 | 1621 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 1622 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt); |
mahphalke | 1:48914f9593f1 | 1623 | if (AD717X_ReadRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1624 | calibration_error = true; |
mahphalke | 1:48914f9593f1 | 1625 | break; |
mahphalke | 1:48914f9593f1 | 1626 | } |
mahphalke | 1:48914f9593f1 | 1627 | |
mahphalke | 1:48914f9593f1 | 1628 | if (device_chnmap_reg->value & AD717X_CHMAP_REG_CH_EN) { |
mahphalke | 1:48914f9593f1 | 1629 | // Save enabled channel |
mahphalke | 1:48914f9593f1 | 1630 | chn_mask |= (1 << chn_cnt); |
mahphalke | 1:48914f9593f1 | 1631 | |
mahphalke | 1:48914f9593f1 | 1632 | // Disable the curent channel |
mahphalke | 1:48914f9593f1 | 1633 | device_chnmap_reg->value &= (~AD717X_CHMAP_REG_CH_EN); |
mahphalke | 1:48914f9593f1 | 1634 | |
mahphalke | 1:48914f9593f1 | 1635 | if(AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1636 | calibration_error = true; |
mahphalke | 1:48914f9593f1 | 1637 | break; |
mahphalke | 1:48914f9593f1 | 1638 | } |
mahphalke | 1:48914f9593f1 | 1639 | } |
mahphalke | 1:48914f9593f1 | 1640 | } |
mahphalke | 1:48914f9593f1 | 1641 | |
mahphalke | 1:48914f9593f1 | 1642 | if (calibration_error == false) { |
mahphalke | 1:48914f9593f1 | 1643 | // Calibrate all the channels |
mahphalke | 1:48914f9593f1 | 1644 | for (chn_cnt = 0 ; chn_cnt < NUMBER_OF_CHANNELS ; chn_cnt++) { |
mahphalke | 1:48914f9593f1 | 1645 | printf(EOL "\tCalibrating Channel %d => " EOL, chn_cnt); |
mahphalke | 1:48914f9593f1 | 1646 | |
mahphalke | 1:48914f9593f1 | 1647 | // Enable current channel |
mahphalke | 1:48914f9593f1 | 1648 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt); |
mahphalke | 1:48914f9593f1 | 1649 | device_chnmap_reg->value |= AD717X_CHMAP_REG_CH_EN; |
mahphalke | 1:48914f9593f1 | 1650 | |
mahphalke | 1:48914f9593f1 | 1651 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1652 | calibration_error = true; |
mahphalke | 1:48914f9593f1 | 1653 | break; |
mahphalke | 1:48914f9593f1 | 1654 | } |
mahphalke | 1:48914f9593f1 | 1655 | |
mahphalke | 1:48914f9593f1 | 1656 | device_mode_reg = AD717X_GetReg(pad717x_dev, AD717X_ADCMODE_REG); |
mahphalke | 1:48914f9593f1 | 1657 | |
mahphalke | 3:6c7324997606 | 1658 | // Start full scale internal (gain) calibration |
mahphalke | 1:48914f9593f1 | 1659 | printf("\tRunning full-scale internal calibration..." EOL); |
mahphalke | 1:48914f9593f1 | 1660 | device_mode_reg->value = |
mahphalke | 1:48914f9593f1 | 1661 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 1662 | AD717X_ADCMODE_REG_MODE(INTERNAL_FULL_SCALE_CAL_MODE)); |
mahphalke | 1:48914f9593f1 | 1663 | |
mahphalke | 1:48914f9593f1 | 1664 | if (AD717X_WriteRegister(pad717x_dev, AD717X_ADCMODE_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1665 | calibration_error = true; |
mahphalke | 1:48914f9593f1 | 1666 | break; |
mahphalke | 1:48914f9593f1 | 1667 | } |
mahphalke | 1:48914f9593f1 | 1668 | |
mahphalke | 1:48914f9593f1 | 1669 | // Wait for calibration to over |
mahphalke | 1:48914f9593f1 | 1670 | if (AD717X_WaitForReady(pad717x_dev, 10000) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1671 | calibration_error = true; |
mahphalke | 1:48914f9593f1 | 1672 | break; |
mahphalke | 1:48914f9593f1 | 1673 | } else { |
mahphalke | 3:6c7324997606 | 1674 | // Start zero scale internal (offset) calibration |
mahphalke | 1:48914f9593f1 | 1675 | printf("\tRunning zero-scale internal calibration..." EOL); |
mahphalke | 1:48914f9593f1 | 1676 | device_mode_reg->value = |
mahphalke | 1:48914f9593f1 | 1677 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 1678 | AD717X_ADCMODE_REG_MODE(INTERNAL_OFFSET_CAL_MODE)); |
mahphalke | 1:48914f9593f1 | 1679 | |
mahphalke | 1:48914f9593f1 | 1680 | if (AD717X_WriteRegister(pad717x_dev, AD717X_ADCMODE_REG) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1681 | calibration_error = true; |
mahphalke | 1:48914f9593f1 | 1682 | break; |
mahphalke | 1:48914f9593f1 | 1683 | } |
mahphalke | 1:48914f9593f1 | 1684 | |
mahphalke | 1:48914f9593f1 | 1685 | // Wait for calibration to over |
mahphalke | 1:48914f9593f1 | 1686 | if (AD717X_WaitForReady(pad717x_dev, 10000) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1687 | printf("\tError in channel calibration..." EOL); |
mahphalke | 1:48914f9593f1 | 1688 | } else { |
mahphalke | 1:48914f9593f1 | 1689 | printf("\tCalibration Successful..." EOL); |
mahphalke | 1:48914f9593f1 | 1690 | } |
mahphalke | 1:48914f9593f1 | 1691 | } |
mahphalke | 1:48914f9593f1 | 1692 | |
mahphalke | 1:48914f9593f1 | 1693 | // Disable current channel |
mahphalke | 1:48914f9593f1 | 1694 | device_chnmap_reg->value &= (~AD717X_CHMAP_REG_CH_EN); |
mahphalke | 1:48914f9593f1 | 1695 | |
mahphalke | 1:48914f9593f1 | 1696 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1697 | calibration_error = true; |
mahphalke | 1:48914f9593f1 | 1698 | break; |
mahphalke | 1:48914f9593f1 | 1699 | } |
mahphalke | 1:48914f9593f1 | 1700 | } |
mahphalke | 1:48914f9593f1 | 1701 | } |
mahphalke | 1:48914f9593f1 | 1702 | |
mahphalke | 1:48914f9593f1 | 1703 | // Need to restore the channels that were disabled during calibration |
mahphalke | 1:48914f9593f1 | 1704 | for (chn_cnt = 0 ; chn_cnt < NUMBER_OF_CHANNELS ; chn_cnt++) { |
mahphalke | 1:48914f9593f1 | 1705 | if (chn_mask & (1 << chn_cnt)) { |
mahphalke | 1:48914f9593f1 | 1706 | // Get the pointer to channel register |
mahphalke | 1:48914f9593f1 | 1707 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt); |
mahphalke | 1:48914f9593f1 | 1708 | device_chnmap_reg->value |= AD717X_CHMAP_REG_CH_EN; |
mahphalke | 1:48914f9593f1 | 1709 | |
mahphalke | 1:48914f9593f1 | 1710 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1711 | // continue with other channels |
mahphalke | 1:48914f9593f1 | 1712 | } |
mahphalke | 1:48914f9593f1 | 1713 | } |
mahphalke | 1:48914f9593f1 | 1714 | } |
mahphalke | 1:48914f9593f1 | 1715 | |
mahphalke | 1:48914f9593f1 | 1716 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 1717 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 1718 | } |
mahphalke | 1:48914f9593f1 | 1719 | |
mahphalke | 1:48914f9593f1 | 1720 | |
mahphalke | 3:6c7324997606 | 1721 | /*! |
mahphalke | 3:6c7324997606 | 1722 | * @brief Handle the menu to select input type for open wire detection |
mahphalke | 3:6c7324997606 | 1723 | * @param User selected analog input type |
mahphalke | 3:6c7324997606 | 1724 | * @return MENU_DONE |
mahphalke | 3:6c7324997606 | 1725 | */ |
mahphalke | 3:6c7324997606 | 1726 | int32_t menu_input_type_selection(uint32_t user_input_type) |
mahphalke | 3:6c7324997606 | 1727 | { |
mahphalke | 3:6c7324997606 | 1728 | // Save the analog input type, for channel and input pair selections |
mahphalke | 3:6c7324997606 | 1729 | analog_input_type = user_input_type; |
mahphalke | 3:6c7324997606 | 1730 | |
mahphalke | 3:6c7324997606 | 1731 | return MENU_DONE; |
mahphalke | 3:6c7324997606 | 1732 | } |
mahphalke | 3:6c7324997606 | 1733 | |
mahphalke | 3:6c7324997606 | 1734 | |
mahphalke | 3:6c7324997606 | 1735 | /*! |
mahphalke | 3:6c7324997606 | 1736 | * @brief Handle the menu to select channel pair for open wire detection |
mahphalke | 3:6c7324997606 | 1737 | * @param User selected channel pair |
mahphalke | 3:6c7324997606 | 1738 | * @return MENU_DONE |
mahphalke | 3:6c7324997606 | 1739 | */ |
mahphalke | 3:6c7324997606 | 1740 | int32_t menu_select_chn_pair(uint32_t user_channel_pair) |
mahphalke | 3:6c7324997606 | 1741 | { |
mahphalke | 3:6c7324997606 | 1742 | // Save the channel pair for configuring channel map register |
mahphalke | 3:6c7324997606 | 1743 | channel_pair = user_channel_pair; |
mahphalke | 3:6c7324997606 | 1744 | |
mahphalke | 3:6c7324997606 | 1745 | return MENU_DONE; |
mahphalke | 3:6c7324997606 | 1746 | } |
mahphalke | 3:6c7324997606 | 1747 | |
mahphalke | 3:6c7324997606 | 1748 | |
mahphalke | 3:6c7324997606 | 1749 | /*! |
mahphalke | 3:6c7324997606 | 1750 | * @brief Handle the menu to select input pair for open wire detection |
mahphalke | 3:6c7324997606 | 1751 | * @param User selected analog input |
mahphalke | 3:6c7324997606 | 1752 | * @return MENU_DONE |
mahphalke | 3:6c7324997606 | 1753 | */ |
mahphalke | 3:6c7324997606 | 1754 | int32_t menu_select_input_pair(uint32_t user_analog_input) |
mahphalke | 3:6c7324997606 | 1755 | { |
mahphalke | 3:6c7324997606 | 1756 | uint8_t current_channel; // current channel |
mahphalke | 3:6c7324997606 | 1757 | ad717x_st_reg *device_chnmap_reg; // pointer to channel map register |
mahphalke | 3:6c7324997606 | 1758 | ad717x_st_reg *device_mode_reg; // pointer to device mode register |
mahphalke | 3:6c7324997606 | 1759 | bool input_pair_select_error = false; // Error in input pair selection |
mahphalke | 3:6c7324997606 | 1760 | |
mahphalke | 3:6c7324997606 | 1761 | if (input_pair_select_error == false) { |
mahphalke | 3:6c7324997606 | 1762 | // Set the configurations for channel pair |
mahphalke | 3:6c7324997606 | 1763 | for (uint8_t chn_cnt = 0; chn_cnt < 2; chn_cnt++) { |
mahphalke | 3:6c7324997606 | 1764 | if (chn_cnt == 0) { |
mahphalke | 3:6c7324997606 | 1765 | // Get the first channel from the pair |
mahphalke | 3:6c7324997606 | 1766 | current_channel = (channel_pair >> CHN_PAIR_OFFSET); |
mahphalke | 3:6c7324997606 | 1767 | } else { |
mahphalke | 3:6c7324997606 | 1768 | // Get the second channel from the pair |
mahphalke | 3:6c7324997606 | 1769 | current_channel = (channel_pair & CHN_PAIR_MASK); |
mahphalke | 3:6c7324997606 | 1770 | } |
mahphalke | 3:6c7324997606 | 1771 | |
mahphalke | 3:6c7324997606 | 1772 | // Get the pointer to channel map register structure |
mahphalke | 3:6c7324997606 | 1773 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, |
mahphalke | 3:6c7324997606 | 1774 | AD717X_CHMAP0_REG + current_channel); |
mahphalke | 3:6c7324997606 | 1775 | |
mahphalke | 3:6c7324997606 | 1776 | // Load the setup 0 value |
mahphalke | 3:6c7324997606 | 1777 | device_chnmap_reg->value = |
mahphalke | 3:6c7324997606 | 1778 | ((device_chnmap_reg->value & ~AD717X_CHMAP_REG_SETUP_SEL_MSK) | |
mahphalke | 3:6c7324997606 | 1779 | AD717X_CHMAP_REG_SETUP_SEL(0)); |
mahphalke | 3:6c7324997606 | 1780 | |
mahphalke | 3:6c7324997606 | 1781 | // Select the analog input |
mahphalke | 3:6c7324997606 | 1782 | device_chnmap_reg->value = |
mahphalke | 3:6c7324997606 | 1783 | ((device_chnmap_reg->value & ~AD4111_CHMAP_REG_INPUT_MSK) | |
mahphalke | 3:6c7324997606 | 1784 | AD4111_CHMAP_REG_INPUT(user_analog_input)); |
mahphalke | 3:6c7324997606 | 1785 | |
mahphalke | 3:6c7324997606 | 1786 | // Enable the channel |
mahphalke | 3:6c7324997606 | 1787 | device_chnmap_reg->value |= AD717X_CHMAP_REG_CH_EN; |
mahphalke | 3:6c7324997606 | 1788 | |
mahphalke | 3:6c7324997606 | 1789 | device_mode_reg = AD717X_GetReg(pad717x_dev, AD717X_ADCMODE_REG); |
mahphalke | 3:6c7324997606 | 1790 | device_mode_reg->value = |
mahphalke | 3:6c7324997606 | 1791 | ((device_mode_reg->value & ~AD717X_ADCMODE_REG_MODE_MSK) | |
mahphalke | 3:6c7324997606 | 1792 | AD717X_ADCMODE_REG_MODE(SINGLE_CONVERISION)); |
mahphalke | 3:6c7324997606 | 1793 | |
mahphalke | 3:6c7324997606 | 1794 | if (AD717X_WriteRegister(pad717x_dev, AD717X_ADCMODE_REG) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1795 | input_pair_select_error = true; |
mahphalke | 3:6c7324997606 | 1796 | } |
mahphalke | 3:6c7324997606 | 1797 | |
mahphalke | 3:6c7324997606 | 1798 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 3:6c7324997606 | 1799 | AD717X_CHMAP0_REG + current_channel) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1800 | input_pair_select_error = true; |
mahphalke | 3:6c7324997606 | 1801 | break; |
mahphalke | 3:6c7324997606 | 1802 | } |
mahphalke | 3:6c7324997606 | 1803 | |
mahphalke | 3:6c7324997606 | 1804 | if (AD717X_WaitForReady(pad717x_dev, 10000) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1805 | input_pair_select_error = true; |
mahphalke | 3:6c7324997606 | 1806 | break; |
mahphalke | 3:6c7324997606 | 1807 | } |
mahphalke | 3:6c7324997606 | 1808 | |
mahphalke | 3:6c7324997606 | 1809 | if (AD717X_ReadData(pad717x_dev, |
mahphalke | 3:6c7324997606 | 1810 | &open_wire_detect_sample_data[chn_cnt]) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1811 | input_pair_select_error = true; |
mahphalke | 3:6c7324997606 | 1812 | break; |
mahphalke | 3:6c7324997606 | 1813 | } |
mahphalke | 3:6c7324997606 | 1814 | |
mahphalke | 3:6c7324997606 | 1815 | // Disable the current channel |
mahphalke | 3:6c7324997606 | 1816 | device_chnmap_reg->value &= (~AD717X_CHMAP_REG_CH_EN); |
mahphalke | 3:6c7324997606 | 1817 | |
mahphalke | 3:6c7324997606 | 1818 | if (AD717X_WriteRegister(pad717x_dev, |
mahphalke | 3:6c7324997606 | 1819 | AD717X_CHMAP0_REG + current_channel) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1820 | input_pair_select_error = true; |
mahphalke | 3:6c7324997606 | 1821 | break; |
mahphalke | 3:6c7324997606 | 1822 | } |
mahphalke | 3:6c7324997606 | 1823 | } |
mahphalke | 3:6c7324997606 | 1824 | } |
mahphalke | 3:6c7324997606 | 1825 | |
mahphalke | 3:6c7324997606 | 1826 | if (input_pair_select_error == true) { |
mahphalke | 3:6c7324997606 | 1827 | printf("\tError in analog input selection!!" EOL); |
mahphalke | 3:6c7324997606 | 1828 | adi_press_any_key_to_continue(); |
mahphalke | 3:6c7324997606 | 1829 | } |
mahphalke | 3:6c7324997606 | 1830 | |
mahphalke | 3:6c7324997606 | 1831 | return MENU_DONE; |
mahphalke | 3:6c7324997606 | 1832 | } |
mahphalke | 3:6c7324997606 | 1833 | |
mahphalke | 3:6c7324997606 | 1834 | |
mahphalke | 3:6c7324997606 | 1835 | /*! |
mahphalke | 3:6c7324997606 | 1836 | * @brief Handle the menu to perform open wire detection |
mahphalke | 3:6c7324997606 | 1837 | * @param menu_id- (Optional parameter) |
mahphalke | 3:6c7324997606 | 1838 | * @return MENU_CONTINUE |
mahphalke | 3:6c7324997606 | 1839 | */ |
mahphalke | 3:6c7324997606 | 1840 | int32_t menu_open_wire_detection(uint32_t menu_id) |
mahphalke | 3:6c7324997606 | 1841 | { |
mahphalke | 3:6c7324997606 | 1842 | ad717x_st_reg *device_chnmap_reg; // pointer to channel map register |
mahphalke | 3:6c7324997606 | 1843 | ad717x_st_reg *device_gpiocon_reg; // pointer to gpio control register |
mahphalke | 3:6c7324997606 | 1844 | ad717x_st_reg *device_setupcon_reg; // pointer to setup control register |
mahphalke | 3:6c7324997606 | 1845 | uint8_t chn_cnt; // Current channel count |
mahphalke | 3:6c7324997606 | 1846 | uint8_t chn_mask = 0; // Channel enable/disable mask |
mahphalke | 3:6c7324997606 | 1847 | bool open_wire_detection_error = false; // Open wire detection error flag |
mahphalke | 3:6c7324997606 | 1848 | |
mahphalke | 3:6c7324997606 | 1849 | // Disable all the enabled channels before starting open wire detection |
mahphalke | 3:6c7324997606 | 1850 | for (chn_cnt = 0; chn_cnt < NUMBER_OF_CHANNELS; chn_cnt++) { |
mahphalke | 3:6c7324997606 | 1851 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt); |
mahphalke | 3:6c7324997606 | 1852 | |
mahphalke | 3:6c7324997606 | 1853 | if (AD717X_ReadRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1854 | open_wire_detection_error = true; |
mahphalke | 3:6c7324997606 | 1855 | break; |
mahphalke | 3:6c7324997606 | 1856 | } |
mahphalke | 3:6c7324997606 | 1857 | |
mahphalke | 3:6c7324997606 | 1858 | if (device_chnmap_reg->value & AD717X_CHMAP_REG_CH_EN) { |
mahphalke | 3:6c7324997606 | 1859 | // Save enabled channel |
mahphalke | 3:6c7324997606 | 1860 | chn_mask |= (1 << chn_cnt); |
mahphalke | 3:6c7324997606 | 1861 | |
mahphalke | 3:6c7324997606 | 1862 | // Disable the curent channel |
mahphalke | 3:6c7324997606 | 1863 | device_chnmap_reg->value &= (~AD717X_CHMAP_REG_CH_EN); |
mahphalke | 3:6c7324997606 | 1864 | |
mahphalke | 3:6c7324997606 | 1865 | // Write to ADC channel register |
mahphalke | 3:6c7324997606 | 1866 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1867 | open_wire_detection_error = true; |
mahphalke | 3:6c7324997606 | 1868 | break; |
mahphalke | 3:6c7324997606 | 1869 | } |
mahphalke | 3:6c7324997606 | 1870 | } |
mahphalke | 3:6c7324997606 | 1871 | } |
mahphalke | 3:6c7324997606 | 1872 | |
mahphalke | 3:6c7324997606 | 1873 | if (open_wire_detection_error == false) { |
mahphalke | 3:6c7324997606 | 1874 | do { |
mahphalke | 3:6c7324997606 | 1875 | // Enable the open wire detection on voltage channels |
mahphalke | 3:6c7324997606 | 1876 | device_gpiocon_reg = AD717X_GetReg(pad717x_dev, AD717X_GPIOCON_REG); |
mahphalke | 3:6c7324997606 | 1877 | |
mahphalke | 3:6c7324997606 | 1878 | if (AD717X_ReadRegister(pad717x_dev, AD717X_GPIOCON_REG) == SUCCESS) { |
mahphalke | 3:6c7324997606 | 1879 | device_gpiocon_reg->value |= (AD4111_GPIOCON_REG_OP_EN0_1 | |
mahphalke | 3:6c7324997606 | 1880 | AD4111_GPIOCON_REG_OW_EN); |
mahphalke | 3:6c7324997606 | 1881 | |
mahphalke | 3:6c7324997606 | 1882 | if (AD717X_WriteRegister(pad717x_dev, AD717X_GPIOCON_REG) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1883 | open_wire_detection_error = true; |
mahphalke | 3:6c7324997606 | 1884 | break; |
mahphalke | 3:6c7324997606 | 1885 | } |
mahphalke | 3:6c7324997606 | 1886 | } else { |
mahphalke | 3:6c7324997606 | 1887 | break; |
mahphalke | 3:6c7324997606 | 1888 | } |
mahphalke | 3:6c7324997606 | 1889 | |
mahphalke | 3:6c7324997606 | 1890 | // Configure the setup control 0 register |
mahphalke | 3:6c7324997606 | 1891 | device_setupcon_reg = AD717X_GetReg(pad717x_dev, AD717X_SETUPCON0_REG); |
mahphalke | 3:6c7324997606 | 1892 | |
mahphalke | 3:6c7324997606 | 1893 | if (AD717X_ReadRegister(pad717x_dev, AD717X_SETUPCON0_REG) == SUCCESS) { |
mahphalke | 3:6c7324997606 | 1894 | device_setupcon_reg->value |= (AD717X_SETUP_CONF_REG_AINBUF_P | |
mahphalke | 3:6c7324997606 | 1895 | AD717X_SETUP_CONF_REG_AINBUF_N | |
mahphalke | 3:6c7324997606 | 1896 | AD717X_SETUP_CONF_REG_BI_UNIPOLAR); |
mahphalke | 3:6c7324997606 | 1897 | |
mahphalke | 3:6c7324997606 | 1898 | device_setupcon_reg->value = ((device_setupcon_reg->value & |
mahphalke | 3:6c7324997606 | 1899 | ~AD717X_SETUP_CONF_REG_REF_SEL_MSK) | |
mahphalke | 3:6c7324997606 | 1900 | AD717X_SETUP_CONF_REG_REF_SEL(EXTERNAL)); |
mahphalke | 3:6c7324997606 | 1901 | |
mahphalke | 3:6c7324997606 | 1902 | if (AD717X_WriteRegister(pad717x_dev, AD717X_SETUPCON0_REG) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1903 | open_wire_detection_error = true; |
mahphalke | 3:6c7324997606 | 1904 | break; |
mahphalke | 3:6c7324997606 | 1905 | } |
mahphalke | 3:6c7324997606 | 1906 | } else { |
mahphalke | 3:6c7324997606 | 1907 | break; |
mahphalke | 3:6c7324997606 | 1908 | } |
mahphalke | 3:6c7324997606 | 1909 | } while (0); |
mahphalke | 3:6c7324997606 | 1910 | |
mahphalke | 3:6c7324997606 | 1911 | |
mahphalke | 3:6c7324997606 | 1912 | if (open_wire_detection_error == false) { |
mahphalke | 3:6c7324997606 | 1913 | // Select the analog input type |
mahphalke | 3:6c7324997606 | 1914 | adi_do_console_menu(&open_wire_detect_input_type_menu); |
mahphalke | 3:6c7324997606 | 1915 | |
mahphalke | 3:6c7324997606 | 1916 | if (analog_input_type == SINGLE_ENDED_INPUT) { |
mahphalke | 3:6c7324997606 | 1917 | // Select the single ended input channel pair |
mahphalke | 3:6c7324997606 | 1918 | adi_do_console_menu(&open_wire_detect_se_channel_menu); |
mahphalke | 3:6c7324997606 | 1919 | |
mahphalke | 3:6c7324997606 | 1920 | // Select the single ended analog input pair |
mahphalke | 3:6c7324997606 | 1921 | adi_do_console_menu(&open_wire_detect_se_analog_input_menu); |
mahphalke | 3:6c7324997606 | 1922 | } else { |
mahphalke | 3:6c7324997606 | 1923 | // Select the differential ended input channel pair |
mahphalke | 3:6c7324997606 | 1924 | adi_do_console_menu(&open_wire_detect_de_channel_menu); |
mahphalke | 3:6c7324997606 | 1925 | |
mahphalke | 3:6c7324997606 | 1926 | // Select the differential ended analog input pair |
mahphalke | 3:6c7324997606 | 1927 | adi_do_console_menu(&open_wire_detect_de_analog_input_menu); |
mahphalke | 3:6c7324997606 | 1928 | } |
mahphalke | 3:6c7324997606 | 1929 | |
mahphalke | 3:6c7324997606 | 1930 | printf(EOL "\tChannel %d = %d" EOL, (channel_pair >> CHN_PAIR_OFFSET), |
mahphalke | 3:6c7324997606 | 1931 | open_wire_detect_sample_data[0]); |
mahphalke | 3:6c7324997606 | 1932 | |
mahphalke | 3:6c7324997606 | 1933 | printf(EOL "\tChannel %d = %d" EOL, (channel_pair & CHN_PAIR_MASK), |
mahphalke | 3:6c7324997606 | 1934 | open_wire_detect_sample_data[1]); |
mahphalke | 3:6c7324997606 | 1935 | |
mahphalke | 3:6c7324997606 | 1936 | // Check for open wire detection by measuring offset of channel pair sampled data |
mahphalke | 3:6c7324997606 | 1937 | if (abs(open_wire_detect_sample_data[0] - open_wire_detect_sample_data[1]) > |
mahphalke | 3:6c7324997606 | 1938 | OPEN_WIRE_DETECT_THRESHOLD) { |
mahphalke | 3:6c7324997606 | 1939 | printf(EOL "\tOpen Wire Detected on Selected Input Pair!!" EOL); |
mahphalke | 3:6c7324997606 | 1940 | } else { |
mahphalke | 3:6c7324997606 | 1941 | printf(EOL "\tNo Open Wire Detected on Selected Input Pair..." EOL); |
mahphalke | 3:6c7324997606 | 1942 | } |
mahphalke | 3:6c7324997606 | 1943 | } else { |
mahphalke | 3:6c7324997606 | 1944 | printf(EOL "\tError in Open Wire Detection!!" EOL); |
mahphalke | 3:6c7324997606 | 1945 | } |
mahphalke | 3:6c7324997606 | 1946 | } else { |
mahphalke | 3:6c7324997606 | 1947 | printf(EOL "\tError in Open Wire Detection!!" EOL); |
mahphalke | 3:6c7324997606 | 1948 | } |
mahphalke | 3:6c7324997606 | 1949 | |
mahphalke | 3:6c7324997606 | 1950 | // Need to restore the channels that were disabled during open wire detection |
mahphalke | 3:6c7324997606 | 1951 | for (chn_cnt = 0 ; chn_cnt < NUMBER_OF_CHANNELS ; chn_cnt++) { |
mahphalke | 3:6c7324997606 | 1952 | if (chn_mask & (1 << chn_cnt)) { |
mahphalke | 3:6c7324997606 | 1953 | // Get the pointer to channel register |
mahphalke | 3:6c7324997606 | 1954 | device_chnmap_reg = AD717X_GetReg(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt); |
mahphalke | 3:6c7324997606 | 1955 | |
mahphalke | 3:6c7324997606 | 1956 | device_chnmap_reg->value |= AD717X_CHMAP_REG_CH_EN; |
mahphalke | 3:6c7324997606 | 1957 | |
mahphalke | 3:6c7324997606 | 1958 | if (AD717X_WriteRegister(pad717x_dev, AD717X_CHMAP0_REG + chn_cnt) != SUCCESS) { |
mahphalke | 3:6c7324997606 | 1959 | continue; |
mahphalke | 3:6c7324997606 | 1960 | } |
mahphalke | 3:6c7324997606 | 1961 | } |
mahphalke | 3:6c7324997606 | 1962 | } |
mahphalke | 3:6c7324997606 | 1963 | |
mahphalke | 3:6c7324997606 | 1964 | adi_press_any_key_to_continue(); |
mahphalke | 3:6c7324997606 | 1965 | return MENU_CONTINUE; |
mahphalke | 3:6c7324997606 | 1966 | } |
mahphalke | 3:6c7324997606 | 1967 | |
mahphalke | 3:6c7324997606 | 1968 | |
mahphalke | 1:48914f9593f1 | 1969 | /* @brief Console menu to read/write the adc register |
mahphalke | 3:6c7324997606 | 1970 | * @param Read/Write ID/Operation |
mahphalke | 3:6c7324997606 | 1971 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 1972 | **/ |
mahphalke | 1:48914f9593f1 | 1973 | int32_t menu_rw_ad717x_register(uint32_t rw_id) |
mahphalke | 1:48914f9593f1 | 1974 | { |
mahphalke | 1:48914f9593f1 | 1975 | uint32_t reg_address; |
mahphalke | 1:48914f9593f1 | 1976 | uint32_t reg_data; |
mahphalke | 1:48914f9593f1 | 1977 | ad717x_st_reg *device_data_reg; // Pointer to data register |
mahphalke | 1:48914f9593f1 | 1978 | |
mahphalke | 1:48914f9593f1 | 1979 | printf(EOL "\tEnter the register address (in hex): "); |
mahphalke | 1:48914f9593f1 | 1980 | reg_address = adi_get_hex_integer(sizeof(reg_address)); |
mahphalke | 1:48914f9593f1 | 1981 | |
mahphalke | 1:48914f9593f1 | 1982 | // Get the pointer to data register |
mahphalke | 1:48914f9593f1 | 1983 | device_data_reg = AD717X_GetReg(pad717x_dev, reg_address); |
mahphalke | 1:48914f9593f1 | 1984 | |
mahphalke | 1:48914f9593f1 | 1985 | if ((uint32_t)DEVICE_REG_READ_ID == rw_id) { |
mahphalke | 1:48914f9593f1 | 1986 | // Read from ADC channel register |
mahphalke | 1:48914f9593f1 | 1987 | if (AD717X_ReadRegister(pad717x_dev, reg_address) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 1988 | printf(EOL "Error reading setup!!" EOL); |
mahphalke | 1:48914f9593f1 | 1989 | } else { |
mahphalke | 1:48914f9593f1 | 1990 | reg_data = device_data_reg->value; |
mahphalke | 1:48914f9593f1 | 1991 | printf(EOL "\tRead Value: 0x%lx", reg_data); |
mahphalke | 1:48914f9593f1 | 1992 | } |
mahphalke | 1:48914f9593f1 | 1993 | } else { |
mahphalke | 1:48914f9593f1 | 1994 | printf(EOL "\tEnter the register data (in hex): "); |
mahphalke | 1:48914f9593f1 | 1995 | reg_data = adi_get_hex_integer(sizeof(reg_data)); |
mahphalke | 1:48914f9593f1 | 1996 | |
mahphalke | 1:48914f9593f1 | 1997 | device_data_reg->value = reg_data; |
mahphalke | 1:48914f9593f1 | 1998 | |
mahphalke | 1:48914f9593f1 | 1999 | if (AD717X_WriteRegister(pad717x_dev, reg_address) != SUCCESS) { |
mahphalke | 1:48914f9593f1 | 2000 | printf(EOL "\tError in writing adc register!!" EOL); |
mahphalke | 1:48914f9593f1 | 2001 | } else { |
mahphalke | 1:48914f9593f1 | 2002 | printf(EOL "\tWrite Successful..." EOL); |
mahphalke | 1:48914f9593f1 | 2003 | } |
mahphalke | 1:48914f9593f1 | 2004 | } |
mahphalke | 1:48914f9593f1 | 2005 | |
mahphalke | 1:48914f9593f1 | 2006 | adi_press_any_key_to_continue(); |
mahphalke | 1:48914f9593f1 | 2007 | return MENU_CONTINUE; |
mahphalke | 1:48914f9593f1 | 2008 | } |
mahphalke | 1:48914f9593f1 | 2009 | |
mahphalke | 1:48914f9593f1 | 2010 | |
mahphalke | 1:48914f9593f1 | 2011 | /*! |
mahphalke | 1:48914f9593f1 | 2012 | * @brief Handle the menu to read/write device registers |
mahphalke | 3:6c7324997606 | 2013 | * @param menu_id- (Optional parameter) |
mahphalke | 1:48914f9593f1 | 2014 | * @return MENU_CONTINUE |
mahphalke | 1:48914f9593f1 | 2015 | */ |
mahphalke | 1:48914f9593f1 | 2016 | int32_t menu_read_write_device_regs(uint32_t menu_id) |
mahphalke | 1:48914f9593f1 | 2017 | { |
mahphalke | 1:48914f9593f1 | 2018 | return (adi_do_console_menu(®_read_write_menu)); |
mahphalke | 1:48914f9593f1 | 2019 | } |