|
| 1 | +LTC2378-20 no-OS driver |
| 2 | +======================= |
| 3 | + |
| 4 | +.. no-os-doxygen:: |
| 5 | + |
| 6 | +Supported Devices |
| 7 | +----------------- |
| 8 | + |
| 9 | +- :adi:`LTC2378-20` |
| 10 | + |
| 11 | +Overview |
| 12 | +-------- |
| 13 | + |
| 14 | +The LTC2378-20 is a high-speed, low-power, and low-noise 20-bit SAR |
| 15 | +(Successive Approximation Register) analog-to-digital converter (ADC). It |
| 16 | +operates from a 2.5V supply and supports both unipolar (0 to VREF) and |
| 17 | +bipolar (±VREF) input ranges, with VREF values ranging from 2.5V to 5.1V. |
| 18 | +Despite its high resolution, the device consumes only 21mW and delivers |
| 19 | +excellent performance with a maximum ±2ppm INL and a signal-to-noise ratio |
| 20 | +(SNR) of 104dB, ensuring no missing codes at 20-bit resolution. |
| 21 | + |
| 22 | +The ADC features a high-speed SPI-compatible serial interface that supports |
| 23 | +multiple logic levels —1.8V, 2.5V, 3.3V, and 5V—and includes a daisy-chain |
| 24 | +mode for connecting multiple devices. Its fast 1Msps throughput and zero |
| 25 | +cycle latency make it ideal for high-speed applications. An internal |
| 26 | +oscillator simplifies timing by setting the conversion time automatically, |
| 27 | +and the device powers down between conversions to reduce power consumption, |
| 28 | +which scales with the sampling rate. |
| 29 | + |
| 30 | +The LTC2378-20 supports both unipolar and bipolar input modes. In unipolar |
| 31 | +mode, the input range is from 0V to VREF with 20-bit resolution (2^20 codes). |
| 32 | +In bipolar mode, the input range is from -VREF to +VREF with effective |
| 33 | +19-bit resolution (2^19 codes for each polarity). The device uses a BUSY |
| 34 | +signal to indicate conversion completion and a CNV signal to initiate |
| 35 | +conversions. |
| 36 | + |
| 37 | +Applications |
| 38 | +------------ |
| 39 | + |
| 40 | +* Medical Imaging |
| 41 | +* High Speed Data Acquisition |
| 42 | +* Portable or Compact Instrumentation |
| 43 | +* Industrial Process Control |
| 44 | +* Low Power Battery-Operated Instrumentation |
| 45 | +* Automated Test Equipment (ATE) |
| 46 | + |
| 47 | +LTC2378-20 Device Configuration |
| 48 | +------------------------------- |
| 49 | + |
| 50 | +Driver Initialization |
| 51 | +--------------------- |
| 52 | + |
| 53 | +In order to be able to use the device, you will have to provide the support |
| 54 | +for the communication protocol (SPI) alongside GPIO pins for conversion |
| 55 | +control (CNV) and busy indication (BUSY). |
| 56 | + |
| 57 | +The first API to be called is **ltc2378_init**. Make sure that it returns 0, |
| 58 | +which means that the driver was initialized correctly. |
| 59 | + |
| 60 | +The initialization API uses the device descriptor and an initialization |
| 61 | +parameter. The initialization parameter contains the SPI configuration, |
| 62 | +GPIO parameters for CNV and BUSY pins, reference voltage (VREF) in microvolts, |
| 63 | +and input mode (unipolar or bipolar). These are defined in the header file |
| 64 | +of the driver. |
| 65 | + |
| 66 | +ADC Configuration |
| 67 | +----------------- |
| 68 | + |
| 69 | +The LTC2378-20 can be configured for either unipolar or bipolar input modes |
| 70 | +using the **input_mode** parameter during initialization. |
| 71 | + |
| 72 | +In **unipolar mode** (LTC2378_UNIPOLAR): |
| 73 | +- Input range: 0V to VREF |
| 74 | +- Resolution: 20 bits (2^20 = 1,048,576 codes) |
| 75 | +- Code 0 represents 0V, code 1048575 represents VREF |
| 76 | + |
| 77 | +In **bipolar mode** (LTC2378_BIPOLAR): |
| 78 | +- Input range: -VREF to +VREF |
| 79 | +- Resolution: 19 bits effective (2^19 = 524,288 codes per polarity) |
| 80 | +- Two's complement format with proper sign extension |
| 81 | + |
| 82 | +ADC Data Acquisition |
| 83 | +-------------------- |
| 84 | + |
| 85 | +Data acquisition is performed using the **ltc2378_read_raw** API, which: |
| 86 | + |
| 87 | +1. Initiates a conversion using the CNV signal |
| 88 | +2. Waits for the BUSY signal to indicate conversion completion |
| 89 | +3. Reads the 20-bit result via SPI |
| 90 | +4. Returns the raw digital code |
| 91 | + |
| 92 | +The **ltc2378_raw_to_uv** API converts the raw digital code to voltage |
| 93 | +in microvolts, taking into account the configured input mode and reference |
| 94 | +voltage. |
| 95 | + |
| 96 | +Power Management |
| 97 | +---------------- |
| 98 | + |
| 99 | +The LTC2378-20 automatically powers down between conversions to minimize |
| 100 | +power consumption. The **ltc2378_power_down** API can be used to manually |
| 101 | +put the device into power-down mode by holding the CNV signal low. |
| 102 | + |
| 103 | +LTC2378-20 Driver Initialization Example |
| 104 | +---------------------------------------- |
| 105 | + |
| 106 | +.. code-block:: bash |
| 107 | +
|
| 108 | + struct ltc2378_dev *ltc2378_dev; |
| 109 | + struct no_os_spi_init_param ltc2378_spi_ip = { |
| 110 | + .device_id = SPI_DEVICE_ID, |
| 111 | + .max_speed_hz = 1000000, |
| 112 | + .chip_select = SPI_CS, |
| 113 | + .mode = NO_OS_SPI_MODE_0, |
| 114 | + .bit_order = NO_OS_SPI_BIT_ORDER_MSB_FIRST, |
| 115 | + .platform_ops = SPI_OPS, |
| 116 | + .extra = SPI_EXTRA, |
| 117 | + }; |
| 118 | +
|
| 119 | + struct no_os_gpio_init_param ltc2378_gpio_cnv = { |
| 120 | + .port = GPIO_CNV_PORT_NUM, |
| 121 | + .number = GPIO_CNV_PIN_NUM, |
| 122 | + .platform_ops = GPIO_OPS, |
| 123 | + .extra = GPIO_EXTRA |
| 124 | + }; |
| 125 | +
|
| 126 | + struct no_os_gpio_init_param ltc2378_gpio_busy = { |
| 127 | + .port = GPIO_BUSY_PORT_NUM, |
| 128 | + .number = GPIO_BUSY_PIN_NUM, |
| 129 | + .platform_ops = GPIO_OPS, |
| 130 | + .extra = GPIO_EXTRA |
| 131 | + }; |
| 132 | +
|
| 133 | + struct ltc2378_init_param ltc2378_ip = { |
| 134 | + .spi_init = <c2378_spi_ip, |
| 135 | + .gpio_cnv_init = <c2378_gpio_cnv, |
| 136 | + .gpio_busy_init = <c2378_gpio_busy, |
| 137 | + .vref_uv = 2500000, // 2.5V reference |
| 138 | + .input_mode = LTC2378_BIPOLAR |
| 139 | + }; |
| 140 | +
|
| 141 | + ret = ltc2378_init(<c2378_dev, <c2378_ip); |
| 142 | + if (ret) |
| 143 | + goto error; |
| 144 | +
|
| 145 | + // Read ADC value |
| 146 | + uint32_t raw_data; |
| 147 | + int32_t voltage_uv; |
| 148 | +
|
| 149 | + ret = ltc2378_read_raw(ltc2378_dev, &raw_data); |
| 150 | + if (ret) |
| 151 | + goto error; |
| 152 | +
|
| 153 | + ret = ltc2378_raw_to_uv(ltc2378_dev, raw_data, &voltage_uv); |
| 154 | + if (ret) |
| 155 | + goto error; |
| 156 | +
|
| 157 | +LTC2378-20 no-OS IIO support |
| 158 | +--------------------------- |
| 159 | +
|
| 160 | +The LTC2378-20 IIO driver comes on top of the LTC2378-20 driver and offers support |
| 161 | +for interfacing IIO clients through libiio. |
| 162 | +
|
| 163 | +LTC2378-20 IIO Device Configuration |
| 164 | +----------------------------------- |
| 165 | +
|
| 166 | +Voltage Channel Attributes |
| 167 | +-------------------------- |
| 168 | +
|
| 169 | +The LTC2378-20 IIO device provides a single voltage input channel with the |
| 170 | +following attributes: |
| 171 | +
|
| 172 | +* ``raw`` - The raw digital code from the ADC (0 to 1048575 for 20-bit) |
| 173 | +* ``scale`` - The scale factor to convert raw values to millivolts |
| 174 | +* ``processed`` - The processed voltage value in millivolts (raw * scale) |
| 175 | +
|
| 176 | +The scale factor is automatically calculated based on the configured reference |
| 177 | +voltage and input mode: |
| 178 | +
|
| 179 | +- **Unipolar mode**: scale = VREF / 2^20 |
| 180 | +- **Bipolar mode**: scale = VREF / 2^19 |
| 181 | +
|
| 182 | +For example, with VREF = 2.5V: |
| 183 | +- Unipolar scale = 2500000 µV / 1048576 ≈ 2.384 µV/LSB |
| 184 | +- Bipolar scale = 2500000 µV / 524288 ≈ 4.768 µV/LSB |
| 185 | +
|
| 186 | +LTC2378-20 IIO Driver Initialization Example |
| 187 | +-------------------------------------------- |
| 188 | +
|
| 189 | +.. code-block:: bash |
| 190 | +
|
| 191 | + int ret; |
| 192 | +
|
| 193 | + struct ltc2378_iio_desc *ltc2378_iio_desc; |
| 194 | + struct ltc2378_iio_desc_init_param ltc2378_iio_ip = { |
| 195 | + .ltc2378_init_param = <c2378_ip, |
| 196 | + }; |
| 197 | +
|
| 198 | + struct iio_app_desc *app; |
| 199 | + struct iio_app_init_param app_init_param = { 0 }; |
| 200 | +
|
| 201 | + ret = ltc2378_iio_init(<c2378_iio_desc, <c2378_iio_ip); |
| 202 | + if (ret) |
| 203 | + goto exit; |
| 204 | +
|
| 205 | + struct iio_app_device iio_devices[] = { |
| 206 | + { |
| 207 | + .name = "ltc2378-20", |
| 208 | + .dev = ltc2378_iio_desc, |
| 209 | + .dev_descriptor = ltc2378_iio_desc->iio_dev, |
| 210 | + }, |
| 211 | + }; |
| 212 | +
|
| 213 | + app_init_param.devices = iio_devices; |
| 214 | + app_init_param.nb_devices = NO_OS_ARRAY_SIZE(iio_devices); |
| 215 | + app_init_param.uart_init_params = uip; |
| 216 | +
|
| 217 | + ret = iio_app_init(&app, app_init_param); |
| 218 | + if (ret) |
| 219 | + goto remove_iio_ltc2378; |
| 220 | +
|
| 221 | + ret = iio_app_run(app); |
| 222 | +
|
| 223 | + iio_app_remove(app); |
| 224 | +
|
| 225 | +remove_iio_ltc2378: |
| 226 | + ltc2378_iio_remove(ltc2378_iio_desc); |
| 227 | +exit: |
| 228 | + if (ret) |
| 229 | + pr_info("Error!\n"); |
| 230 | + return ret; |
0 commit comments