![](/media/cache/group/ADI_Logo_AWP_zgjvy7B.png.50x50_q85.png)
Example Program for EVAL-AD7606
Dependencies: platform_drivers
app/ad7606_support.c@7:054dbd5e1f45, 2021-08-03 (annotated)
- Committer:
- Kjansen
- Date:
- Tue Aug 03 11:54:49 2021 +0100
- Revision:
- 7:054dbd5e1f45
- Parent:
- 1:819ac9aa5667
Modified the ADC data capture module to remove dependancy on type of ADC and it's specific operations
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mahphalke |
1:819ac9aa5667 | 1 | /*************************************************************************//** |
mahphalke |
1:819ac9aa5667 | 2 | * @file ad7606_support.c |
mahphalke |
1:819ac9aa5667 | 3 | * @brief AD7606 device No-OS driver supports |
mahphalke |
1:819ac9aa5667 | 4 | ****************************************************************************** |
mahphalke |
1:819ac9aa5667 | 5 | * Copyright (c) 2020 Analog Devices, Inc. |
mahphalke |
1:819ac9aa5667 | 6 | * |
mahphalke |
1:819ac9aa5667 | 7 | * All rights reserved. |
mahphalke |
1:819ac9aa5667 | 8 | * |
mahphalke |
1:819ac9aa5667 | 9 | * This software is proprietary to Analog Devices, Inc. and its licensors. |
mahphalke |
1:819ac9aa5667 | 10 | * By using this software you agree to the terms of the associated |
mahphalke |
1:819ac9aa5667 | 11 | * Analog Devices Software License Agreement. |
mahphalke |
1:819ac9aa5667 | 12 | *****************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 13 | |
mahphalke |
1:819ac9aa5667 | 14 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 15 | /***************************** Include Files **********************************/ |
mahphalke |
1:819ac9aa5667 | 16 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 17 | |
mahphalke |
1:819ac9aa5667 | 18 | #include <stdint.h> |
mahphalke |
1:819ac9aa5667 | 19 | |
mahphalke |
1:819ac9aa5667 | 20 | #include "app_config.h" |
mahphalke |
1:819ac9aa5667 | 21 | #include "ad7606_support.h" |
mahphalke |
1:819ac9aa5667 | 22 | #include "ad7606_data_capture.h" |
mahphalke |
1:819ac9aa5667 | 23 | |
mahphalke |
1:819ac9aa5667 | 24 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 25 | /********************** Macros and Constants Definition ***********************/ |
mahphalke |
1:819ac9aa5667 | 26 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 27 | |
mahphalke |
1:819ac9aa5667 | 28 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 29 | /********************** Variables and User Defined Data Types *****************/ |
mahphalke |
1:819ac9aa5667 | 30 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 31 | |
mahphalke |
1:819ac9aa5667 | 32 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 33 | /************************ Functions Definitions *******************************/ |
mahphalke |
1:819ac9aa5667 | 34 | /******************************************************************************/ |
mahphalke |
1:819ac9aa5667 | 35 | |
mahphalke |
1:819ac9aa5667 | 36 | /*! |
mahphalke |
1:819ac9aa5667 | 37 | * @brief Function to convert adc raw data into equivalent voltage |
mahphalke |
1:819ac9aa5667 | 38 | * @param adc_raw[in] - ADC raw data |
mahphalke |
1:819ac9aa5667 | 39 | * @param scale[in] - ADC raw to voltage conversion scale |
mahphalke |
1:819ac9aa5667 | 40 | * @return equivalent voltage |
mahphalke |
1:819ac9aa5667 | 41 | */ |
mahphalke |
1:819ac9aa5667 | 42 | float convert_adc_raw_to_voltage(int32_t adc_raw, float scale) |
mahphalke |
1:819ac9aa5667 | 43 | { |
mahphalke |
1:819ac9aa5667 | 44 | float voltage; |
mahphalke |
1:819ac9aa5667 | 45 | |
mahphalke |
1:819ac9aa5667 | 46 | /* Convert adc data into equivalent voltage. |
mahphalke |
1:819ac9aa5667 | 47 | * scale = (chn_range / MAX_ADC_CNT * 1000) as defined in iio_ad7606.c |
mahphalke |
1:819ac9aa5667 | 48 | * */ |
mahphalke |
1:819ac9aa5667 | 49 | voltage = (adc_raw * (scale / 1000)); |
mahphalke |
1:819ac9aa5667 | 50 | |
mahphalke |
1:819ac9aa5667 | 51 | return voltage; |
mahphalke |
1:819ac9aa5667 | 52 | } |
mahphalke |
1:819ac9aa5667 | 53 | |
mahphalke |
1:819ac9aa5667 | 54 | |
mahphalke |
1:819ac9aa5667 | 55 | /*! |
mahphalke |
1:819ac9aa5667 | 56 | * @brief Function to get the polarity of analog input |
mahphalke |
1:819ac9aa5667 | 57 | * @param chn_range_bits[in] - Bits from the channel range register |
mahphalke |
1:819ac9aa5667 | 58 | * @return UNIPOLAR or BIPOLAR |
mahphalke |
1:819ac9aa5667 | 59 | */ |
mahphalke |
1:819ac9aa5667 | 60 | polarity_e ad7606_get_input_polarity(uint8_t chn_range_bits) |
mahphalke |
1:819ac9aa5667 | 61 | { |
mahphalke |
1:819ac9aa5667 | 62 | polarity_e polarity; |
mahphalke |
1:819ac9aa5667 | 63 | |
mahphalke |
1:819ac9aa5667 | 64 | if (chn_range_bits >= AD7606C_UNIPOLAR_RANGE_MIN |
mahphalke |
1:819ac9aa5667 | 65 | && chn_range_bits <= AD7606C_UNIPOLAR_RANGE_MAX) { |
mahphalke |
1:819ac9aa5667 | 66 | polarity = UNIPOLAR; |
mahphalke |
1:819ac9aa5667 | 67 | } else { |
mahphalke |
1:819ac9aa5667 | 68 | polarity = BIPOLAR; |
mahphalke |
1:819ac9aa5667 | 69 | } |
mahphalke |
1:819ac9aa5667 | 70 | |
mahphalke |
1:819ac9aa5667 | 71 | return polarity; |
mahphalke |
1:819ac9aa5667 | 72 | } |
mahphalke |
1:819ac9aa5667 | 73 | |
mahphalke |
1:819ac9aa5667 | 74 | |
mahphalke |
1:819ac9aa5667 | 75 | /*! |
mahphalke |
1:819ac9aa5667 | 76 | * @brief Read the num_of_bytes from previous conversion |
mahphalke |
1:819ac9aa5667 | 77 | * @param dev[in]- Device instance |
mahphalke |
1:819ac9aa5667 | 78 | * @param num_of_bytes[in] - Number of bytes to read from previous conversion |
mahphalke |
1:819ac9aa5667 | 79 | * @return SUCCESS in case of success, FAILURE otherwise |
mahphalke |
1:819ac9aa5667 | 80 | */ |
mahphalke |
1:819ac9aa5667 | 81 | int32_t ad7606_read_conversion_data(struct ad7606_dev *dev, |
mahphalke |
1:819ac9aa5667 | 82 | uint8_t num_of_bytes) |
mahphalke |
1:819ac9aa5667 | 83 | { |
mahphalke |
1:819ac9aa5667 | 84 | memset(dev->data, 0, sizeof(dev->data)); |
mahphalke |
1:819ac9aa5667 | 85 | return spi_write_and_read(dev->spi_desc, dev->data, num_of_bytes); |
mahphalke |
1:819ac9aa5667 | 86 | } |