![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Example program for CN0535-FMCZ.
Dependencies: platform_drivers AD77681
main.cpp@2:998f1de78dae, 2021-04-12 (annotated)
- Committer:
- jngarlitos
- Date:
- Mon Apr 12 07:44:03 2021 +0000
- Revision:
- 2:998f1de78dae
- Parent:
- 1:f3b5e79a8488
Update license of EVAL-CN0535-FMCZ example program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jngarlitos | 2:998f1de78dae | 1 | /*! |
jngarlitos | 2:998f1de78dae | 2 | ***************************************************************************** |
jngarlitos | 2:998f1de78dae | 3 | *@file: main.c |
jngarlitos | 2:998f1de78dae | 4 | * |
jngarlitos | 2:998f1de78dae | 5 | *@brief: main module for EVAL-CN0535-FMCZ example program |
jngarlitos | 2:998f1de78dae | 6 | * |
jngarlitos | 2:998f1de78dae | 7 | *@details: main module for EVAL-CN0535-FMCZ example program |
jngarlitos | 2:998f1de78dae | 8 | *----------------------------------------------------------------------------- |
jngarlitos | 2:998f1de78dae | 9 | * |
jngarlitos | 2:998f1de78dae | 10 | Copyright (c) 2021 Analog Devices, Inc. |
jngarlitos | 2:998f1de78dae | 11 | All rights reserved. |
jngarlitos | 2:998f1de78dae | 12 | |
jngarlitos | 2:998f1de78dae | 13 | This software is proprietary to Analog Devices, Inc. and its licensors. |
jngarlitos | 2:998f1de78dae | 14 | By using this software you agree to the terms of the associated |
jngarlitos | 2:998f1de78dae | 15 | Analog Devices Software License Agreement. |
jngarlitos | 2:998f1de78dae | 16 | *****************************************************************************/ |
jngarlitos | 2:998f1de78dae | 17 | |
jngarlitos | 2:998f1de78dae | 18 | /*** includes ***/ |
jngarlitos | 1:f3b5e79a8488 | 19 | #include "mbed.h" |
jngarlitos | 1:f3b5e79a8488 | 20 | #include "main.h" |
jngarlitos | 1:f3b5e79a8488 | 21 | #include "app_config.h" |
jngarlitos | 1:f3b5e79a8488 | 22 | #include "cn0535_init_params.h" |
jngarlitos | 2:998f1de78dae | 23 | |
jngarlitos | 2:998f1de78dae | 24 | //Uncomment this to print CRC/XOR |
jngarlitos | 2:998f1de78dae | 25 | //#define CRC_DEBUG |
jngarlitos | 1:f3b5e79a8488 | 26 | |
jngarlitos | 1:f3b5e79a8488 | 27 | // Descriptor of the main device - the ADC AD7768-1 |
jngarlitos | 1:f3b5e79a8488 | 28 | ad77681_dev *device; |
jngarlitos | 1:f3b5e79a8488 | 29 | // Descriptor of the ADC AD7768-1 Status |
jngarlitos | 1:f3b5e79a8488 | 30 | ad77681_status_registers *current_status; |
jngarlitos | 1:f3b5e79a8488 | 31 | // Structure carying measured data, sampled by the ADC |
jngarlitos | 1:f3b5e79a8488 | 32 | adc_data measured_data; |
jngarlitos | 1:f3b5e79a8488 | 33 | |
jngarlitos | 1:f3b5e79a8488 | 34 | |
jngarlitos | 1:f3b5e79a8488 | 35 | // Initialize the serial object with TX and RX pins |
jngarlitos | 1:f3b5e79a8488 | 36 | Serial pc(USBTX, USBRX); |
jngarlitos | 1:f3b5e79a8488 | 37 | // Initialize the drdy pin as interrupt input |
jngarlitos | 1:f3b5e79a8488 | 38 | InterruptIn drdy(DRDY_PIN, PullNone); |
jngarlitos | 1:f3b5e79a8488 | 39 | // Initialize the adc_rst_pin pin as digital output |
jngarlitos | 1:f3b5e79a8488 | 40 | DigitalOut adc_rst(ADC_RST_PIN); |
jngarlitos | 1:f3b5e79a8488 | 41 | // Initialize the interrupt event variable |
jngarlitos | 1:f3b5e79a8488 | 42 | volatile bool int_event= false; |
jngarlitos | 1:f3b5e79a8488 | 43 | |
jngarlitos | 1:f3b5e79a8488 | 44 | |
jngarlitos | 1:f3b5e79a8488 | 45 | /* |
jngarlitos | 1:f3b5e79a8488 | 46 | * ADC data recteption interrupt from DRDY |
jngarlitos | 1:f3b5e79a8488 | 47 | * |
jngarlitos | 1:f3b5e79a8488 | 48 | * Data reception from the ADC using interrupt generated by the ADC's DRDY (Data Ready) pin |
jngarlitos | 1:f3b5e79a8488 | 49 | * Interrupt triggers falling edge of the active-high DRDY pulse |
jngarlitos | 1:f3b5e79a8488 | 50 | * DRDY pulse is generated by the ADC and frequency of the DRDY pulse depends on the ADC settings: |
jngarlitos | 1:f3b5e79a8488 | 51 | * |
jngarlitos | 1:f3b5e79a8488 | 52 | * DRDY frequency = MCLK / ( MCLK_DIV * FILTER_OSR ) |
jngarlitos | 1:f3b5e79a8488 | 53 | * |
jngarlitos | 1:f3b5e79a8488 | 54 | */ |
jngarlitos | 1:f3b5e79a8488 | 55 | void drdy_interrupt() |
jngarlitos | 1:f3b5e79a8488 | 56 | { |
jngarlitos | 1:f3b5e79a8488 | 57 | int_event = true; |
jngarlitos | 1:f3b5e79a8488 | 58 | |
jngarlitos | 1:f3b5e79a8488 | 59 | if (measured_data.count == measured_data.samples) { // Desired numer of samples has been taken, set everything back |
jngarlitos | 1:f3b5e79a8488 | 60 | drdy.disable_irq(); // Disable interrupt on DRDY pin |
jngarlitos | 1:f3b5e79a8488 | 61 | measured_data.finish = true; // Desired number of samples has been taken |
jngarlitos | 1:f3b5e79a8488 | 62 | measured_data.count = 0; // Set measured data counter to 0 |
jngarlitos | 1:f3b5e79a8488 | 63 | } |
jngarlitos | 1:f3b5e79a8488 | 64 | } |
jngarlitos | 1:f3b5e79a8488 | 65 | |
jngarlitos | 1:f3b5e79a8488 | 66 | |
jngarlitos | 1:f3b5e79a8488 | 67 | int main() |
jngarlitos | 1:f3b5e79a8488 | 68 | { |
jngarlitos | 1:f3b5e79a8488 | 69 | int32_t connected = FAILURE; |
jngarlitos | 1:f3b5e79a8488 | 70 | uint32_t menu; |
jngarlitos | 1:f3b5e79a8488 | 71 | |
jngarlitos | 1:f3b5e79a8488 | 72 | adc_hard_reset(); // Perform hard reset thru GPIO |
jngarlitos | 1:f3b5e79a8488 | 73 | connected = ad77681_setup(&device, init_params, ¤t_status); // SETUP and check connection |
jngarlitos | 1:f3b5e79a8488 | 74 | |
jngarlitos | 1:f3b5e79a8488 | 75 | if(connected == FAILURE) |
jngarlitos | 1:f3b5e79a8488 | 76 | go_to_error(); |
jngarlitos | 1:f3b5e79a8488 | 77 | |
jngarlitos | 1:f3b5e79a8488 | 78 | adc_gpio_init(); // Initilized SDP-K1 GPIOS |
jngarlitos | 1:f3b5e79a8488 | 79 | print_title(); |
jngarlitos | 1:f3b5e79a8488 | 80 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 81 | |
jngarlitos | 1:f3b5e79a8488 | 82 | //============ MAIN WHILE ==================== |
jngarlitos | 1:f3b5e79a8488 | 83 | while(1) { |
jngarlitos | 1:f3b5e79a8488 | 84 | if (pc.readable()) { // Settings menu SWITCH |
jngarlitos | 1:f3b5e79a8488 | 85 | getUserInput(&menu); |
jngarlitos | 1:f3b5e79a8488 | 86 | |
jngarlitos | 1:f3b5e79a8488 | 87 | switch (menu) { |
Kjansen45 | 0:ae894be1131f | 88 | |
jngarlitos | 1:f3b5e79a8488 | 89 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 90 | menu_1_set_pgia_gain_mode(); // Set PGIA gain or mode |
jngarlitos | 1:f3b5e79a8488 | 91 | break; |
jngarlitos | 1:f3b5e79a8488 | 92 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 93 | menu_2_set_fda_powermode(); // Set FDA power mode |
jngarlitos | 1:f3b5e79a8488 | 94 | break; |
jngarlitos | 1:f3b5e79a8488 | 95 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 96 | menu_3_set_ad77681_powermode(); // Set FDA power mode |
jngarlitos | 1:f3b5e79a8488 | 97 | break; |
jngarlitos | 1:f3b5e79a8488 | 98 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 99 | menu_4_set_ad77681_clock_divider(); // Set FDA power mode |
jngarlitos | 1:f3b5e79a8488 | 100 | break; |
jngarlitos | 1:f3b5e79a8488 | 101 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 102 | menu_5_set_ad77681_filter_type(); // Set ad7768-1 filter type |
jngarlitos | 1:f3b5e79a8488 | 103 | break; |
jngarlitos | 1:f3b5e79a8488 | 104 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 105 | menu_6_ad77681_AIN_buffers_controll(); // Set ad7768-1 AIN buffers |
jngarlitos | 1:f3b5e79a8488 | 106 | break; |
jngarlitos | 1:f3b5e79a8488 | 107 | case 7: |
jngarlitos | 1:f3b5e79a8488 | 108 | menu_7_ad77681_REF_buffers_controll(); // Set ad7768-1 REF buffers |
jngarlitos | 1:f3b5e79a8488 | 109 | break; |
jngarlitos | 1:f3b5e79a8488 | 110 | case 8: |
jngarlitos | 1:f3b5e79a8488 | 111 | menu_8_set_ad77681_vcm_setup(); // Set ad7768-1 VCM |
jngarlitos | 1:f3b5e79a8488 | 112 | break; |
jngarlitos | 1:f3b5e79a8488 | 113 | case 9: |
jngarlitos | 1:f3b5e79a8488 | 114 | menu_9_set_ad77681_data_output_mode(); // Set ad7768-1 Data output mode |
jngarlitos | 1:f3b5e79a8488 | 115 | break; |
jngarlitos | 1:f3b5e79a8488 | 116 | case 10: |
jngarlitos | 1:f3b5e79a8488 | 117 | menu_10_set_ad77681_diagnostic_mode(); // Set ad7768-1 Diagnostic mode |
jngarlitos | 1:f3b5e79a8488 | 118 | break; |
jngarlitos | 1:f3b5e79a8488 | 119 | case 11: |
jngarlitos | 1:f3b5e79a8488 | 120 | menu_11_set_ad77681_gains_offsets(); // Set ad7768-1 gain and offset |
jngarlitos | 1:f3b5e79a8488 | 121 | break; |
jngarlitos | 1:f3b5e79a8488 | 122 | case 12: |
jngarlitos | 1:f3b5e79a8488 | 123 | menu_12_ad77681_read_master_status(); // Read ad7768-1 Master status |
jngarlitos | 1:f3b5e79a8488 | 124 | break; |
jngarlitos | 1:f3b5e79a8488 | 125 | case 13: |
jngarlitos | 1:f3b5e79a8488 | 126 | menu_13_ad77681_read_register(); // Read ad7768-1 registers |
jngarlitos | 1:f3b5e79a8488 | 127 | break; |
jngarlitos | 1:f3b5e79a8488 | 128 | case 14: |
jngarlitos | 1:f3b5e79a8488 | 129 | menu_14_read_ad77681_single_conv_data(); // Read ad7768-1 single convertion data |
jngarlitos | 1:f3b5e79a8488 | 130 | break; |
jngarlitos | 1:f3b5e79a8488 | 131 | case 15: |
jngarlitos | 1:f3b5e79a8488 | 132 | menu_15_read_ad77681_continuous_data(); // Read ad7768-1 continuous read data |
jngarlitos | 1:f3b5e79a8488 | 133 | break; |
jngarlitos | 1:f3b5e79a8488 | 134 | case 16: |
jngarlitos | 1:f3b5e79a8488 | 135 | menu_16_print_ad77681_continuos_read_data();// Print ad7768-1 continuous read data |
jngarlitos | 1:f3b5e79a8488 | 136 | break; |
jngarlitos | 1:f3b5e79a8488 | 137 | case 17: |
jngarlitos | 1:f3b5e79a8488 | 138 | menu_17_ad77681_check_scratchpad(); // Perform ad7768-1 scratch pad check |
jngarlitos | 1:f3b5e79a8488 | 139 | break; |
jngarlitos | 1:f3b5e79a8488 | 140 | case 18: |
jngarlitos | 1:f3b5e79a8488 | 141 | menu_18_reset_ad77681_ADC(); // Reset ad7768-1 |
jngarlitos | 1:f3b5e79a8488 | 142 | break; |
jngarlitos | 1:f3b5e79a8488 | 143 | case 19: |
jngarlitos | 1:f3b5e79a8488 | 144 | menu_19_set_default_settings(); // Set Board defaul settings |
jngarlitos | 1:f3b5e79a8488 | 145 | break; |
jngarlitos | 1:f3b5e79a8488 | 146 | case 20: |
jngarlitos | 1:f3b5e79a8488 | 147 | menu_20_mclk_vref(); // Set ad7768-1 MCLK and Vref Values |
jngarlitos | 1:f3b5e79a8488 | 148 | break; |
jngarlitos | 1:f3b5e79a8488 | 149 | default: |
jngarlitos | 1:f3b5e79a8488 | 150 | pc.printf("Invalid option"); // Invalid Option |
jngarlitos | 1:f3b5e79a8488 | 151 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 152 | break; |
jngarlitos | 1:f3b5e79a8488 | 153 | } |
jngarlitos | 1:f3b5e79a8488 | 154 | } |
jngarlitos | 1:f3b5e79a8488 | 155 | } |
jngarlitos | 1:f3b5e79a8488 | 156 | } |
Kjansen45 | 0:ae894be1131f | 157 | |
jngarlitos | 1:f3b5e79a8488 | 158 | /** |
jngarlitos | 1:f3b5e79a8488 | 159 | * Error warning, in case of unsuccessfull SPI connection |
jngarlitos | 1:f3b5e79a8488 | 160 | * |
jngarlitos | 1:f3b5e79a8488 | 161 | */ |
jngarlitos | 1:f3b5e79a8488 | 162 | void static go_to_error() |
jngarlitos | 1:f3b5e79a8488 | 163 | { |
jngarlitos | 1:f3b5e79a8488 | 164 | int32_t connected = FAILURE; |
jngarlitos | 1:f3b5e79a8488 | 165 | |
jngarlitos | 1:f3b5e79a8488 | 166 | while (1) { |
jngarlitos | 1:f3b5e79a8488 | 167 | pc.printf("ERROR: NOT CONNECTED\nCHECK YOUR PHYSICAL CONNECTION\n\n"); // When not connected, keep showing error message |
jngarlitos | 1:f3b5e79a8488 | 168 | wait(5); |
jngarlitos | 1:f3b5e79a8488 | 169 | |
jngarlitos | 1:f3b5e79a8488 | 170 | connected = ad77681_setup(&device, init_params, ¤t_status); // Keep trying to connect |
jngarlitos | 1:f3b5e79a8488 | 171 | if (connected == SUCCESS) { |
jngarlitos | 1:f3b5e79a8488 | 172 | pc.printf("SUCCESSFULLY RECONNECTED\n\n"); // If successfull reading from scratchpad, init the ADC and go back |
jngarlitos | 1:f3b5e79a8488 | 173 | break; |
jngarlitos | 1:f3b5e79a8488 | 174 | } |
jngarlitos | 1:f3b5e79a8488 | 175 | } |
jngarlitos | 1:f3b5e79a8488 | 176 | } |
Kjansen45 | 0:ae894be1131f | 177 | |
jngarlitos | 1:f3b5e79a8488 | 178 | /** |
jngarlitos | 1:f3b5e79a8488 | 179 | * Print title |
jngarlitos | 1:f3b5e79a8488 | 180 | * |
jngarlitos | 1:f3b5e79a8488 | 181 | */ |
jngarlitos | 1:f3b5e79a8488 | 182 | void static print_title() |
jngarlitos | 1:f3b5e79a8488 | 183 | { |
jngarlitos | 1:f3b5e79a8488 | 184 | pc.printf("\n\r"); |
jngarlitos | 1:f3b5e79a8488 | 185 | pc.printf("****************************************************************\n"); |
jngarlitos | 1:f3b5e79a8488 | 186 | pc.printf("* CN0535 Demonstration Program -- (mbed) *\n"); |
jngarlitos | 1:f3b5e79a8488 | 187 | pc.printf("* *\n"); |
jngarlitos | 1:f3b5e79a8488 | 188 | pc.printf("* This program demonstrates Universal Measurement Platform *\n"); |
jngarlitos | 1:f3b5e79a8488 | 189 | pc.printf("* using the AD7768-1 Precision 24-bit sigma-delta AD converter *\n"); |
jngarlitos | 1:f3b5e79a8488 | 190 | pc.printf("* *\n"); |
jngarlitos | 1:f3b5e79a8488 | 191 | pc.printf("* Set the baud rate to 115200 select the newline terminator. *\n"); |
jngarlitos | 1:f3b5e79a8488 | 192 | pc.printf("****************************************************************\n"); |
jngarlitos | 1:f3b5e79a8488 | 193 | } |
jngarlitos | 1:f3b5e79a8488 | 194 | |
jngarlitos | 1:f3b5e79a8488 | 195 | /** |
jngarlitos | 1:f3b5e79a8488 | 196 | * Print main menu to console |
jngarlitos | 1:f3b5e79a8488 | 197 | * |
jngarlitos | 1:f3b5e79a8488 | 198 | */ |
jngarlitos | 1:f3b5e79a8488 | 199 | void static print_prompt() |
jngarlitos | 1:f3b5e79a8488 | 200 | { |
jngarlitos | 1:f3b5e79a8488 | 201 | pc.printf("\n\nCommand Summary:\n\n"); |
jngarlitos | 1:f3b5e79a8488 | 202 | pc.printf(" 1 - Set LTC6373 PGIA Gain/Mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 203 | pc.printf(" 2 - Set ADA4945 FDA Power Mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 204 | pc.printf(" 3 - Set AD7768-1 power mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 205 | pc.printf(" 4 - Set AD7768-1 MCLK clock divider\n"); |
jngarlitos | 1:f3b5e79a8488 | 206 | pc.printf(" 5 - Set AD7768-1 filter type\n"); |
jngarlitos | 1:f3b5e79a8488 | 207 | pc.printf(" 6 - Set AD7768-1 AIN buffers\n"); |
jngarlitos | 1:f3b5e79a8488 | 208 | pc.printf(" 7 - Set AD7768-1 REF buffers\n"); |
jngarlitos | 1:f3b5e79a8488 | 209 | pc.printf(" 8 - Set AD7768-1 VCM output\n"); |
jngarlitos | 1:f3b5e79a8488 | 210 | pc.printf(" 9 - Set AD7768-1 data output mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 211 | pc.printf(" 10 - Set AD7768-1 diagnostic mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 212 | pc.printf(" 11 - Set AD7768-1 Gains and Offsets\n"); |
jngarlitos | 1:f3b5e79a8488 | 213 | pc.printf(" 12 - Read AD7768-1 master status\n"); |
jngarlitos | 1:f3b5e79a8488 | 214 | pc.printf(" 13 - Read AD7768-1 desired register\n"); |
jngarlitos | 1:f3b5e79a8488 | 215 | pc.printf(" 14 - Read AD7768-1 data register\n"); |
jngarlitos | 1:f3b5e79a8488 | 216 | pc.printf(" 15 - Read AD7768-1 continuous mode data\n"); |
jngarlitos | 1:f3b5e79a8488 | 217 | pc.printf(" 16 - Print AD7768-1 Continuous mode measured data\n"); |
jngarlitos | 1:f3b5e79a8488 | 218 | pc.printf(" 17 - AD7768-1 Scratchpad Check \n"); |
jngarlitos | 1:f3b5e79a8488 | 219 | pc.printf(" 18 - Reset AD7768-1 ADC\n"); |
jngarlitos | 1:f3b5e79a8488 | 220 | pc.printf(" 19 - Set to Board Default Config\n"); |
jngarlitos | 1:f3b5e79a8488 | 221 | pc.printf(" 20 - Update Vref and MCLK values\n"); |
jngarlitos | 1:f3b5e79a8488 | 222 | pc.printf("\n\r"); |
jngarlitos | 1:f3b5e79a8488 | 223 | } |
Kjansen45 | 0:ae894be1131f | 224 | |
jngarlitos | 1:f3b5e79a8488 | 225 | /** |
jngarlitos | 1:f3b5e79a8488 | 226 | * Set LTC6373 PGIA Gain or Mode |
jngarlitos | 1:f3b5e79a8488 | 227 | * |
jngarlitos | 1:f3b5e79a8488 | 228 | */ |
jngarlitos | 1:f3b5e79a8488 | 229 | void static menu_1_set_pgia_gain_mode(void) |
jngarlitos | 1:f3b5e79a8488 | 230 | { |
jngarlitos | 1:f3b5e79a8488 | 231 | uint32_t new_pgia_gain; |
jngarlitos | 1:f3b5e79a8488 | 232 | uint8_t value; |
Kjansen45 | 0:ae894be1131f | 233 | |
jngarlitos | 1:f3b5e79a8488 | 234 | pc.printf(" Avaliable LT6373 PGIA Gains and Mode: \n"); |
jngarlitos | 1:f3b5e79a8488 | 235 | pc.printf(" 1 - Shutdown\n"); |
jngarlitos | 1:f3b5e79a8488 | 236 | pc.printf(" 2 - 0.25V/V\n"); |
jngarlitos | 1:f3b5e79a8488 | 237 | pc.printf(" 3 - 0.50V/V\n"); |
jngarlitos | 1:f3b5e79a8488 | 238 | pc.printf(" 4 - 1V/V\n"); |
jngarlitos | 1:f3b5e79a8488 | 239 | pc.printf(" 5 - 2V/V\n"); |
jngarlitos | 1:f3b5e79a8488 | 240 | pc.printf(" 6 - 4V/V\n"); |
jngarlitos | 1:f3b5e79a8488 | 241 | pc.printf(" 7 - 8V/V\n"); |
jngarlitos | 1:f3b5e79a8488 | 242 | pc.printf(" 8 - 16V/V\n"); |
jngarlitos | 1:f3b5e79a8488 | 243 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 244 | |
jngarlitos | 1:f3b5e79a8488 | 245 | getUserInput(&new_pgia_gain); |
jngarlitos | 1:f3b5e79a8488 | 246 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 247 | |
jngarlitos | 1:f3b5e79a8488 | 248 | switch (new_pgia_gain) { |
Kjansen45 | 0:ae894be1131f | 249 | |
jngarlitos | 1:f3b5e79a8488 | 250 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 251 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 252 | value |= 7; |
jngarlitos | 1:f3b5e79a8488 | 253 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 254 | pc.printf(" PGIA Shutdown selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 255 | break; |
jngarlitos | 1:f3b5e79a8488 | 256 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 257 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 258 | value |= 6; |
jngarlitos | 1:f3b5e79a8488 | 259 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 260 | pc.printf(" PGIA gain: 0.25V/V selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 261 | break; |
jngarlitos | 1:f3b5e79a8488 | 262 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 263 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 264 | value |= 5; |
jngarlitos | 1:f3b5e79a8488 | 265 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 266 | pc.printf(" PGIA gain: 0.5V/V selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 267 | break; |
jngarlitos | 1:f3b5e79a8488 | 268 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 269 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 270 | value |= 4; |
jngarlitos | 1:f3b5e79a8488 | 271 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 272 | pc.printf(" PGIA gain: 1V/V selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 273 | break; |
jngarlitos | 1:f3b5e79a8488 | 274 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 275 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 276 | value |= 3; |
jngarlitos | 1:f3b5e79a8488 | 277 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 278 | pc.printf(" PGIA gain: 2V/V selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 279 | break; |
jngarlitos | 1:f3b5e79a8488 | 280 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 281 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 282 | value |= 2; |
jngarlitos | 1:f3b5e79a8488 | 283 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 284 | pc.printf(" PGIA gain: 4V/V selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 285 | break; |
jngarlitos | 1:f3b5e79a8488 | 286 | case 7: |
jngarlitos | 1:f3b5e79a8488 | 287 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 288 | value |= 1; |
jngarlitos | 1:f3b5e79a8488 | 289 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 290 | pc.printf(" PGIA gain: 8V/V selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 291 | break; |
jngarlitos | 1:f3b5e79a8488 | 292 | case 8: |
jngarlitos | 1:f3b5e79a8488 | 293 | ad77681_spi_read_mask(device, AD77681_REG_GPIO_WRITE, AD77681_GPIO_WRITE_3_MSK, &value); |
jngarlitos | 1:f3b5e79a8488 | 294 | value |= 0; |
jngarlitos | 1:f3b5e79a8488 | 295 | ad77681_gpio_write(device,value, AD77681_ALL_GPIOS); |
jngarlitos | 1:f3b5e79a8488 | 296 | pc.printf(" PGIA gain: 16V/V selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 297 | break; |
jngarlitos | 1:f3b5e79a8488 | 298 | default: |
jngarlitos | 1:f3b5e79a8488 | 299 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 300 | break; |
jngarlitos | 1:f3b5e79a8488 | 301 | } |
jngarlitos | 1:f3b5e79a8488 | 302 | print_prompt(); |
Kjansen45 | 0:ae894be1131f | 303 | } |
Kjansen45 | 0:ae894be1131f | 304 | |
jngarlitos | 1:f3b5e79a8488 | 305 | /** |
jngarlitos | 1:f3b5e79a8488 | 306 | * Set ADA4945 FDA Mode |
jngarlitos | 1:f3b5e79a8488 | 307 | * |
jngarlitos | 1:f3b5e79a8488 | 308 | */ |
jngarlitos | 1:f3b5e79a8488 | 309 | void static menu_2_set_fda_powermode(void) |
jngarlitos | 1:f3b5e79a8488 | 310 | { |
jngarlitos | 1:f3b5e79a8488 | 311 | uint32_t new_fda_powermode; |
jngarlitos | 1:f3b5e79a8488 | 312 | uint8_t value; |
jngarlitos | 1:f3b5e79a8488 | 313 | |
jngarlitos | 1:f3b5e79a8488 | 314 | pc.printf(" Avaliable LT6373 PGIA Gains and Mode: \n"); |
jngarlitos | 1:f3b5e79a8488 | 315 | pc.printf(" 1 - Full Power Mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 316 | pc.printf(" 2 - Low Power Moden"); |
jngarlitos | 1:f3b5e79a8488 | 317 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 318 | |
jngarlitos | 1:f3b5e79a8488 | 319 | getUserInput(&new_fda_powermode); |
jngarlitos | 1:f3b5e79a8488 | 320 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 321 | |
jngarlitos | 1:f3b5e79a8488 | 322 | switch (new_fda_powermode) { |
jngarlitos | 1:f3b5e79a8488 | 323 | |
jngarlitos | 1:f3b5e79a8488 | 324 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 325 | value = 1; |
jngarlitos | 1:f3b5e79a8488 | 326 | ad77681_gpio_write(device,value, AD77681_GPIO3); |
jngarlitos | 1:f3b5e79a8488 | 327 | pc.printf(" FDA Full Power Mode selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 328 | break; |
jngarlitos | 1:f3b5e79a8488 | 329 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 330 | value = 0; |
jngarlitos | 1:f3b5e79a8488 | 331 | ad77681_gpio_write(device,value, AD77681_GPIO3); |
jngarlitos | 1:f3b5e79a8488 | 332 | pc.printf(" FDA Low Power Mode selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 333 | break; |
jngarlitos | 1:f3b5e79a8488 | 334 | default: |
jngarlitos | 1:f3b5e79a8488 | 335 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 336 | break; |
jngarlitos | 1:f3b5e79a8488 | 337 | } |
jngarlitos | 1:f3b5e79a8488 | 338 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 339 | } |
jngarlitos | 1:f3b5e79a8488 | 340 | |
jngarlitos | 1:f3b5e79a8488 | 341 | /** |
jngarlitos | 1:f3b5e79a8488 | 342 | * Set AD7768-1 power mode |
jngarlitos | 1:f3b5e79a8488 | 343 | * |
jngarlitos | 1:f3b5e79a8488 | 344 | */ |
jngarlitos | 1:f3b5e79a8488 | 345 | void static menu_3_set_ad77681_powermode(void) |
jngarlitos | 1:f3b5e79a8488 | 346 | { |
jngarlitos | 1:f3b5e79a8488 | 347 | uint32_t new_ad77681_pwr_mode; |
jngarlitos | 1:f3b5e79a8488 | 348 | |
jngarlitos | 1:f3b5e79a8488 | 349 | pc.printf(" Avaliable AD7768-1 power modes: \n"); |
jngarlitos | 1:f3b5e79a8488 | 350 | pc.printf(" 1 - Low power mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 351 | pc.printf(" 2 - Median power mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 352 | pc.printf(" 3 - Fast power mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 353 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 354 | |
jngarlitos | 1:f3b5e79a8488 | 355 | getUserInput(&new_ad77681_pwr_mode); |
jngarlitos | 1:f3b5e79a8488 | 356 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 357 | |
jngarlitos | 1:f3b5e79a8488 | 358 | switch (new_ad77681_pwr_mode) { |
jngarlitos | 1:f3b5e79a8488 | 359 | |
jngarlitos | 1:f3b5e79a8488 | 360 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 361 | ad77681_set_power_mode(device, AD77681_ECO); |
jngarlitos | 1:f3b5e79a8488 | 362 | pc.printf(" AD7768-1 Low power mode selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 363 | break; |
jngarlitos | 1:f3b5e79a8488 | 364 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 365 | ad77681_set_power_mode(device, AD77681_MEDIAN); |
jngarlitos | 1:f3b5e79a8488 | 366 | pc.printf(" AD7768-1 Median power mode selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 367 | break; |
jngarlitos | 1:f3b5e79a8488 | 368 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 369 | ad77681_set_power_mode(device, AD77681_FAST); |
jngarlitos | 1:f3b5e79a8488 | 370 | pc.printf(" AD7768-1 Fast power mode selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 371 | break; |
jngarlitos | 1:f3b5e79a8488 | 372 | default: |
jngarlitos | 1:f3b5e79a8488 | 373 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 374 | break; |
jngarlitos | 1:f3b5e79a8488 | 375 | } |
jngarlitos | 1:f3b5e79a8488 | 376 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 377 | } |
jngarlitos | 1:f3b5e79a8488 | 378 | |
jngarlitos | 1:f3b5e79a8488 | 379 | /** |
jngarlitos | 1:f3b5e79a8488 | 380 | * Set AD7768-1 clock divider |
jngarlitos | 1:f3b5e79a8488 | 381 | * |
jngarlitos | 1:f3b5e79a8488 | 382 | */ |
jngarlitos | 1:f3b5e79a8488 | 383 | void static menu_4_set_ad77681_clock_divider(void) |
jngarlitos | 1:f3b5e79a8488 | 384 | { |
jngarlitos | 1:f3b5e79a8488 | 385 | uint32_t new_ad77681_mclk_div; |
jngarlitos | 1:f3b5e79a8488 | 386 | |
jngarlitos | 1:f3b5e79a8488 | 387 | pc.printf(" Avaliable AD7768-1 MCLK divider options: \n"); |
jngarlitos | 1:f3b5e79a8488 | 388 | pc.printf(" 1 - MCLK/16\n"); |
jngarlitos | 1:f3b5e79a8488 | 389 | pc.printf(" 2 - MCLK/8\n"); |
jngarlitos | 1:f3b5e79a8488 | 390 | pc.printf(" 3 - MCLK/4\n"); |
jngarlitos | 1:f3b5e79a8488 | 391 | pc.printf(" 4 - MCLK/2\n"); |
jngarlitos | 1:f3b5e79a8488 | 392 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 393 | |
jngarlitos | 1:f3b5e79a8488 | 394 | getUserInput(&new_ad77681_mclk_div); |
jngarlitos | 1:f3b5e79a8488 | 395 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 396 | |
jngarlitos | 1:f3b5e79a8488 | 397 | switch (new_ad77681_mclk_div) { |
jngarlitos | 1:f3b5e79a8488 | 398 | |
jngarlitos | 1:f3b5e79a8488 | 399 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 400 | ad77681_set_mclk_div(device, AD77681_MCLK_DIV_16); |
jngarlitos | 1:f3b5e79a8488 | 401 | pc.printf(" AD7768-1 MCLK/16 selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 402 | break; |
jngarlitos | 1:f3b5e79a8488 | 403 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 404 | ad77681_set_mclk_div(device, AD77681_MCLK_DIV_8); |
jngarlitos | 1:f3b5e79a8488 | 405 | pc.printf(" AD7768-1 MCLK/8 selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 406 | break; |
jngarlitos | 1:f3b5e79a8488 | 407 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 408 | ad77681_set_mclk_div(device, AD77681_MCLK_DIV_4); |
jngarlitos | 1:f3b5e79a8488 | 409 | pc.printf(" AD7768-1 MCLK/4 selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 410 | break; |
jngarlitos | 1:f3b5e79a8488 | 411 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 412 | ad77681_set_mclk_div(device, AD77681_MCLK_DIV_2); |
jngarlitos | 1:f3b5e79a8488 | 413 | pc.printf(" AD7768-1 MCLK/2 selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 414 | break; |
jngarlitos | 1:f3b5e79a8488 | 415 | default: |
jngarlitos | 1:f3b5e79a8488 | 416 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 417 | break; |
jngarlitos | 1:f3b5e79a8488 | 418 | } |
jngarlitos | 1:f3b5e79a8488 | 419 | |
jngarlitos | 1:f3b5e79a8488 | 420 | ad77681_update_sample_rate(device); // Update the sample rate after changing the MCLK divider |
jngarlitos | 1:f3b5e79a8488 | 421 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 422 | } |
jngarlitos | 1:f3b5e79a8488 | 423 | |
jngarlitos | 1:f3b5e79a8488 | 424 | /** |
jngarlitos | 1:f3b5e79a8488 | 425 | * Set filter type |
jngarlitos | 1:f3b5e79a8488 | 426 | * |
jngarlitos | 1:f3b5e79a8488 | 427 | */ |
jngarlitos | 1:f3b5e79a8488 | 428 | void static menu_5_set_ad77681_filter_type(void) |
Kjansen45 | 0:ae894be1131f | 429 | { |
jngarlitos | 1:f3b5e79a8488 | 430 | pc.printf(" Avaliable AD7768-1 Filter Type options: \n"); |
jngarlitos | 1:f3b5e79a8488 | 431 | pc.printf(" 1 - SINC3 Fileter\n"); |
jngarlitos | 1:f3b5e79a8488 | 432 | pc.printf(" 2 - SINC5 Filter\n"); |
jngarlitos | 1:f3b5e79a8488 | 433 | pc.printf(" 3 - Low ripple FIR Filter\n"); |
jngarlitos | 1:f3b5e79a8488 | 434 | pc.printf(" 4 - SINC3 50/60Hz rejection\n"); |
jngarlitos | 1:f3b5e79a8488 | 435 | pc.printf(" 5 - User-defined FIR filter\n"); |
jngarlitos | 1:f3b5e79a8488 | 436 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 437 | |
jngarlitos | 1:f3b5e79a8488 | 438 | uint32_t new_filter = 0; |
jngarlitos | 1:f3b5e79a8488 | 439 | int32_t ret; |
jngarlitos | 1:f3b5e79a8488 | 440 | |
jngarlitos | 1:f3b5e79a8488 | 441 | getUserInput(&new_filter); |
jngarlitos | 1:f3b5e79a8488 | 442 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 443 | |
jngarlitos | 1:f3b5e79a8488 | 444 | switch (new_filter) { |
jngarlitos | 1:f3b5e79a8488 | 445 | |
jngarlitos | 1:f3b5e79a8488 | 446 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 447 | set_SINC3_filter(); |
jngarlitos | 1:f3b5e79a8488 | 448 | break; |
jngarlitos | 1:f3b5e79a8488 | 449 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 450 | set_SINC5_filter(); |
jngarlitos | 1:f3b5e79a8488 | 451 | break; |
jngarlitos | 1:f3b5e79a8488 | 452 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 453 | set_FIR_filter(); |
jngarlitos | 1:f3b5e79a8488 | 454 | break; |
jngarlitos | 1:f3b5e79a8488 | 455 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 456 | set_50HZ_rej(); |
jngarlitos | 1:f3b5e79a8488 | 457 | break; |
jngarlitos | 1:f3b5e79a8488 | 458 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 459 | set_user_defined_FIR(); |
jngarlitos | 1:f3b5e79a8488 | 460 | break; |
jngarlitos | 1:f3b5e79a8488 | 461 | default: |
jngarlitos | 1:f3b5e79a8488 | 462 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 463 | break; |
jngarlitos | 1:f3b5e79a8488 | 464 | } |
jngarlitos | 1:f3b5e79a8488 | 465 | |
jngarlitos | 1:f3b5e79a8488 | 466 | ad77681_update_sample_rate(device); // Update the sample rate after changing the Filter type |
jngarlitos | 1:f3b5e79a8488 | 467 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 468 | } |
jngarlitos | 1:f3b5e79a8488 | 469 | |
jngarlitos | 1:f3b5e79a8488 | 470 | /** |
jngarlitos | 1:f3b5e79a8488 | 471 | * Set SINC3 filter |
jngarlitos | 1:f3b5e79a8488 | 472 | * |
jngarlitos | 1:f3b5e79a8488 | 473 | */ |
jngarlitos | 1:f3b5e79a8488 | 474 | void static set_SINC3_filter(void) |
jngarlitos | 1:f3b5e79a8488 | 475 | { |
jngarlitos | 1:f3b5e79a8488 | 476 | uint32_t new_sinc3 = 0, new_sinc5 = 0; |
jngarlitos | 1:f3b5e79a8488 | 477 | int32_t ret; |
jngarlitos | 1:f3b5e79a8488 | 478 | |
jngarlitos | 1:f3b5e79a8488 | 479 | pc.printf(" AD7768-1 SINC3 filter Oversampling ratios: \n"); |
jngarlitos | 1:f3b5e79a8488 | 480 | pc.printf(" OSR is calculated as (x + 1)*32\n"); |
jngarlitos | 1:f3b5e79a8488 | 481 | pc.printf(" x is SINC3 OSR register value\n"); |
jngarlitos | 1:f3b5e79a8488 | 482 | pc.printf(" Please input a value from 0 to 8192 = 2^13\n :"); |
jngarlitos | 1:f3b5e79a8488 | 483 | |
jngarlitos | 1:f3b5e79a8488 | 484 | ret = getUserInput(&new_sinc3); |
jngarlitos | 1:f3b5e79a8488 | 485 | |
jngarlitos | 1:f3b5e79a8488 | 486 | if ((new_sinc3 >= 0) && (new_sinc3 <= 8192) && (ret == SUCCESS)) { |
jngarlitos | 1:f3b5e79a8488 | 487 | pc.printf("%d\n", new_sinc3); |
jngarlitos | 1:f3b5e79a8488 | 488 | |
jngarlitos | 1:f3b5e79a8488 | 489 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx32, AD77681_SINC3, new_sinc3); |
jngarlitos | 1:f3b5e79a8488 | 490 | pc.printf(" SINC3 OSR is set to %d\n", (new_sinc3 + 1) * 32); |
jngarlitos | 1:f3b5e79a8488 | 491 | } else { |
jngarlitos | 1:f3b5e79a8488 | 492 | pc.printf("%d\n", new_sinc3); |
jngarlitos | 1:f3b5e79a8488 | 493 | pc.printf(" Invalid option - too large number\n"); |
jngarlitos | 1:f3b5e79a8488 | 494 | } |
jngarlitos | 1:f3b5e79a8488 | 495 | } |
jngarlitos | 1:f3b5e79a8488 | 496 | |
jngarlitos | 1:f3b5e79a8488 | 497 | /** |
jngarlitos | 1:f3b5e79a8488 | 498 | * Set SINC5 filter |
jngarlitos | 1:f3b5e79a8488 | 499 | * |
jngarlitos | 1:f3b5e79a8488 | 500 | */ |
jngarlitos | 1:f3b5e79a8488 | 501 | void static set_SINC5_filter(void) |
jngarlitos | 1:f3b5e79a8488 | 502 | { |
jngarlitos | 1:f3b5e79a8488 | 503 | uint32_t new_sinc5; |
jngarlitos | 1:f3b5e79a8488 | 504 | |
jngarlitos | 1:f3b5e79a8488 | 505 | pc.printf(" AD7768-1 SINC5 filter Oversampling ratios: \n"); |
jngarlitos | 1:f3b5e79a8488 | 506 | pc.printf(" 1 - Oversampled by 8\n"); |
jngarlitos | 1:f3b5e79a8488 | 507 | pc.printf(" 2 - Oversampled by 16\n"); |
jngarlitos | 1:f3b5e79a8488 | 508 | pc.printf(" 3 - Oversampled by 32\n"); |
jngarlitos | 1:f3b5e79a8488 | 509 | pc.printf(" 4 - Oversampled by 64\n"); |
jngarlitos | 1:f3b5e79a8488 | 510 | pc.printf(" 5 - Oversampled by 128\n"); |
jngarlitos | 1:f3b5e79a8488 | 511 | pc.printf(" 6 - Oversampled by 256\n"); |
jngarlitos | 1:f3b5e79a8488 | 512 | pc.printf(" 7 - Oversampled by 512\n"); |
jngarlitos | 1:f3b5e79a8488 | 513 | pc.printf(" 8 - Oversampled by 1024\n"); |
jngarlitos | 1:f3b5e79a8488 | 514 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 515 | |
jngarlitos | 1:f3b5e79a8488 | 516 | getUserInput(&new_sinc5); |
jngarlitos | 1:f3b5e79a8488 | 517 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 518 | |
jngarlitos | 1:f3b5e79a8488 | 519 | switch (new_sinc5) { |
jngarlitos | 1:f3b5e79a8488 | 520 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 521 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx32, AD77681_SINC5_DECx8, 0); |
jngarlitos | 1:f3b5e79a8488 | 522 | pc.printf(" SINC5 with OSRx8 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 523 | break; |
jngarlitos | 1:f3b5e79a8488 | 524 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 525 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx32, AD77681_SINC5_DECx16, 0); |
jngarlitos | 1:f3b5e79a8488 | 526 | pc.printf(" SINC5 with OSRx16 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 527 | break; |
jngarlitos | 1:f3b5e79a8488 | 528 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 529 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx32, AD77681_SINC5, 0); |
jngarlitos | 1:f3b5e79a8488 | 530 | pc.printf(" SINC5 with OSRx32 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 531 | break; |
jngarlitos | 1:f3b5e79a8488 | 532 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 533 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx64, AD77681_SINC5, 0); |
jngarlitos | 1:f3b5e79a8488 | 534 | pc.printf(" SINC5 with OSRx64 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 535 | break; |
jngarlitos | 1:f3b5e79a8488 | 536 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 537 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx128, AD77681_SINC5, 0); |
jngarlitos | 1:f3b5e79a8488 | 538 | pc.printf(" SINC5 with OSRx128 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 539 | break; |
jngarlitos | 1:f3b5e79a8488 | 540 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 541 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx256, AD77681_SINC5, 0); |
jngarlitos | 1:f3b5e79a8488 | 542 | pc.printf(" SINC5 with OSRx256 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 543 | break; |
jngarlitos | 1:f3b5e79a8488 | 544 | case 7: |
jngarlitos | 1:f3b5e79a8488 | 545 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx512, AD77681_SINC5, 0); |
jngarlitos | 1:f3b5e79a8488 | 546 | pc.printf(" SINC5 with OSRx512 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 547 | break; |
jngarlitos | 1:f3b5e79a8488 | 548 | case 8: |
jngarlitos | 1:f3b5e79a8488 | 549 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx1024, AD77681_SINC5, 0); |
jngarlitos | 1:f3b5e79a8488 | 550 | pc.printf(" SINC5 with OSRx1024 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 551 | break; |
jngarlitos | 1:f3b5e79a8488 | 552 | default: |
jngarlitos | 1:f3b5e79a8488 | 553 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 554 | break; |
jngarlitos | 1:f3b5e79a8488 | 555 | } |
jngarlitos | 1:f3b5e79a8488 | 556 | } |
jngarlitos | 1:f3b5e79a8488 | 557 | |
jngarlitos | 1:f3b5e79a8488 | 558 | /** |
jngarlitos | 1:f3b5e79a8488 | 559 | * Set FIR filter |
jngarlitos | 1:f3b5e79a8488 | 560 | * |
jngarlitos | 1:f3b5e79a8488 | 561 | */ |
jngarlitos | 1:f3b5e79a8488 | 562 | void static set_FIR_filter(void) |
jngarlitos | 1:f3b5e79a8488 | 563 | { |
jngarlitos | 1:f3b5e79a8488 | 564 | uint32_t new_fir; |
jngarlitos | 1:f3b5e79a8488 | 565 | |
jngarlitos | 1:f3b5e79a8488 | 566 | pc.printf(" AD7768-1 FIR filter Oversampling ratios: \n"); |
jngarlitos | 1:f3b5e79a8488 | 567 | pc.printf(" 1 - Oversampled by 32\n"); |
jngarlitos | 1:f3b5e79a8488 | 568 | pc.printf(" 2 - Oversampled by 64\n"); |
jngarlitos | 1:f3b5e79a8488 | 569 | pc.printf(" 3 - Oversampled by 128\n"); |
jngarlitos | 1:f3b5e79a8488 | 570 | pc.printf(" 4 - Oversampled by 256\n"); |
jngarlitos | 1:f3b5e79a8488 | 571 | pc.printf(" 5 - Oversampled by 512\n"); |
jngarlitos | 1:f3b5e79a8488 | 572 | pc.printf(" 6 - Oversampled by 1024\n"); |
jngarlitos | 1:f3b5e79a8488 | 573 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 574 | |
jngarlitos | 1:f3b5e79a8488 | 575 | getUserInput(&new_fir); |
jngarlitos | 1:f3b5e79a8488 | 576 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 577 | |
jngarlitos | 1:f3b5e79a8488 | 578 | switch (new_fir) { |
jngarlitos | 1:f3b5e79a8488 | 579 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 580 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx32, AD77681_FIR, 0); |
jngarlitos | 1:f3b5e79a8488 | 581 | pc.printf(" FIR with OSRx32 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 582 | break; |
jngarlitos | 1:f3b5e79a8488 | 583 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 584 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx64, AD77681_FIR, 0); |
jngarlitos | 1:f3b5e79a8488 | 585 | pc.printf(" FIR with OSRx64 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 586 | break; |
jngarlitos | 1:f3b5e79a8488 | 587 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 588 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx128, AD77681_FIR, 0); |
jngarlitos | 1:f3b5e79a8488 | 589 | pc.printf(" FIR with OSRx128 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 590 | break; |
jngarlitos | 1:f3b5e79a8488 | 591 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 592 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx256, AD77681_FIR, 0); |
jngarlitos | 1:f3b5e79a8488 | 593 | pc.printf(" FIR with OSRx256 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 594 | break; |
jngarlitos | 1:f3b5e79a8488 | 595 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 596 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx512, AD77681_FIR, 0); |
jngarlitos | 1:f3b5e79a8488 | 597 | pc.printf(" FIR with OSRx512 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 598 | break; |
jngarlitos | 1:f3b5e79a8488 | 599 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 600 | ad77681_set_filter_type(device, AD77681_SINC5_FIR_DECx1024, AD77681_FIR, 0); |
jngarlitos | 1:f3b5e79a8488 | 601 | pc.printf(" FIR with OSRx1024 set\n"); |
jngarlitos | 1:f3b5e79a8488 | 602 | break; |
jngarlitos | 1:f3b5e79a8488 | 603 | default: |
jngarlitos | 1:f3b5e79a8488 | 604 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 605 | break; |
jngarlitos | 1:f3b5e79a8488 | 606 | } |
jngarlitos | 1:f3b5e79a8488 | 607 | } |
jngarlitos | 1:f3b5e79a8488 | 608 | |
jngarlitos | 1:f3b5e79a8488 | 609 | /** |
jngarlitos | 1:f3b5e79a8488 | 610 | * Set 50HZ rejection bit when SINC3 is being used |
jngarlitos | 1:f3b5e79a8488 | 611 | * |
jngarlitos | 1:f3b5e79a8488 | 612 | */ |
jngarlitos | 1:f3b5e79a8488 | 613 | void static set_50HZ_rej(void) |
jngarlitos | 1:f3b5e79a8488 | 614 | { |
jngarlitos | 1:f3b5e79a8488 | 615 | uint32_t new_50Hz; |
jngarlitos | 1:f3b5e79a8488 | 616 | |
jngarlitos | 1:f3b5e79a8488 | 617 | pc.printf(" AD7768-1 SINC3 50/60Hz rejection: \n"); |
jngarlitos | 1:f3b5e79a8488 | 618 | pc.printf(" 1 - 50/60Hz rejection enable \n"); |
jngarlitos | 1:f3b5e79a8488 | 619 | pc.printf(" 2 - 50/60Hz rejection disable \n"); |
jngarlitos | 1:f3b5e79a8488 | 620 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 621 | |
jngarlitos | 1:f3b5e79a8488 | 622 | getUserInput(&new_50Hz); |
jngarlitos | 1:f3b5e79a8488 | 623 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 624 | |
jngarlitos | 1:f3b5e79a8488 | 625 | switch (new_50Hz) { |
jngarlitos | 1:f3b5e79a8488 | 626 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 627 | ad77681_set_50HZ_rejection(device, ENABLE); |
jngarlitos | 1:f3b5e79a8488 | 628 | pc.printf(" SINC3 50/60Hz rejection enabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 629 | break; |
jngarlitos | 1:f3b5e79a8488 | 630 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 631 | ad77681_set_50HZ_rejection(device, DISABLE); |
jngarlitos | 1:f3b5e79a8488 | 632 | pc.printf(" SINC3 50/60Hz rejection disabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 633 | break; |
jngarlitos | 1:f3b5e79a8488 | 634 | default: |
jngarlitos | 1:f3b5e79a8488 | 635 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 636 | break; |
Kjansen45 | 0:ae894be1131f | 637 | } |
Kjansen45 | 0:ae894be1131f | 638 | } |
Kjansen45 | 0:ae894be1131f | 639 | |
jngarlitos | 1:f3b5e79a8488 | 640 | /** |
jngarlitos | 1:f3b5e79a8488 | 641 | * Insert user-defined FIR filter coeffs |
jngarlitos | 1:f3b5e79a8488 | 642 | * |
jngarlitos | 1:f3b5e79a8488 | 643 | */ |
jngarlitos | 1:f3b5e79a8488 | 644 | void static set_user_defined_FIR(void) |
jngarlitos | 1:f3b5e79a8488 | 645 | { |
jngarlitos | 1:f3b5e79a8488 | 646 | const uint8_t coeff_reg_length = 56; // Maximum allowed number of coefficients in the coeff register |
jngarlitos | 1:f3b5e79a8488 | 647 | |
jngarlitos | 1:f3b5e79a8488 | 648 | pc.printf(" AD7768-1 User Defined FIR filter\n"); |
jngarlitos | 1:f3b5e79a8488 | 649 | |
jngarlitos | 1:f3b5e79a8488 | 650 | if ((ARRAY_SIZE(programmable_FIR) <= coeff_reg_length) && (count_of_active_coeffs <= coeff_reg_length)) { |
jngarlitos | 1:f3b5e79a8488 | 651 | pc.printf(" Aplying user-defined FIR filter coefficients from 'cn0535_init_params.h' programmable_FIR[56] \n"); |
jngarlitos | 1:f3b5e79a8488 | 652 | ad77681_programmable_filter(device, programmable_FIR, count_of_active_coeffs); |
jngarlitos | 1:f3b5e79a8488 | 653 | pc.printf(" Coeffs inserted successfully\n"); |
jngarlitos | 1:f3b5e79a8488 | 654 | } else |
jngarlitos | 1:f3b5e79a8488 | 655 | pc.printf(" Incorrect count of coefficients in 'cn0535_init_params.h' programmable_FIR[56]\n"); |
jngarlitos | 1:f3b5e79a8488 | 656 | } |
jngarlitos | 1:f3b5e79a8488 | 657 | |
jngarlitos | 1:f3b5e79a8488 | 658 | /** |
jngarlitos | 1:f3b5e79a8488 | 659 | * AIN and REF buffers controll |
jngarlitos | 1:f3b5e79a8488 | 660 | * |
jngarlitos | 1:f3b5e79a8488 | 661 | */ |
jngarlitos | 1:f3b5e79a8488 | 662 | void static menu_6_ad77681_AIN_buffers_controll(void) |
jngarlitos | 1:f3b5e79a8488 | 663 | { |
jngarlitos | 1:f3b5e79a8488 | 664 | uint32_t new_AD77681_REF_buffer = 0; |
jngarlitos | 1:f3b5e79a8488 | 665 | |
jngarlitos | 1:f3b5e79a8488 | 666 | pc.printf(" AD7768-1 Analog IN precharge buffers settings: \n"); |
jngarlitos | 1:f3b5e79a8488 | 667 | pc.printf(" 1 - Turn ON both precharge buffers\n"); |
jngarlitos | 1:f3b5e79a8488 | 668 | pc.printf(" 2 - Turn OFF both precharge buffers\n"); |
jngarlitos | 1:f3b5e79a8488 | 669 | pc.printf(" 3 - Turn ON AIN- precharge buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 670 | pc.printf(" 4 - Turn OFF AIN- precharge buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 671 | pc.printf(" 5 - Turn ON AIN+ precharge buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 672 | pc.printf(" 6 - Turn OFF AIN+ precharge buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 673 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 674 | |
jngarlitos | 1:f3b5e79a8488 | 675 | |
jngarlitos | 1:f3b5e79a8488 | 676 | getUserInput(&new_AD77681_REF_buffer); |
jngarlitos | 1:f3b5e79a8488 | 677 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 678 | |
jngarlitos | 1:f3b5e79a8488 | 679 | switch (new_AD77681_REF_buffer) { |
jngarlitos | 1:f3b5e79a8488 | 680 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 681 | ad77681_set_AINn_buffer(device, AD77681_AINn_ENABLED); |
jngarlitos | 1:f3b5e79a8488 | 682 | ad77681_set_AINp_buffer(device, AD77681_AINp_ENABLED); |
jngarlitos | 1:f3b5e79a8488 | 683 | pc.printf(" AIN+ and AIN- enabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 684 | break; |
jngarlitos | 1:f3b5e79a8488 | 685 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 686 | ad77681_set_AINn_buffer(device, AD77681_AINn_DISABLED); |
jngarlitos | 1:f3b5e79a8488 | 687 | ad77681_set_AINp_buffer(device, AD77681_AINp_DISABLED); |
jngarlitos | 1:f3b5e79a8488 | 688 | pc.printf(" AIN+ and AIN- disabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 689 | break; |
jngarlitos | 1:f3b5e79a8488 | 690 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 691 | ad77681_set_AINn_buffer(device, AD77681_AINn_ENABLED); |
jngarlitos | 1:f3b5e79a8488 | 692 | pc.printf(" AIN- Enabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 693 | break; |
jngarlitos | 1:f3b5e79a8488 | 694 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 695 | ad77681_set_AINn_buffer(device, AD77681_AINn_DISABLED); |
jngarlitos | 1:f3b5e79a8488 | 696 | pc.printf(" AIN- Disabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 697 | break; |
jngarlitos | 1:f3b5e79a8488 | 698 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 699 | ad77681_set_AINp_buffer(device, AD77681_AINp_ENABLED); |
jngarlitos | 1:f3b5e79a8488 | 700 | pc.printf(" AIN+ Enabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 701 | break; |
jngarlitos | 1:f3b5e79a8488 | 702 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 703 | ad77681_set_AINp_buffer(device, AD77681_AINp_DISABLED); |
jngarlitos | 1:f3b5e79a8488 | 704 | pc.printf(" AIN+ Disabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 705 | break; |
jngarlitos | 1:f3b5e79a8488 | 706 | default: |
jngarlitos | 1:f3b5e79a8488 | 707 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 708 | break; |
jngarlitos | 1:f3b5e79a8488 | 709 | } |
jngarlitos | 1:f3b5e79a8488 | 710 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 711 | } |
jngarlitos | 1:f3b5e79a8488 | 712 | |
jngarlitos | 1:f3b5e79a8488 | 713 | /** |
jngarlitos | 1:f3b5e79a8488 | 714 | * AIN and REF buffers controll |
jngarlitos | 1:f3b5e79a8488 | 715 | * |
jngarlitos | 1:f3b5e79a8488 | 716 | */ |
jngarlitos | 1:f3b5e79a8488 | 717 | void static menu_7_ad77681_REF_buffers_controll(void) |
jngarlitos | 1:f3b5e79a8488 | 718 | { |
jngarlitos | 1:f3b5e79a8488 | 719 | |
jngarlitos | 1:f3b5e79a8488 | 720 | uint32_t new_REF_buffer = 0; |
jngarlitos | 1:f3b5e79a8488 | 721 | |
jngarlitos | 1:f3b5e79a8488 | 722 | pc.printf(" REF buffers settings: \n"); |
jngarlitos | 1:f3b5e79a8488 | 723 | pc.printf(" 1 - Full REF- reference buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 724 | pc.printf(" 2 - Full REF+ reference buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 725 | pc.printf(" 3 - Unbuffered REF- reference buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 726 | pc.printf(" 4 - Unbuffered REF+ reference buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 727 | pc.printf(" 5 - Precharge REF- reference buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 728 | pc.printf(" 6 - Precharge REF+ reference buffer\n"); |
jngarlitos | 1:f3b5e79a8488 | 729 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 730 | |
jngarlitos | 1:f3b5e79a8488 | 731 | getUserInput(&new_REF_buffer); |
jngarlitos | 1:f3b5e79a8488 | 732 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 733 | |
jngarlitos | 1:f3b5e79a8488 | 734 | switch (new_REF_buffer) { |
jngarlitos | 1:f3b5e79a8488 | 735 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 736 | ad77681_set_REFn_buffer(device, AD77681_BUFn_FULL_BUFFER_ON); |
jngarlitos | 1:f3b5e79a8488 | 737 | pc.printf(" Fully buffered REF-\n"); |
jngarlitos | 1:f3b5e79a8488 | 738 | break; |
jngarlitos | 1:f3b5e79a8488 | 739 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 740 | ad77681_set_REFp_buffer(device, AD77681_BUFp_FULL_BUFFER_ON); |
jngarlitos | 1:f3b5e79a8488 | 741 | pc.printf(" Fully buffered REF+\n"); |
jngarlitos | 1:f3b5e79a8488 | 742 | break; |
jngarlitos | 1:f3b5e79a8488 | 743 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 744 | ad77681_set_REFn_buffer(device, AD77681_BUFn_DISABLED); |
jngarlitos | 1:f3b5e79a8488 | 745 | pc.printf(" Unbuffered REF-\n"); |
jngarlitos | 1:f3b5e79a8488 | 746 | break; |
jngarlitos | 1:f3b5e79a8488 | 747 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 748 | ad77681_set_REFp_buffer(device, AD77681_BUFp_DISABLED); |
jngarlitos | 1:f3b5e79a8488 | 749 | pc.printf(" Unbuffered REF+\n"); |
jngarlitos | 1:f3b5e79a8488 | 750 | break; |
jngarlitos | 1:f3b5e79a8488 | 751 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 752 | ad77681_set_REFn_buffer(device, AD77681_BUFn_ENABLED); |
jngarlitos | 1:f3b5e79a8488 | 753 | pc.printf(" Precharge buffer on REF-\n"); |
jngarlitos | 1:f3b5e79a8488 | 754 | break; |
jngarlitos | 1:f3b5e79a8488 | 755 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 756 | ad77681_set_REFp_buffer(device, AD77681_BUFp_ENABLED); |
jngarlitos | 1:f3b5e79a8488 | 757 | pc.printf(" Precharge buffer on REF+\n"); |
jngarlitos | 1:f3b5e79a8488 | 758 | break; |
jngarlitos | 1:f3b5e79a8488 | 759 | default: |
jngarlitos | 1:f3b5e79a8488 | 760 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 761 | break; |
jngarlitos | 1:f3b5e79a8488 | 762 | |
jngarlitos | 1:f3b5e79a8488 | 763 | } |
jngarlitos | 1:f3b5e79a8488 | 764 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 765 | } |
jngarlitos | 1:f3b5e79a8488 | 766 | |
jngarlitos | 1:f3b5e79a8488 | 767 | /** |
jngarlitos | 1:f3b5e79a8488 | 768 | * VCM output controll |
jngarlitos | 1:f3b5e79a8488 | 769 | * |
jngarlitos | 1:f3b5e79a8488 | 770 | */ |
jngarlitos | 1:f3b5e79a8488 | 771 | void static menu_8_set_ad77681_vcm_setup(void) |
jngarlitos | 1:f3b5e79a8488 | 772 | { |
jngarlitos | 1:f3b5e79a8488 | 773 | uint32_t new_vcm = 0; |
jngarlitos | 1:f3b5e79a8488 | 774 | |
jngarlitos | 1:f3b5e79a8488 | 775 | pc.printf(" Avaliable VCM output voltage levels: \n"); |
jngarlitos | 1:f3b5e79a8488 | 776 | pc.printf(" 1 - VCM = (AVDD1-AVSS)/2\n"); |
jngarlitos | 1:f3b5e79a8488 | 777 | pc.printf(" 2 - VCM = 2.5V\n"); |
jngarlitos | 1:f3b5e79a8488 | 778 | pc.printf(" 3 - VCM = 2.05V\n"); |
jngarlitos | 1:f3b5e79a8488 | 779 | pc.printf(" 4 - VCM = 1.9V\n"); |
jngarlitos | 1:f3b5e79a8488 | 780 | pc.printf(" 5 - VCM = 1.65V\n"); |
jngarlitos | 1:f3b5e79a8488 | 781 | pc.printf(" 6 - VCM = 1.1V\n"); |
jngarlitos | 1:f3b5e79a8488 | 782 | pc.printf(" 7 - VCM = 0.9V\n"); |
jngarlitos | 1:f3b5e79a8488 | 783 | pc.printf(" 8 - VCM off\n"); |
jngarlitos | 1:f3b5e79a8488 | 784 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 785 | |
jngarlitos | 1:f3b5e79a8488 | 786 | getUserInput(&new_vcm); |
jngarlitos | 1:f3b5e79a8488 | 787 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 788 | |
jngarlitos | 1:f3b5e79a8488 | 789 | switch (new_vcm) { |
jngarlitos | 1:f3b5e79a8488 | 790 | |
jngarlitos | 1:f3b5e79a8488 | 791 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 792 | ad77681_set_VCM_output(device, AD77681_VCM_HALF_VCC); |
jngarlitos | 1:f3b5e79a8488 | 793 | pc.printf(" VCM set to half of the Vcc\n"); |
jngarlitos | 1:f3b5e79a8488 | 794 | break; |
jngarlitos | 1:f3b5e79a8488 | 795 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 796 | ad77681_set_VCM_output(device, AD77681_VCM_2_5V); |
jngarlitos | 1:f3b5e79a8488 | 797 | pc.printf(" VCM set to 2.5V\n"); |
jngarlitos | 1:f3b5e79a8488 | 798 | break; |
jngarlitos | 1:f3b5e79a8488 | 799 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 800 | ad77681_set_VCM_output(device, AD77681_VCM_2_05V); |
jngarlitos | 1:f3b5e79a8488 | 801 | pc.printf(" VCM set to 2.05V\n"); |
jngarlitos | 1:f3b5e79a8488 | 802 | break; |
jngarlitos | 1:f3b5e79a8488 | 803 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 804 | ad77681_set_VCM_output(device, AD77681_VCM_1_9V); |
jngarlitos | 1:f3b5e79a8488 | 805 | pc.printf(" VCM set to 1.9V\n"); |
jngarlitos | 1:f3b5e79a8488 | 806 | break; |
jngarlitos | 1:f3b5e79a8488 | 807 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 808 | ad77681_set_VCM_output(device, AD77681_VCM_1_65V); |
jngarlitos | 1:f3b5e79a8488 | 809 | pc.printf(" VCM set to 1.65V\n"); |
jngarlitos | 1:f3b5e79a8488 | 810 | break; |
jngarlitos | 1:f3b5e79a8488 | 811 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 812 | ad77681_set_VCM_output(device, AD77681_VCM_1_1V); |
jngarlitos | 1:f3b5e79a8488 | 813 | pc.printf(" VCM set to 1.1V\n"); |
jngarlitos | 1:f3b5e79a8488 | 814 | break; |
jngarlitos | 1:f3b5e79a8488 | 815 | case 7: |
jngarlitos | 1:f3b5e79a8488 | 816 | ad77681_set_VCM_output(device, AD77681_VCM_0_9V); |
jngarlitos | 1:f3b5e79a8488 | 817 | pc.printf(" VCM set to 0.9V\n"); |
jngarlitos | 1:f3b5e79a8488 | 818 | break; |
jngarlitos | 1:f3b5e79a8488 | 819 | case 8: |
jngarlitos | 1:f3b5e79a8488 | 820 | ad77681_set_VCM_output(device, AD77681_VCM_OFF); |
jngarlitos | 1:f3b5e79a8488 | 821 | pc.printf(" VCM OFF\n"); |
jngarlitos | 1:f3b5e79a8488 | 822 | break; |
jngarlitos | 1:f3b5e79a8488 | 823 | default: |
jngarlitos | 1:f3b5e79a8488 | 824 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 825 | break; |
jngarlitos | 1:f3b5e79a8488 | 826 | } |
jngarlitos | 1:f3b5e79a8488 | 827 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 828 | } |
jngarlitos | 1:f3b5e79a8488 | 829 | |
jngarlitos | 1:f3b5e79a8488 | 830 | /** |
jngarlitos | 1:f3b5e79a8488 | 831 | * Set data output mode |
jngarlitos | 1:f3b5e79a8488 | 832 | * |
jngarlitos | 1:f3b5e79a8488 | 833 | */ |
jngarlitos | 1:f3b5e79a8488 | 834 | void static menu_9_set_ad77681_data_output_mode(void) |
jngarlitos | 1:f3b5e79a8488 | 835 | { |
jngarlitos | 1:f3b5e79a8488 | 836 | uint32_t new_data_mode = 0, new_length = 0, new_status = 0, new_crc = 0; |
jngarlitos | 1:f3b5e79a8488 | 837 | |
jngarlitos | 1:f3b5e79a8488 | 838 | pc.printf(" ADC data outpup modes: \n"); |
jngarlitos | 1:f3b5e79a8488 | 839 | pc.printf(" 1 - Continuous: waiting for DRDY\n"); |
jngarlitos | 1:f3b5e79a8488 | 840 | pc.printf(" 2 - Continuous one shot: waiting for SYNC_IN\n"); |
jngarlitos | 1:f3b5e79a8488 | 841 | pc.printf(" 3 - Single-conversion standby\n"); |
jngarlitos | 1:f3b5e79a8488 | 842 | pc.printf(" 4 - Periodic standby\n"); |
jngarlitos | 1:f3b5e79a8488 | 843 | pc.printf(" 5 - Standby mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 844 | pc.printf(" 6 - 16bit or 24bit data format\n"); |
jngarlitos | 1:f3b5e79a8488 | 845 | pc.printf(" 7 - Status bit output\n"); |
jngarlitos | 1:f3b5e79a8488 | 846 | pc.printf(" 8 - Switch form diag mode to measure\n"); |
jngarlitos | 1:f3b5e79a8488 | 847 | pc.printf(" 9 - Switch form measure to diag mode\n"); |
jngarlitos | 1:f3b5e79a8488 | 848 | pc.printf(" 10 - Set CRC type\n"); |
jngarlitos | 1:f3b5e79a8488 | 849 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 850 | |
jngarlitos | 1:f3b5e79a8488 | 851 | getUserInput(&new_data_mode); |
jngarlitos | 1:f3b5e79a8488 | 852 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 853 | |
jngarlitos | 1:f3b5e79a8488 | 854 | switch (new_data_mode) { |
jngarlitos | 1:f3b5e79a8488 | 855 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 856 | ad77681_set_conv_mode(device, AD77681_CONV_CONTINUOUS, device->diag_mux_sel, device->conv_diag_sel); // DIAG MUX NOT SELECTED |
jngarlitos | 1:f3b5e79a8488 | 857 | pc.printf(" Continuous mode set\n"); |
jngarlitos | 1:f3b5e79a8488 | 858 | break; |
jngarlitos | 1:f3b5e79a8488 | 859 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 860 | ad77681_set_conv_mode(device, AD77681_CONV_ONE_SHOT, device->diag_mux_sel, device->conv_diag_sel); |
jngarlitos | 1:f3b5e79a8488 | 861 | pc.printf(" Continuous one shot conversion set\n"); |
jngarlitos | 1:f3b5e79a8488 | 862 | break; |
jngarlitos | 1:f3b5e79a8488 | 863 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 864 | ad77681_set_conv_mode(device, AD77681_CONV_SINGLE, device->diag_mux_sel, device->conv_diag_sel); |
jngarlitos | 1:f3b5e79a8488 | 865 | pc.printf(" Single conversion standby mode set\n"); |
jngarlitos | 1:f3b5e79a8488 | 866 | break; |
jngarlitos | 1:f3b5e79a8488 | 867 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 868 | ad77681_set_conv_mode(device, AD77681_CONV_PERIODIC, device->diag_mux_sel, device->conv_diag_sel); |
jngarlitos | 1:f3b5e79a8488 | 869 | pc.printf(" Periodiec standby mode set\n"); |
jngarlitos | 1:f3b5e79a8488 | 870 | break; |
jngarlitos | 1:f3b5e79a8488 | 871 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 872 | ad77681_set_conv_mode(device, AD77681_CONV_STANDBY, device->diag_mux_sel, device->conv_diag_sel); |
jngarlitos | 1:f3b5e79a8488 | 873 | pc.printf(" Standby mode set\n"); |
jngarlitos | 1:f3b5e79a8488 | 874 | break; |
jngarlitos | 1:f3b5e79a8488 | 875 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 876 | pc.printf(" Conversion length select: \n"); |
jngarlitos | 1:f3b5e79a8488 | 877 | pc.printf(" 1 - 24bit length\n"); |
jngarlitos | 1:f3b5e79a8488 | 878 | pc.printf(" 2 - 16bit length\n"); |
jngarlitos | 1:f3b5e79a8488 | 879 | |
jngarlitos | 1:f3b5e79a8488 | 880 | getUserInput(&new_length); |
jngarlitos | 1:f3b5e79a8488 | 881 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 882 | |
jngarlitos | 1:f3b5e79a8488 | 883 | switch (new_length) { |
jngarlitos | 1:f3b5e79a8488 | 884 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 885 | ad77681_set_convlen(device, AD77681_CONV_24BIT); |
jngarlitos | 1:f3b5e79a8488 | 886 | pc.printf(" 24bit data output format selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 887 | break; |
jngarlitos | 1:f3b5e79a8488 | 888 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 889 | ad77681_set_convlen(device, AD77681_CONV_16BIT); |
jngarlitos | 1:f3b5e79a8488 | 890 | pc.printf(" 16bit data output format selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 891 | break; |
jngarlitos | 1:f3b5e79a8488 | 892 | default: |
jngarlitos | 1:f3b5e79a8488 | 893 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 894 | break; |
jngarlitos | 1:f3b5e79a8488 | 895 | } |
jngarlitos | 1:f3b5e79a8488 | 896 | break; |
jngarlitos | 1:f3b5e79a8488 | 897 | case 7: |
jngarlitos | 1:f3b5e79a8488 | 898 | pc.printf(" Status bit output: \n"); |
jngarlitos | 1:f3b5e79a8488 | 899 | pc.printf(" 1 - Enable status bit after each ADC conversion\n"); |
jngarlitos | 1:f3b5e79a8488 | 900 | pc.printf(" 2 - Disable status bit after each ADC conversion\n"); |
jngarlitos | 1:f3b5e79a8488 | 901 | |
jngarlitos | 1:f3b5e79a8488 | 902 | getUserInput(&new_status); |
jngarlitos | 1:f3b5e79a8488 | 903 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 904 | |
jngarlitos | 1:f3b5e79a8488 | 905 | switch (new_status) { |
jngarlitos | 1:f3b5e79a8488 | 906 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 907 | ad77681_set_status_bit(device, true); |
jngarlitos | 1:f3b5e79a8488 | 908 | pc.printf(" Status bit enabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 909 | break; |
jngarlitos | 1:f3b5e79a8488 | 910 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 911 | ad77681_set_status_bit(device, false); |
jngarlitos | 1:f3b5e79a8488 | 912 | pc.printf(" Status bit disabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 913 | break; |
jngarlitos | 1:f3b5e79a8488 | 914 | default: |
jngarlitos | 1:f3b5e79a8488 | 915 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 916 | break; |
jngarlitos | 1:f3b5e79a8488 | 917 | } |
jngarlitos | 1:f3b5e79a8488 | 918 | |
jngarlitos | 1:f3b5e79a8488 | 919 | break; |
jngarlitos | 1:f3b5e79a8488 | 920 | case 8: |
jngarlitos | 1:f3b5e79a8488 | 921 | ad77681_set_conv_mode(device, device->conv_mode, device->diag_mux_sel, false); // DIAG MUX NOT SELECTED |
jngarlitos | 1:f3b5e79a8488 | 922 | pc.printf(" Measure mode selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 923 | break; |
jngarlitos | 1:f3b5e79a8488 | 924 | case 9: |
jngarlitos | 1:f3b5e79a8488 | 925 | ad77681_set_conv_mode(device, device->conv_mode, device->diag_mux_sel, true); // DIAG MUX SELECTED |
jngarlitos | 1:f3b5e79a8488 | 926 | pc.printf(" Diagnostic mode selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 927 | break; |
jngarlitos | 1:f3b5e79a8488 | 928 | case 10: |
jngarlitos | 1:f3b5e79a8488 | 929 | pc.printf(" CRC settings \n"); |
jngarlitos | 1:f3b5e79a8488 | 930 | pc.printf(" 1 - Disable CRC\n"); |
jngarlitos | 1:f3b5e79a8488 | 931 | pc.printf(" 2 - 8-bit polynomial CRC\n"); |
jngarlitos | 1:f3b5e79a8488 | 932 | pc.printf(" 3 - XOR based CRC\n"); |
jngarlitos | 1:f3b5e79a8488 | 933 | |
jngarlitos | 1:f3b5e79a8488 | 934 | getUserInput(&new_crc); |
jngarlitos | 1:f3b5e79a8488 | 935 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 936 | |
jngarlitos | 1:f3b5e79a8488 | 937 | switch (new_crc) { |
jngarlitos | 1:f3b5e79a8488 | 938 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 939 | if(ad77681_set_crc_sel(device, AD77681_NO_CRC)==SUCCESS) |
jngarlitos | 1:f3b5e79a8488 | 940 | pc.printf(" CRC disabled\n"); |
jngarlitos | 1:f3b5e79a8488 | 941 | else |
jngarlitos | 1:f3b5e79a8488 | 942 | pc.printf("Command Failed\n"); |
jngarlitos | 1:f3b5e79a8488 | 943 | break; |
jngarlitos | 1:f3b5e79a8488 | 944 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 945 | ad77681_set_crc_sel(device, AD77681_CRC); |
jngarlitos | 1:f3b5e79a8488 | 946 | pc.printf(" 8-bit polynomial CRC method selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 947 | break; |
jngarlitos | 1:f3b5e79a8488 | 948 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 949 | ad77681_set_crc_sel(device, AD77681_XOR); |
jngarlitos | 1:f3b5e79a8488 | 950 | pc.printf(" XOR based CRC method selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 951 | break; |
jngarlitos | 1:f3b5e79a8488 | 952 | default: |
jngarlitos | 1:f3b5e79a8488 | 953 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 954 | break; |
jngarlitos | 1:f3b5e79a8488 | 955 | } |
jngarlitos | 1:f3b5e79a8488 | 956 | break; |
jngarlitos | 1:f3b5e79a8488 | 957 | |
jngarlitos | 1:f3b5e79a8488 | 958 | default: |
jngarlitos | 1:f3b5e79a8488 | 959 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 960 | break; |
jngarlitos | 1:f3b5e79a8488 | 961 | } |
jngarlitos | 1:f3b5e79a8488 | 962 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 963 | } |
jngarlitos | 1:f3b5e79a8488 | 964 | |
jngarlitos | 1:f3b5e79a8488 | 965 | /** |
jngarlitos | 1:f3b5e79a8488 | 966 | * Set diagnostic mode |
jngarlitos | 1:f3b5e79a8488 | 967 | * |
jngarlitos | 1:f3b5e79a8488 | 968 | */ |
jngarlitos | 1:f3b5e79a8488 | 969 | void static menu_10_set_ad77681_diagnostic_mode(void) |
jngarlitos | 1:f3b5e79a8488 | 970 | { |
jngarlitos | 1:f3b5e79a8488 | 971 | uint32_t new_diag_mode = 0; |
jngarlitos | 1:f3b5e79a8488 | 972 | |
jngarlitos | 1:f3b5e79a8488 | 973 | pc.printf(" ADC diagnostic modes: \n"); |
jngarlitos | 1:f3b5e79a8488 | 974 | pc.printf(" 1 - Internal temperature sensor\n"); |
jngarlitos | 1:f3b5e79a8488 | 975 | pc.printf(" 2 - AIN shorted\n"); |
jngarlitos | 1:f3b5e79a8488 | 976 | pc.printf(" 3 - Positive full-scale\n"); |
jngarlitos | 1:f3b5e79a8488 | 977 | pc.printf(" 4 - Negative full-scale\n"); |
jngarlitos | 1:f3b5e79a8488 | 978 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 979 | |
jngarlitos | 1:f3b5e79a8488 | 980 | getUserInput(&new_diag_mode); |
jngarlitos | 1:f3b5e79a8488 | 981 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 982 | |
jngarlitos | 1:f3b5e79a8488 | 983 | switch (new_diag_mode) { |
jngarlitos | 1:f3b5e79a8488 | 984 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 985 | ad77681_set_conv_mode(device, device->conv_mode, AD77681_TEMP_SENSOR, true); |
jngarlitos | 1:f3b5e79a8488 | 986 | pc.printf(" Diagnostic mode: Internal temperature sensor selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 987 | break; |
jngarlitos | 1:f3b5e79a8488 | 988 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 989 | ad77681_set_conv_mode(device, device->conv_mode, AD77681_AIN_SHORT, true); |
jngarlitos | 1:f3b5e79a8488 | 990 | pc.printf(" Diagnostic mode: AIN shorted selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 991 | break; |
jngarlitos | 1:f3b5e79a8488 | 992 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 993 | ad77681_set_conv_mode(device, device->conv_mode, AD77681_POSITIVE_FS, true); |
jngarlitos | 1:f3b5e79a8488 | 994 | pc.printf(" Diagnostic mode: Positive full-scale selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 995 | break; |
jngarlitos | 1:f3b5e79a8488 | 996 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 997 | ad77681_set_conv_mode(device, device->conv_mode, AD77681_NEGATIVE_FS, true); |
jngarlitos | 1:f3b5e79a8488 | 998 | pc.printf(" Diagnostic mode: Negative full-scale selected\n"); |
jngarlitos | 1:f3b5e79a8488 | 999 | break; |
jngarlitos | 1:f3b5e79a8488 | 1000 | default: |
jngarlitos | 1:f3b5e79a8488 | 1001 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1002 | break; |
jngarlitos | 1:f3b5e79a8488 | 1003 | } |
jngarlitos | 1:f3b5e79a8488 | 1004 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1005 | } |
jngarlitos | 1:f3b5e79a8488 | 1006 | |
jngarlitos | 1:f3b5e79a8488 | 1007 | /** |
jngarlitos | 1:f3b5e79a8488 | 1008 | * Set Gains and Offsets |
jngarlitos | 1:f3b5e79a8488 | 1009 | * |
jngarlitos | 1:f3b5e79a8488 | 1010 | */ |
jngarlitos | 1:f3b5e79a8488 | 1011 | void static menu_11_set_ad77681_gains_offsets(void) |
jngarlitos | 1:f3b5e79a8488 | 1012 | { |
jngarlitos | 1:f3b5e79a8488 | 1013 | uint32_t gain_offset, ret; |
jngarlitos | 1:f3b5e79a8488 | 1014 | uint32_t new_menu_select; |
jngarlitos | 1:f3b5e79a8488 | 1015 | |
jngarlitos | 1:f3b5e79a8488 | 1016 | pc.printf(" Gains and Offsets settings: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1017 | pc.printf(" 1 - Set gain\n"); |
jngarlitos | 1:f3b5e79a8488 | 1018 | pc.printf(" 2 - Set offset\n"); |
jngarlitos | 1:f3b5e79a8488 | 1019 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1020 | |
jngarlitos | 1:f3b5e79a8488 | 1021 | getUserInput(&new_menu_select); |
jngarlitos | 1:f3b5e79a8488 | 1022 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1023 | |
jngarlitos | 1:f3b5e79a8488 | 1024 | switch (new_menu_select) { |
jngarlitos | 1:f3b5e79a8488 | 1025 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 1026 | pc.printf(" Insert new Gain value in decimal form\n"); |
jngarlitos | 1:f3b5e79a8488 | 1027 | ret = getUserInput(&gain_offset); |
jngarlitos | 1:f3b5e79a8488 | 1028 | |
jngarlitos | 1:f3b5e79a8488 | 1029 | if ((gain_offset <= 0xFFFFFF) && (ret == SUCCESS)) { |
jngarlitos | 1:f3b5e79a8488 | 1030 | ad77681_apply_gain(device, gain_offset); |
jngarlitos | 1:f3b5e79a8488 | 1031 | pc.printf(" Value %d has been successfully inserted to the Gain register\n", gain_offset); |
jngarlitos | 1:f3b5e79a8488 | 1032 | } else |
jngarlitos | 1:f3b5e79a8488 | 1033 | pc.printf(" Invalid value\n"); |
jngarlitos | 1:f3b5e79a8488 | 1034 | break; |
jngarlitos | 1:f3b5e79a8488 | 1035 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 1036 | pc.printf(" Insert new Offset value in decimal form\n"); |
jngarlitos | 1:f3b5e79a8488 | 1037 | ret = getUserInput(&gain_offset); |
jngarlitos | 1:f3b5e79a8488 | 1038 | |
jngarlitos | 1:f3b5e79a8488 | 1039 | if ((gain_offset <= 0xFFFFFF) && (ret == SUCCESS)) { |
jngarlitos | 1:f3b5e79a8488 | 1040 | ad77681_apply_offset(device, gain_offset); |
jngarlitos | 1:f3b5e79a8488 | 1041 | pc.printf(" Value %d has been successfully inserted to the Offset register\n", gain_offset); |
jngarlitos | 1:f3b5e79a8488 | 1042 | } else |
jngarlitos | 1:f3b5e79a8488 | 1043 | pc.printf(" Invalid value\n"); |
jngarlitos | 1:f3b5e79a8488 | 1044 | break; |
jngarlitos | 1:f3b5e79a8488 | 1045 | default: |
jngarlitos | 1:f3b5e79a8488 | 1046 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1047 | break; |
jngarlitos | 1:f3b5e79a8488 | 1048 | } |
jngarlitos | 1:f3b5e79a8488 | 1049 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1050 | } |
jngarlitos | 1:f3b5e79a8488 | 1051 | |
jngarlitos | 1:f3b5e79a8488 | 1052 | /** |
jngarlitos | 1:f3b5e79a8488 | 1053 | * Read ADC status from status registers |
jngarlitos | 1:f3b5e79a8488 | 1054 | * |
jngarlitos | 1:f3b5e79a8488 | 1055 | */ |
jngarlitos | 1:f3b5e79a8488 | 1056 | void static menu_12_ad77681_read_master_status(void) |
jngarlitos | 1:f3b5e79a8488 | 1057 | { |
jngarlitos | 1:f3b5e79a8488 | 1058 | uint8_t reg_read_buf[3]; |
jngarlitos | 1:f3b5e79a8488 | 1059 | char binary_number[8]; |
jngarlitos | 1:f3b5e79a8488 | 1060 | |
jngarlitos | 1:f3b5e79a8488 | 1061 | ad77681_status(device, current_status); // Read AD7768-1 Status |
jngarlitos | 1:f3b5e79a8488 | 1062 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1063 | pc.printf("== MASTER STATUS REGISER\n"); |
jngarlitos | 1:f3b5e79a8488 | 1064 | pc.printf("Master error: %s\n", ((current_status->master_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1065 | pc.printf("ADC error: %s\n", ((current_status->adc_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1066 | pc.printf("Dig error: %s\n", ((current_status->dig_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1067 | pc.printf("Ext. clock: %s\n", ((current_status->adc_err_ext_clk_qual == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1068 | pc.printf("Filter saturated: %s\n", ((current_status->adc_filt_saturated == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1069 | pc.printf("Filter not settled: %s\n", ((current_status->adc_filt_not_settled == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1070 | pc.printf("SPI error: %s\n", ((current_status->spi_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1071 | pc.printf("POR Flag: %s\n", ((current_status->por_flag == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1072 | |
jngarlitos | 1:f3b5e79a8488 | 1073 | if (current_status->spi_error == 1) { |
jngarlitos | 1:f3b5e79a8488 | 1074 | pc.printf("\n== SPI DIAG STATUS REGISER\n"); |
jngarlitos | 1:f3b5e79a8488 | 1075 | pc.printf("SPI ignore error: %s\n", ((current_status->spi_ignore == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1076 | pc.printf("SPI clock count error: %s\n", ((current_status->spi_clock_count == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1077 | pc.printf("SPI read error: %s\n", ((current_status->spi_read_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1078 | pc.printf("SPI write error: %s\n", ((current_status->spi_write_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1079 | pc.printf("SPI CRC error: %s\n", ((current_status->spi_crc_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1080 | } |
jngarlitos | 1:f3b5e79a8488 | 1081 | |
jngarlitos | 1:f3b5e79a8488 | 1082 | if (current_status->adc_error == 1) { |
jngarlitos | 1:f3b5e79a8488 | 1083 | pc.printf("\n== ADC DIAG STATUS REGISER\n"); |
jngarlitos | 1:f3b5e79a8488 | 1084 | pc.printf("DLDO PSM error: %s\n", ((current_status->dldo_psm_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1085 | pc.printf("ALDO PSM error: %s\n", ((current_status->aldo_psm_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1086 | pc.printf("REF DET error: %s\n", ((current_status->ref_det_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1087 | pc.printf("FILT SAT error: %s\n", ((current_status->filt_sat_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1088 | pc.printf("FILT NOT SET error: %s\n", ((current_status->filt_not_set_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1089 | pc.printf("EXT CLK QUAL error: %s\n", ((current_status->ext_clk_qual_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1090 | } |
jngarlitos | 1:f3b5e79a8488 | 1091 | |
jngarlitos | 1:f3b5e79a8488 | 1092 | if (current_status->dig_error == 1) { |
jngarlitos | 1:f3b5e79a8488 | 1093 | pc.printf("\n== DIGITAL DIAG STATUS REGISER\n"); |
jngarlitos | 1:f3b5e79a8488 | 1094 | pc.printf("Memory map CRC error: %s\n", ((current_status->memoy_map_crc_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1095 | pc.printf("RAM CRC error: %s\n", ((current_status->ram_crc_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1096 | pc.printf("FUSE CRC error: %s\n", ((current_status->fuse_crc_error == 0) ? "OK" : "FAULT")); |
jngarlitos | 1:f3b5e79a8488 | 1097 | } |
jngarlitos | 1:f3b5e79a8488 | 1098 | |
jngarlitos | 1:f3b5e79a8488 | 1099 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1100 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1101 | } |
jngarlitos | 1:f3b5e79a8488 | 1102 | |
jngarlitos | 1:f3b5e79a8488 | 1103 | /** |
jngarlitos | 1:f3b5e79a8488 | 1104 | * Register read |
jngarlitos | 1:f3b5e79a8488 | 1105 | * |
jngarlitos | 1:f3b5e79a8488 | 1106 | */ |
jngarlitos | 1:f3b5e79a8488 | 1107 | void static menu_13_ad77681_read_register(void) |
jngarlitos | 1:f3b5e79a8488 | 1108 | { |
jngarlitos | 1:f3b5e79a8488 | 1109 | uint32_t new_reg_to_read = 0; |
jngarlitos | 1:f3b5e79a8488 | 1110 | uint8_t reg_read_buf[3], read_adc_data[6], hex_number = 0; |
jngarlitos | 1:f3b5e79a8488 | 1111 | uint8_t HI = 0, MID = 0, LO = 0; |
jngarlitos | 1:f3b5e79a8488 | 1112 | char binary_number[8]; |
jngarlitos | 1:f3b5e79a8488 | 1113 | |
jngarlitos | 1:f3b5e79a8488 | 1114 | pc.printf(" Read desired register: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1115 | pc.printf(" 1 - 0x03 - Chip type\n"); |
jngarlitos | 1:f3b5e79a8488 | 1116 | pc.printf(" 2 - 0x14 - Interface format\n"); |
jngarlitos | 1:f3b5e79a8488 | 1117 | pc.printf(" 3 - 0x15 - Power clock\n"); |
jngarlitos | 1:f3b5e79a8488 | 1118 | pc.printf(" 4 - 0x16 - Analog\n"); |
jngarlitos | 1:f3b5e79a8488 | 1119 | pc.printf(" 5 - 0x17 - Analog2\n"); |
jngarlitos | 1:f3b5e79a8488 | 1120 | pc.printf(" 6 - 0x18 - Conversion\n"); |
jngarlitos | 1:f3b5e79a8488 | 1121 | pc.printf(" 7 - 0x19 - Digital filter\n"); |
jngarlitos | 1:f3b5e79a8488 | 1122 | pc.printf(" 8 - 0x1A - SINC3 Dec. rate MSB\n"); |
jngarlitos | 1:f3b5e79a8488 | 1123 | pc.printf(" 9 - 0x1B - SINC3 Dec. rate LSB\n"); |
jngarlitos | 1:f3b5e79a8488 | 1124 | pc.printf(" 10 - 0x1C - Duty cycle ratio\n"); |
jngarlitos | 1:f3b5e79a8488 | 1125 | pc.printf(" 11 - 0x1D - Sync, Reset\n"); |
jngarlitos | 1:f3b5e79a8488 | 1126 | pc.printf(" 12 - 0x1E - GPIO Controll\n"); |
jngarlitos | 1:f3b5e79a8488 | 1127 | pc.printf(" 13 - 0x1F - GPIO Write\n"); |
jngarlitos | 1:f3b5e79a8488 | 1128 | pc.printf(" 14 - 0x20 - GPIO Read\n"); |
jngarlitos | 1:f3b5e79a8488 | 1129 | pc.printf(" 15 - 0x21 - 0x23 - Offset register\n"); |
jngarlitos | 1:f3b5e79a8488 | 1130 | pc.printf(" 16 - 0x24 - 0x26 - Gain register\n"); |
jngarlitos | 1:f3b5e79a8488 | 1131 | pc.printf(" 17 - 0x2C - ADC Data\n"); |
jngarlitos | 1:f3b5e79a8488 | 1132 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1133 | |
jngarlitos | 1:f3b5e79a8488 | 1134 | getUserInput(&new_reg_to_read); |
jngarlitos | 1:f3b5e79a8488 | 1135 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1136 | |
jngarlitos | 1:f3b5e79a8488 | 1137 | switch (new_reg_to_read) { |
jngarlitos | 1:f3b5e79a8488 | 1138 | |
jngarlitos | 1:f3b5e79a8488 | 1139 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 1140 | ad77681_spi_reg_read(device, AD77681_REG_CHIP_TYPE, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1141 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1142 | pc.printf(" Value of 0x03 - Chip type register is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1143 | break; |
jngarlitos | 1:f3b5e79a8488 | 1144 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 1145 | ad77681_spi_reg_read(device, AD77681_REG_INTERFACE_FORMAT, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1146 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1147 | pc.printf(" Value of 0x14 - Interface format register is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1148 | break; |
jngarlitos | 1:f3b5e79a8488 | 1149 | case 3: |
jngarlitos | 1:f3b5e79a8488 | 1150 | ad77681_spi_reg_read(device, AD77681_REG_POWER_CLOCK, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1151 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1152 | pc.printf(" Value of 0x15 - Power clock register is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1153 | break; |
jngarlitos | 1:f3b5e79a8488 | 1154 | case 4: |
jngarlitos | 1:f3b5e79a8488 | 1155 | ad77681_spi_reg_read(device, AD77681_REG_ANALOG, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1156 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1157 | pc.printf(" Value of 0x16 - Anlaog register is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1158 | break; |
jngarlitos | 1:f3b5e79a8488 | 1159 | case 5: |
jngarlitos | 1:f3b5e79a8488 | 1160 | ad77681_spi_reg_read(device, AD77681_REG_ANALOG2, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1161 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1162 | pc.printf(" Value of 0x17 - Analog2 regster is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1163 | break; |
jngarlitos | 1:f3b5e79a8488 | 1164 | case 6: |
jngarlitos | 1:f3b5e79a8488 | 1165 | ad77681_spi_reg_read(device, AD77681_REG_CONVERSION, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1166 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1167 | pc.printf(" Value of 0x18 - Conversion register is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1168 | break; |
jngarlitos | 1:f3b5e79a8488 | 1169 | case 7: |
jngarlitos | 1:f3b5e79a8488 | 1170 | ad77681_spi_reg_read(device, AD77681_REG_DIGITAL_FILTER, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1171 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1172 | pc.printf(" Value of 0x19 - Digital filter register is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1173 | break; |
jngarlitos | 1:f3b5e79a8488 | 1174 | case 8: |
jngarlitos | 1:f3b5e79a8488 | 1175 | ad77681_spi_reg_read(device, AD77681_REG_SINC3_DEC_RATE_MSB, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1176 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1177 | pc.printf(" Value of 0x1A - SINC3 Dec. rate MSB is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1178 | break; |
jngarlitos | 1:f3b5e79a8488 | 1179 | case 9: |
jngarlitos | 1:f3b5e79a8488 | 1180 | ad77681_spi_reg_read(device, AD77681_REG_SINC3_DEC_RATE_LSB, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1181 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1182 | pc.printf(" Value of 0x1B - SINC3 Dec. rate LSB is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1183 | break; |
jngarlitos | 1:f3b5e79a8488 | 1184 | case 10: |
jngarlitos | 1:f3b5e79a8488 | 1185 | ad77681_spi_reg_read(device, AD77681_REG_DUTY_CYCLE_RATIO, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1186 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1187 | pc.printf(" Value of 0x1C - Duty cycle ratio 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1188 | break; |
jngarlitos | 1:f3b5e79a8488 | 1189 | case 11: |
jngarlitos | 1:f3b5e79a8488 | 1190 | ad77681_spi_reg_read(device, AD77681_REG_SYNC_RESET, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1191 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1192 | pc.printf(" Value of 0x1D - Sync, Reset 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1193 | break; |
jngarlitos | 1:f3b5e79a8488 | 1194 | case 12: |
jngarlitos | 1:f3b5e79a8488 | 1195 | ad77681_spi_reg_read(device, AD77681_REG_GPIO_CONTROL, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1196 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1197 | pc.printf(" Value of 0x1E - GPIO Controll is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1198 | break; |
jngarlitos | 1:f3b5e79a8488 | 1199 | case 13: |
jngarlitos | 1:f3b5e79a8488 | 1200 | ad77681_spi_reg_read(device, AD77681_REG_GPIO_WRITE, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1201 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1202 | pc.printf(" Value of 0x1F - GPIO Write is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1203 | break; |
jngarlitos | 1:f3b5e79a8488 | 1204 | case 14: |
jngarlitos | 1:f3b5e79a8488 | 1205 | ad77681_spi_reg_read(device, AD77681_REG_GPIO_READ, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1206 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1207 | pc.printf(" Value of 0x20 - GPIO Read is: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1208 | break; |
jngarlitos | 1:f3b5e79a8488 | 1209 | case 15: |
jngarlitos | 1:f3b5e79a8488 | 1210 | ad77681_spi_reg_read(device, AD77681_REG_OFFSET_HI, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1211 | HI = reg_read_buf[1]; |
jngarlitos | 1:f3b5e79a8488 | 1212 | |
jngarlitos | 1:f3b5e79a8488 | 1213 | ad77681_spi_reg_read(device, AD77681_REG_OFFSET_MID, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1214 | MID = reg_read_buf[1]; |
jngarlitos | 1:f3b5e79a8488 | 1215 | |
jngarlitos | 1:f3b5e79a8488 | 1216 | ad77681_spi_reg_read(device, AD77681_REG_OFFSET_LO, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1217 | LO = reg_read_buf[1]; |
jngarlitos | 1:f3b5e79a8488 | 1218 | |
jngarlitos | 1:f3b5e79a8488 | 1219 | pc.printf(" Value of 0x21 - 0x23 - Offset register is: 0x%x %x %x\n", HI, MID, LO); |
jngarlitos | 1:f3b5e79a8488 | 1220 | break; |
jngarlitos | 1:f3b5e79a8488 | 1221 | case 16: |
jngarlitos | 1:f3b5e79a8488 | 1222 | ad77681_spi_reg_read(device, AD77681_REG_GAIN_HI, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1223 | HI = reg_read_buf[1]; |
jngarlitos | 1:f3b5e79a8488 | 1224 | |
jngarlitos | 1:f3b5e79a8488 | 1225 | ad77681_spi_reg_read(device, AD77681_REG_GAIN_MID, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1226 | MID = reg_read_buf[1]; |
jngarlitos | 1:f3b5e79a8488 | 1227 | |
jngarlitos | 1:f3b5e79a8488 | 1228 | ad77681_spi_reg_read(device, AD77681_REG_GAIN_LO, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1229 | LO = reg_read_buf[1]; |
jngarlitos | 1:f3b5e79a8488 | 1230 | |
jngarlitos | 1:f3b5e79a8488 | 1231 | pc.printf(" Value of 0x24 - 0x26 - Gain register is: 0x%x %x %x\n", HI, MID, LO); |
jngarlitos | 1:f3b5e79a8488 | 1232 | break; |
jngarlitos | 1:f3b5e79a8488 | 1233 | case 17: |
jngarlitos | 1:f3b5e79a8488 | 1234 | ad77681_spi_read_adc_data(device, read_adc_data, AD77681_REGISTER_DATA_READ); |
jngarlitos | 1:f3b5e79a8488 | 1235 | pc.printf(" Value of 0x2C - ADC data is: 0x%x 0x%x 0x%x\n", read_adc_data[1], read_adc_data[2], read_adc_data[3]); |
jngarlitos | 1:f3b5e79a8488 | 1236 | break; |
jngarlitos | 1:f3b5e79a8488 | 1237 | case 18: |
jngarlitos | 1:f3b5e79a8488 | 1238 | ad77681_spi_reg_read(device, AD77681_REG_INTERFACE_FORMAT, reg_read_buf); |
jngarlitos | 1:f3b5e79a8488 | 1239 | print_binary(reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1240 | pc.printf(" Value of 0x14 -REG_INTERFACE_FORMATis: 0x%x 0b%s\n", reg_read_buf[1], binary_number); |
jngarlitos | 1:f3b5e79a8488 | 1241 | break; |
jngarlitos | 1:f3b5e79a8488 | 1242 | default : |
jngarlitos | 1:f3b5e79a8488 | 1243 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1244 | break; |
jngarlitos | 1:f3b5e79a8488 | 1245 | } |
jngarlitos | 1:f3b5e79a8488 | 1246 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1247 | } |
jngarlitos | 1:f3b5e79a8488 | 1248 | |
jngarlitos | 1:f3b5e79a8488 | 1249 | /** |
jngarlitos | 1:f3b5e79a8488 | 1250 | * Print measured data and transfered to voltage |
jngarlitos | 1:f3b5e79a8488 | 1251 | * |
jngarlitos | 1:f3b5e79a8488 | 1252 | */ |
jngarlitos | 1:f3b5e79a8488 | 1253 | void static menu_14_read_ad77681_single_conv_data(void) |
jngarlitos | 1:f3b5e79a8488 | 1254 | { |
jngarlitos | 1:f3b5e79a8488 | 1255 | |
jngarlitos | 1:f3b5e79a8488 | 1256 | uint8_t adc_reg[6]; |
jngarlitos | 1:f3b5e79a8488 | 1257 | uint32_t raw_code; |
jngarlitos | 1:f3b5e79a8488 | 1258 | int32_t converted_data; |
jngarlitos | 1:f3b5e79a8488 | 1259 | double voltage; |
jngarlitos | 1:f3b5e79a8488 | 1260 | int32_t shifted_data; |
jngarlitos | 1:f3b5e79a8488 | 1261 | char buf[15]; |
jngarlitos | 1:f3b5e79a8488 | 1262 | |
jngarlitos | 1:f3b5e79a8488 | 1263 | ad77681_spi_read_adc_data(device, adc_reg, AD77681_REGISTER_DATA_READ); |
jngarlitos | 1:f3b5e79a8488 | 1264 | raw_code = (adc_reg[1] << 16) | (adc_reg[2] << 8) | (adc_reg[3] << 0); |
jngarlitos | 1:f3b5e79a8488 | 1265 | // Printing Voltage |
jngarlitos | 1:f3b5e79a8488 | 1266 | pc.printf("\n\nVoltage\n"); |
jngarlitos | 1:f3b5e79a8488 | 1267 | ad77681_data_to_voltage(device, &raw_code, &voltage); |
jngarlitos | 1:f3b5e79a8488 | 1268 | sprintf(buf, "%.9f \n",voltage); |
jngarlitos | 1:f3b5e79a8488 | 1269 | pc.printf(buf); |
jngarlitos | 1:f3b5e79a8488 | 1270 | memset(buf, 0, sizeof(buf));//clears buffer |
jngarlitos | 1:f3b5e79a8488 | 1271 | |
jngarlitos | 1:f3b5e79a8488 | 1272 | // Printing Raw Code |
jngarlitos | 1:f3b5e79a8488 | 1273 | pc.printf("\n\nRaw Code\n"); |
jngarlitos | 1:f3b5e79a8488 | 1274 | pc.printf("%d\n", raw_code); |
jngarlitos | 1:f3b5e79a8488 | 1275 | |
jngarlitos | 1:f3b5e79a8488 | 1276 | // Printing Shifted Code |
jngarlitos | 1:f3b5e79a8488 | 1277 | pc.printf("\n\nShifted Code\n"); |
jngarlitos | 1:f3b5e79a8488 | 1278 | if (raw_code & 0x800000) |
jngarlitos | 1:f3b5e79a8488 | 1279 | shifted_data = (int32_t)((0xFF << 24) | raw_code); |
jngarlitos | 1:f3b5e79a8488 | 1280 | else |
jngarlitos | 1:f3b5e79a8488 | 1281 | shifted_data = (int32_t)((0x00 << 24) | raw_code); |
jngarlitos | 1:f3b5e79a8488 | 1282 | pc.printf("%d\n", shifted_data + AD7768_HALF_SCALE); |
jngarlitos | 1:f3b5e79a8488 | 1283 | |
jngarlitos | 1:f3b5e79a8488 | 1284 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1285 | } |
jngarlitos | 1:f3b5e79a8488 | 1286 | |
jngarlitos | 1:f3b5e79a8488 | 1287 | /** |
jngarlitos | 1:f3b5e79a8488 | 1288 | * Read ADC data |
jngarlitos | 1:f3b5e79a8488 | 1289 | * |
jngarlitos | 1:f3b5e79a8488 | 1290 | */ |
jngarlitos | 1:f3b5e79a8488 | 1291 | void static menu_15_read_ad77681_continuous_data(void) |
jngarlitos | 1:f3b5e79a8488 | 1292 | { |
jngarlitos | 1:f3b5e79a8488 | 1293 | uint8_t buf[6]; |
jngarlitos | 1:f3b5e79a8488 | 1294 | uint32_t new_sample_count = 0; |
jngarlitos | 1:f3b5e79a8488 | 1295 | int32_t ret; |
jngarlitos | 1:f3b5e79a8488 | 1296 | |
jngarlitos | 1:f3b5e79a8488 | 1297 | pc.printf(" Read Continuous ADC Data"); |
jngarlitos | 1:f3b5e79a8488 | 1298 | pc.printf(" Input number of samples (1 to 4096): \n"); |
jngarlitos | 1:f3b5e79a8488 | 1299 | ret = getUserInput(&new_sample_count); // Get user input |
jngarlitos | 1:f3b5e79a8488 | 1300 | |
jngarlitos | 1:f3b5e79a8488 | 1301 | if ((new_sample_count <= 4096) && (ret == SUCCESS) ) { |
jngarlitos | 1:f3b5e79a8488 | 1302 | pc.printf("\n%d of samples\n", new_sample_count); // Print Desired Measurement Count |
jngarlitos | 1:f3b5e79a8488 | 1303 | measured_data.samples = (uint16_t)(new_sample_count); |
jngarlitos | 1:f3b5e79a8488 | 1304 | measured_data.finish = false; |
jngarlitos | 1:f3b5e79a8488 | 1305 | measured_data.count = 0; |
jngarlitos | 1:f3b5e79a8488 | 1306 | pc.printf("Sampling....\n"); |
jngarlitos | 1:f3b5e79a8488 | 1307 | ad77681_set_continuos_read(device, AD77681_CONTINUOUS_READ_ENABLE); |
jngarlitos | 1:f3b5e79a8488 | 1308 | __enable_irq(); // Enable all interupts |
jngarlitos | 1:f3b5e79a8488 | 1309 | drdy.enable_irq(); // Enable interrupt on DRDY pin |
jngarlitos | 1:f3b5e79a8488 | 1310 | drdy.fall(&drdy_interrupt); // Interrupt on falling edne of DRDY |
jngarlitos | 1:f3b5e79a8488 | 1311 | |
jngarlitos | 1:f3b5e79a8488 | 1312 | while (!measured_data.finish) { // While loop. Waiting for the measurements to be completed |
jngarlitos | 1:f3b5e79a8488 | 1313 | if (int_event==true) { // Checks if Interrupt Occurred |
jngarlitos | 1:f3b5e79a8488 | 1314 | ad77681_spi_read_adc_data(device, buf, AD77681_CONTINUOUS_DATA_READ); // Read the continuous read data |
jngarlitos | 1:f3b5e79a8488 | 1315 | if (device->conv_len == AD77681_CONV_24BIT) // 24bit format |
jngarlitos | 1:f3b5e79a8488 | 1316 | measured_data.raw_data[measured_data.count] = (buf[0] << 16 | buf[1] << 8 | buf[2]<< 0); // Combining the SPI buffers |
jngarlitos | 1:f3b5e79a8488 | 1317 | else // 16bit format |
jngarlitos | 1:f3b5e79a8488 | 1318 | measured_data.raw_data[measured_data.count] = (buf[0] << 8 | buf[1]<< 0); // Combining the SPI buffers |
jngarlitos | 1:f3b5e79a8488 | 1319 | measured_data.count++; // Increment Measured Data Counter |
jngarlitos | 1:f3b5e79a8488 | 1320 | int_event=false; // Set int event flag after reading the Data |
jngarlitos | 1:f3b5e79a8488 | 1321 | } |
jngarlitos | 1:f3b5e79a8488 | 1322 | } |
jngarlitos | 1:f3b5e79a8488 | 1323 | ad77681_set_continuos_read(device, AD77681_CONTINUOUS_READ_DISABLE); // Disable continuous ADC read |
jngarlitos | 1:f3b5e79a8488 | 1324 | pc.printf("Done Sampling....\n"); |
jngarlitos | 1:f3b5e79a8488 | 1325 | } |
jngarlitos | 1:f3b5e79a8488 | 1326 | |
jngarlitos | 1:f3b5e79a8488 | 1327 | else { |
jngarlitos | 1:f3b5e79a8488 | 1328 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1329 | } |
jngarlitos | 1:f3b5e79a8488 | 1330 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1331 | } |
jngarlitos | 1:f3b5e79a8488 | 1332 | |
jngarlitos | 1:f3b5e79a8488 | 1333 | /** |
jngarlitos | 1:f3b5e79a8488 | 1334 | * Print measured data and transfered to voltage |
jngarlitos | 1:f3b5e79a8488 | 1335 | * |
jngarlitos | 1:f3b5e79a8488 | 1336 | */ |
jngarlitos | 1:f3b5e79a8488 | 1337 | void static menu_16_print_ad77681_continuos_read_data(void) |
jngarlitos | 1:f3b5e79a8488 | 1338 | { |
jngarlitos | 1:f3b5e79a8488 | 1339 | double voltage; |
jngarlitos | 1:f3b5e79a8488 | 1340 | int32_t shifted_data; |
jngarlitos | 1:f3b5e79a8488 | 1341 | uint16_t i; |
jngarlitos | 1:f3b5e79a8488 | 1342 | char buf[15]; |
jngarlitos | 1:f3b5e79a8488 | 1343 | |
jngarlitos | 1:f3b5e79a8488 | 1344 | if (measured_data.finish) { |
jngarlitos | 1:f3b5e79a8488 | 1345 | // Printing Voltage |
jngarlitos | 1:f3b5e79a8488 | 1346 | pc.printf("\n\nVoltage\n"); |
jngarlitos | 1:f3b5e79a8488 | 1347 | for ( i = 0; i < measured_data.samples; i++) { |
jngarlitos | 1:f3b5e79a8488 | 1348 | ad77681_data_to_voltage(device, &measured_data.raw_data[i], &voltage); |
jngarlitos | 1:f3b5e79a8488 | 1349 | sprintf(buf, "%.9f \n",voltage); |
jngarlitos | 1:f3b5e79a8488 | 1350 | pc.printf(buf); |
jngarlitos | 1:f3b5e79a8488 | 1351 | memset(buf, 0, sizeof(buf));//clears buffer |
jngarlitos | 1:f3b5e79a8488 | 1352 | } |
jngarlitos | 1:f3b5e79a8488 | 1353 | // Printing Codes |
jngarlitos | 1:f3b5e79a8488 | 1354 | pc.printf("\n\nCodes\n"); |
jngarlitos | 1:f3b5e79a8488 | 1355 | for(i = 0 ; i < measured_data.samples ; i++) { |
jngarlitos | 1:f3b5e79a8488 | 1356 | if (measured_data.raw_data[i] & 0x800000) |
jngarlitos | 1:f3b5e79a8488 | 1357 | shifted_data = (int32_t)((0xFF << 24) | measured_data.raw_data[i]); |
jngarlitos | 1:f3b5e79a8488 | 1358 | else |
jngarlitos | 1:f3b5e79a8488 | 1359 | shifted_data = (int32_t)((0x00 << 24) | measured_data.raw_data[i]); |
jngarlitos | 1:f3b5e79a8488 | 1360 | |
jngarlitos | 1:f3b5e79a8488 | 1361 | pc.printf("%d\n", shifted_data + AD7768_HALF_SCALE); |
jngarlitos | 1:f3b5e79a8488 | 1362 | } |
jngarlitos | 1:f3b5e79a8488 | 1363 | // Printing Raw Date |
jngarlitos | 1:f3b5e79a8488 | 1364 | pc.printf("\n\nRaw data\n"); |
jngarlitos | 1:f3b5e79a8488 | 1365 | for (i = 0; i < measured_data.samples; i++) |
jngarlitos | 1:f3b5e79a8488 | 1366 | pc.printf("%d\n", measured_data.raw_data[i]); |
jngarlitos | 1:f3b5e79a8488 | 1367 | // Set measured_data.finish to false after Printing |
jngarlitos | 1:f3b5e79a8488 | 1368 | measured_data.finish = false; |
jngarlitos | 1:f3b5e79a8488 | 1369 | } else |
jngarlitos | 1:f3b5e79a8488 | 1370 | pc.printf("Data not prepared\n"); |
jngarlitos | 1:f3b5e79a8488 | 1371 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1372 | } |
jngarlitos | 1:f3b5e79a8488 | 1373 | |
jngarlitos | 1:f3b5e79a8488 | 1374 | /** |
jngarlitos | 1:f3b5e79a8488 | 1375 | * Chceck read and write functionaity by writing to and reading from scratchpad register |
jngarlitos | 1:f3b5e79a8488 | 1376 | * |
jngarlitos | 1:f3b5e79a8488 | 1377 | */ |
jngarlitos | 1:f3b5e79a8488 | 1378 | void static menu_17_ad77681_check_scratchpad(void) |
jngarlitos | 1:f3b5e79a8488 | 1379 | { |
jngarlitos | 1:f3b5e79a8488 | 1380 | uint32_t new_menu_select; |
jngarlitos | 1:f3b5e79a8488 | 1381 | uint8_t chceck_sequence; |
jngarlitos | 1:f3b5e79a8488 | 1382 | int32_t ret; |
jngarlitos | 1:f3b5e79a8488 | 1383 | |
jngarlitos | 1:f3b5e79a8488 | 1384 | pc.printf(" Scratchpad check\n"); |
jngarlitos | 1:f3b5e79a8488 | 1385 | pc.printf(" Insert 8bit number for scratchpad check: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1386 | |
jngarlitos | 1:f3b5e79a8488 | 1387 | ret = getUserInput(&new_menu_select); // Get user input |
jngarlitos | 1:f3b5e79a8488 | 1388 | |
jngarlitos | 1:f3b5e79a8488 | 1389 | if ((new_menu_select <= 0xFF) && (new_menu_select >= 0) && (ret == SUCCESS)) { |
jngarlitos | 1:f3b5e79a8488 | 1390 | chceck_sequence = (uint8_t)(new_menu_select); |
jngarlitos | 1:f3b5e79a8488 | 1391 | ret = ad77681_scratchpad(device, &chceck_sequence); // Write and read Scratch Pad |
jngarlitos | 1:f3b5e79a8488 | 1392 | pc.printf(" Insered sequence: %d\n Returned sequence: %d\n", new_menu_select, chceck_sequence); |
jngarlitos | 1:f3b5e79a8488 | 1393 | if (ret == SUCCESS) |
jngarlitos | 1:f3b5e79a8488 | 1394 | pc.printf(" SUCCESS!\n"); |
jngarlitos | 1:f3b5e79a8488 | 1395 | else |
jngarlitos | 1:f3b5e79a8488 | 1396 | pc.printf(" FAILURE!\n"); |
jngarlitos | 1:f3b5e79a8488 | 1397 | } else |
jngarlitos | 1:f3b5e79a8488 | 1398 | pc.printf(" Invalid value\n"); |
jngarlitos | 1:f3b5e79a8488 | 1399 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1400 | } |
jngarlitos | 1:f3b5e79a8488 | 1401 | |
jngarlitos | 1:f3b5e79a8488 | 1402 | void static menu_18_reset_ad77681_ADC(void) |
jngarlitos | 1:f3b5e79a8488 | 1403 | { |
jngarlitos | 1:f3b5e79a8488 | 1404 | uint32_t new_reset_option = 0; |
jngarlitos | 1:f3b5e79a8488 | 1405 | |
jngarlitos | 1:f3b5e79a8488 | 1406 | pc.printf(" ADC reset opportunities: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1407 | pc.printf(" 1 - Soft reset - over SPI\n"); |
jngarlitos | 1:f3b5e79a8488 | 1408 | pc.printf(" 2 - Hard reset - uing RESET pin\n"); |
jngarlitos | 1:f3b5e79a8488 | 1409 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1410 | |
jngarlitos | 1:f3b5e79a8488 | 1411 | getUserInput(&new_reset_option); |
jngarlitos | 1:f3b5e79a8488 | 1412 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1413 | |
jngarlitos | 1:f3b5e79a8488 | 1414 | switch (new_reset_option) { |
jngarlitos | 1:f3b5e79a8488 | 1415 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 1416 | ad77681_soft_reset(device); // Perform soft reset thru SPI write |
jngarlitos | 1:f3b5e79a8488 | 1417 | pc.printf(" ADC after soft reset\n"); |
jngarlitos | 1:f3b5e79a8488 | 1418 | break; |
jngarlitos | 1:f3b5e79a8488 | 1419 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 1420 | adc_hard_reset(); // Perform hard reset thru GPIO |
jngarlitos | 1:f3b5e79a8488 | 1421 | pc.printf(" ADC after hard reset\n"); |
jngarlitos | 1:f3b5e79a8488 | 1422 | break; |
jngarlitos | 1:f3b5e79a8488 | 1423 | default: |
jngarlitos | 1:f3b5e79a8488 | 1424 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1425 | break; |
jngarlitos | 1:f3b5e79a8488 | 1426 | } |
jngarlitos | 1:f3b5e79a8488 | 1427 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1428 | } |
jngarlitos | 1:f3b5e79a8488 | 1429 | |
jngarlitos | 1:f3b5e79a8488 | 1430 | /** |
jngarlitos | 1:f3b5e79a8488 | 1431 | * Rest and set the Board to default setting |
jngarlitos | 1:f3b5e79a8488 | 1432 | * |
jngarlitos | 1:f3b5e79a8488 | 1433 | */ |
jngarlitos | 1:f3b5e79a8488 | 1434 | void static menu_19_set_default_settings(void) |
jngarlitos | 1:f3b5e79a8488 | 1435 | { |
jngarlitos | 1:f3b5e79a8488 | 1436 | |
jngarlitos | 1:f3b5e79a8488 | 1437 | int32_t default_settings_flag; |
jngarlitos | 1:f3b5e79a8488 | 1438 | |
jngarlitos | 1:f3b5e79a8488 | 1439 | adc_hard_reset(); // Perform hard reset thru GPIO |
jngarlitos | 1:f3b5e79a8488 | 1440 | default_settings_flag = ad77681_setup(&device, init_params, ¤t_status); // SETUP and check connection |
jngarlitos | 1:f3b5e79a8488 | 1441 | adc_gpio_init(); // Initilized SDP-K1 GPIOS |
jngarlitos | 1:f3b5e79a8488 | 1442 | |
jngarlitos | 1:f3b5e79a8488 | 1443 | if (default_settings_flag == SUCCESS) |
jngarlitos | 1:f3b5e79a8488 | 1444 | pc.printf("\n Default settings successfull loaded\n"); |
jngarlitos | 1:f3b5e79a8488 | 1445 | else |
jngarlitos | 1:f3b5e79a8488 | 1446 | pc.printf("\n Error in settings, please reset the ADC\n"); |
jngarlitos | 1:f3b5e79a8488 | 1447 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1448 | } |
jngarlitos | 1:f3b5e79a8488 | 1449 | |
jngarlitos | 1:f3b5e79a8488 | 1450 | /** |
jngarlitos | 1:f3b5e79a8488 | 1451 | * Set Vref anc MCLK as "exteranl" values, depending on you setup |
jngarlitos | 1:f3b5e79a8488 | 1452 | * |
jngarlitos | 1:f3b5e79a8488 | 1453 | */ |
jngarlitos | 1:f3b5e79a8488 | 1454 | void static menu_20_mclk_vref(void) |
jngarlitos | 1:f3b5e79a8488 | 1455 | { |
jngarlitos | 1:f3b5e79a8488 | 1456 | uint32_t input = 0, new_settings = 0; |
jngarlitos | 1:f3b5e79a8488 | 1457 | int32_t ret; |
jngarlitos | 1:f3b5e79a8488 | 1458 | |
jngarlitos | 1:f3b5e79a8488 | 1459 | pc.printf(" Set Vref and Mclk: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1460 | pc.printf(" 1 - Change Vref\n"); |
jngarlitos | 1:f3b5e79a8488 | 1461 | pc.printf(" 2 - Change MCLK\n"); |
jngarlitos | 1:f3b5e79a8488 | 1462 | pc.printf(" Select an option: \n"); |
jngarlitos | 1:f3b5e79a8488 | 1463 | |
jngarlitos | 1:f3b5e79a8488 | 1464 | getUserInput(&new_settings); |
jngarlitos | 1:f3b5e79a8488 | 1465 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1466 | |
jngarlitos | 1:f3b5e79a8488 | 1467 | switch (new_settings) { |
jngarlitos | 1:f3b5e79a8488 | 1468 | case 1: |
jngarlitos | 1:f3b5e79a8488 | 1469 | pc.printf(" Change Vref from %d mV to [mV]: ", device->vref); // Vref change |
jngarlitos | 1:f3b5e79a8488 | 1470 | ret = getUserInput(&input); |
jngarlitos | 1:f3b5e79a8488 | 1471 | |
jngarlitos | 1:f3b5e79a8488 | 1472 | if ((input >= 1000) && (input <= 5000) && (ret == SUCCESS)) { |
jngarlitos | 1:f3b5e79a8488 | 1473 | pc.printf("\n New Vref value is %d mV", input); |
jngarlitos | 1:f3b5e79a8488 | 1474 | device->vref = input; |
jngarlitos | 1:f3b5e79a8488 | 1475 | } else |
jngarlitos | 1:f3b5e79a8488 | 1476 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1477 | |
jngarlitos | 1:f3b5e79a8488 | 1478 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1479 | break; |
jngarlitos | 1:f3b5e79a8488 | 1480 | |
jngarlitos | 1:f3b5e79a8488 | 1481 | case 2: |
jngarlitos | 1:f3b5e79a8488 | 1482 | pc.printf(" Change MCLK from %d kHz to [kHz]: ", device->mclk); // MCLK change |
jngarlitos | 1:f3b5e79a8488 | 1483 | ret = getUserInput(&input); |
jngarlitos | 1:f3b5e79a8488 | 1484 | if ((input >= 10000) && (input <= 50000) && (ret == SUCCESS)) { |
jngarlitos | 1:f3b5e79a8488 | 1485 | pc.printf("\n New MCLK value is %d kHz\n", input); |
jngarlitos | 1:f3b5e79a8488 | 1486 | device->vref = input; |
jngarlitos | 1:f3b5e79a8488 | 1487 | ad77681_update_sample_rate(device); // Update the sample rate after changinig the MCLK |
jngarlitos | 1:f3b5e79a8488 | 1488 | } else |
jngarlitos | 1:f3b5e79a8488 | 1489 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1490 | |
jngarlitos | 1:f3b5e79a8488 | 1491 | pc.putc('\n'); |
jngarlitos | 1:f3b5e79a8488 | 1492 | break; |
jngarlitos | 1:f3b5e79a8488 | 1493 | default: |
jngarlitos | 1:f3b5e79a8488 | 1494 | pc.printf(" Invalid option\n"); |
jngarlitos | 1:f3b5e79a8488 | 1495 | break; |
jngarlitos | 1:f3b5e79a8488 | 1496 | } |
jngarlitos | 1:f3b5e79a8488 | 1497 | print_prompt(); |
jngarlitos | 1:f3b5e79a8488 | 1498 | } |
jngarlitos | 1:f3b5e79a8488 | 1499 | |
jngarlitos | 1:f3b5e79a8488 | 1500 | /** |
jngarlitos | 1:f3b5e79a8488 | 1501 | * Prints out an array in binary form |
jngarlitos | 1:f3b5e79a8488 | 1502 | * |
jngarlitos | 1:f3b5e79a8488 | 1503 | */ |
jngarlitos | 1:f3b5e79a8488 | 1504 | void static print_binary(uint8_t number, char *binary_number) |
jngarlitos | 1:f3b5e79a8488 | 1505 | { |
jngarlitos | 1:f3b5e79a8488 | 1506 | for (int8_t i = 7; i >= 0; i--) { |
jngarlitos | 1:f3b5e79a8488 | 1507 | if (number & 1) |
jngarlitos | 1:f3b5e79a8488 | 1508 | binary_number[i] = '1'; |
jngarlitos | 1:f3b5e79a8488 | 1509 | else |
jngarlitos | 1:f3b5e79a8488 | 1510 | binary_number[i] = '0'; |
jngarlitos | 1:f3b5e79a8488 | 1511 | number >>= 1; |
jngarlitos | 1:f3b5e79a8488 | 1512 | } |
jngarlitos | 1:f3b5e79a8488 | 1513 | } |
jngarlitos | 1:f3b5e79a8488 | 1514 | |
jngarlitos | 1:f3b5e79a8488 | 1515 | /** |
jngarlitos | 1:f3b5e79a8488 | 1516 | * Read user input from uart |
jngarlitos | 1:f3b5e79a8488 | 1517 | * *UserInput = 0 if failure |
jngarlitos | 1:f3b5e79a8488 | 1518 | * |
jngarlitos | 1:f3b5e79a8488 | 1519 | */ |
jngarlitos | 1:f3b5e79a8488 | 1520 | int32_t static getUserInput(uint32_t *UserInput) |
jngarlitos | 1:f3b5e79a8488 | 1521 | { |
jngarlitos | 1:f3b5e79a8488 | 1522 | long uart_val; |
jngarlitos | 1:f3b5e79a8488 | 1523 | int32_t ret; |
jngarlitos | 1:f3b5e79a8488 | 1524 | |
jngarlitos | 1:f3b5e79a8488 | 1525 | ret = pc.scanf("%ld", &uart_val); // Return 1 = OK, Return 0 = Fail |
jngarlitos | 1:f3b5e79a8488 | 1526 | |
jngarlitos | 1:f3b5e79a8488 | 1527 | if((ret == 0) || (uart_val < 0)) { // Failure if uart_val is negative, or non-digit |
jngarlitos | 1:f3b5e79a8488 | 1528 | *UserInput = 0; |
jngarlitos | 1:f3b5e79a8488 | 1529 | return FAILURE; |
jngarlitos | 1:f3b5e79a8488 | 1530 | } |
jngarlitos | 1:f3b5e79a8488 | 1531 | *UserInput = (uint32_t)(uart_val); |
jngarlitos | 1:f3b5e79a8488 | 1532 | return SUCCESS; |
jngarlitos | 1:f3b5e79a8488 | 1533 | } |
jngarlitos | 1:f3b5e79a8488 | 1534 | |
jngarlitos | 1:f3b5e79a8488 | 1535 | /** |
jngarlitos | 1:f3b5e79a8488 | 1536 | * ADC hard reset thru SDP-K1 GPIO |
jngarlitos | 1:f3b5e79a8488 | 1537 | * |
jngarlitos | 1:f3b5e79a8488 | 1538 | */ |
jngarlitos | 1:f3b5e79a8488 | 1539 | void static adc_hard_reset() |
jngarlitos | 1:f3b5e79a8488 | 1540 | { |
jngarlitos | 1:f3b5e79a8488 | 1541 | adc_rst=0; // Set ADC reset pin to Low |
jngarlitos | 1:f3b5e79a8488 | 1542 | mdelay(100); // Delay 100ms |
jngarlitos | 1:f3b5e79a8488 | 1543 | adc_rst=1; // Set ADC reset pin to High |
jngarlitos | 1:f3b5e79a8488 | 1544 | mdelay(100); // Delay 100ms |
jngarlitos | 1:f3b5e79a8488 | 1545 | } |
jngarlitos | 1:f3b5e79a8488 | 1546 | |
jngarlitos | 1:f3b5e79a8488 | 1547 | /** |
jngarlitos | 1:f3b5e79a8488 | 1548 | * ADC hard reset thru SDP-K1 GPIO |
jngarlitos | 1:f3b5e79a8488 | 1549 | * |
jngarlitos | 1:f3b5e79a8488 | 1550 | */ |
jngarlitos | 1:f3b5e79a8488 | 1551 | void static adc_gpio_init() |
jngarlitos | 1:f3b5e79a8488 | 1552 | { |
jngarlitos | 1:f3b5e79a8488 | 1553 | ad77681_global_gpio(device, AD77681_GLOBAL_GPIO_ENABLE); // Enable AD7768-1 GPIO pins |
jngarlitos | 1:f3b5e79a8488 | 1554 | ad77681_gpio_inout(device, AD77681_GPIO_CNTRL_ALL_GPIOS_OP_EN(0x0F), AD77681_ALL_GPIOS); // Set AD7768-1 GPIO1 - GPIO3 as Output |
jngarlitos | 1:f3b5e79a8488 | 1555 | ad77681_gpio_write(device,AD77681_GPIO_CNTRL_ALL_GPIOS_OP_EN(0x05), AD77681_ALL_GPIOS); // Set FDA to Low Power mode and PGIA Gain to 1 |
jngarlitos | 1:f3b5e79a8488 | 1556 | } |