社区导航

 
查看: 5411|回复: 23

[讨论] 分享一个我改的TI ADS126x(ADS1262/ADS1263)的头文件(全注释)

[复制链接]

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

发表于 2016-8-2 17:42:39 | 显示全部楼层 |阅读模式
本帖最后由 littleshrimp 于 2016-8-2 17:56 编辑

分享一个改的TI ADS126x(ADS1262/ADS1263)的头文件

ADS1262 和 ADS1263 是具有集成 PGA、电压基准和内部故障监视器的低噪声、低漂移、38.4kSPS、Δ-Σ (ΔΣ) ADC。ADS1263 集成有一个 24 位辅助 ΔΣ ADC,专用于后台测量。这些支持传感器的 ADC 提供了一套完备的高精度、单芯片测量解决方案,可满足大多数传感器 应用的需求,其中包括秤重天平、应力计传感器、热电偶和电阻式温度器件 (RTD)。

ADC 由低噪声 CMOS PGA(增益范围为 1 至 32)、ΔΣ 调制器以及可编程数字滤波器组成。模拟前端 (AFE) 非常灵活,其包含两个传感器激励电流源,非常适合直接 RTD 测量。

单周期稳定数字滤波器可最大限度提高多输入转换吞吐量,同时能够为 50Hz 和 60Hz 的线路周期干扰提供 130dB 抑制。

ADS1262 与 ADS1263 的引脚和功能彼此兼容。这两款器件均采用 28 引脚薄型小外形尺寸 (TSSOP) 封装,并且均在 –40°C 至 +125°C 温度范围内完全额定运行。

根据官方TIPD188设计文件修改

http://www.ti.com.cn/tool/cn/TIPD188

tidcan1.zip (12.14 MB, 下载次数: 1024)

虾扯蛋


回复

使用道具 举报

2

TA的帖子

0

TA的资源

一粒金砂(初级)

Rank: 1

发表于 2016-8-3 14:55:06 | 显示全部楼层
感谢楼主分享, 问下 楼主 在调试这块芯片吗?  数据稳定不?

点评

简单测试,稳定。  详情 回复 发表于 2016-8-3 15:55


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-8-3 15:55:24 | 显示全部楼层
qagainc 发表于 2016-8-3 14:55
感谢楼主分享, 问下 楼主 在调试这块芯片吗?  数据稳定不?

简单测试,稳定。
虾扯蛋


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-8-17 16:37:10 | 显示全部楼层
官方头文件中发现一处错误
   #define MAG1_MASK                       (0xF0)
应该修改为
   #define MAG1_MASK                       (0x0F)
虾扯蛋


回复

使用道具 举报

7

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-11-11 10:33:32 | 显示全部楼层
我用的hal库,之前24位的通信都没有问题,结果这个寄存器完全写不进去。这是为什么啊?求解答

点评

你能说一下你的具体情况吗?  详情 回复 发表于 2016-11-11 10:45


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-11-11 10:45:34 | 显示全部楼层
lqz1219 发表于 2016-11-11 10:33
我用的hal库,之前24位的通信都没有问题,结果这个寄存器完全写不进去。这是为什么啊?求解答

你能说一下你的具体情况吗?

内容多的话可以发一个求助贴,我帮你看下。
虾扯蛋


回复

使用道具 举报

7

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-11-11 10:54:30 | 显示全部楼层
littleshrimp 发表于 2016-11-11 10:45
你能说一下你的具体情况吗?

内容多的话可以发一个求助贴,我帮你看下。

就是之前用的1248,也是SPI通信的,程序完全都通了。现在改用1262,时序什么都跟之前一样啊,头文件都写好了,校对过命令跟寄存器也都没问题,能从AD读出数来,但是错的,发现寄存器全都没写成功。。。

点评

span { font-family: 'Courier New'; font-size: 10pt; color: #000000; } .sc0 { } .sc1 { color: #008000; } .sc2 { color: #008000; } .sc4 { color: #FF8000; } .sc5 { font-weig  详情 回复 发表于 2016-11-11 11:13
你可以先读一下ID,或者用示波器看一下时序,确定SPI通信成功了 然后根据TI官方提供的ADS126x工程中的代码配置ADC 参考一楼rar文件中的ac_bridge.c文件  详情 回复 发表于 2016-11-11 11:11


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-11-11 11:11:21 | 显示全部楼层
lqz1219 发表于 2016-11-11 10:54
就是之前用的1248,也是SPI通信的,程序完全都通了。现在改用1262,时序什么都跟之前一样啊,头文件都写 ...

你可以先读一下ID,或者用示波器看一下时序,确定SPI通信成功了
然后根据TI官方提供的ADS126x工程中的代码配置ADC
参考一楼rar文件中的ac_bridge.c文件
虾扯蛋


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-11-11 11:13:31 | 显示全部楼层
lqz1219 发表于 2016-11-11 10:54 就是之前用的1248,也是SPI通信的,程序完全都通了。现在改用1262,时序什么都跟之前一样啊,头文件都写 ...
/* --COPYRIGHT--,BSD * Copyright (c) 2015, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --/COPYRIGHT--*/ /* * ac_bridge.c * * Created on: May 27, 2015 * Author: a0282860 */ #include "ac_bridge.h" // All other required source files are declared here #include "hal.h" #define MEASU_COUNT 100 //Values used by "g_excitationStatus" #define EXC_OFF 0x00 #define EXC_POS 0x01 #define EXC_NEG 0x02 #define NumContReadings 16 //File global variables static char g_excitationStatus = EXC_OFF; //Indicates bridge excitation polarity static char output_mode = 0; //Controls output data formatting //Internal inline function prototypes (not declared in "control.h") static inline void show_AppMenu(void); static inline void LoadInitRegSettings(void); static inline void run_ReadPosCont(void); static inline void run_ReadChopCont(void); static inline double get_voltage(void); static inline double get_current(void); static inline double get_reference(uint8_t print_output); static inline double get_temperature(void); static inline void set_excitation(uint8_t excitation_target); void run_demo(char c) { int16_t option = (int16_t) c - 48; //Convert character "c" to a (0 through 9) integer "option" if (NULL == c) show_AppMenu(); //show application menu else if (0 == option) LoadInitRegSettings(); //configure register settings else if (1 == option) { get_reference(1); //read reference voltage and store it for later use get_temperature(); //read int temp sensor } else if (2 == option) //read pos input 16 times - compute noise run_ReadPosCont(); else if (3 == option) //read chopped input 16 times - compute noise run_ReadChopCont(); else if (4 == option) { output_mode = 1; get_reference(1); //read reference voltage and store it for later use get_temperature(); run_ReadPosCont(); __delay_cycles(SYSFREQ); run_ReadChopCont(); output_mode = 0; } else if(5 == option) { get_voltage(); } else if(6 == option) { get_current(); } else printError(); //invalid option } static inline void show_AppMenu(void) { #ifdef CONSOLE_OUTPUT strcpy(outString,"\r\nSelect Operation:\r\n"); print2Console(outString); strcpy(outString,"\tz0) Load Initial Register Settings\r\n"); print2Console(outString); strcpy(outString,"\tz1) Read Supply & Reference\r\n"); print2Console(outString); strcpy(outString,"\tz2) Read Bridge (dc excitation)\r\n"); print2Console(outString); strcpy(outString,"\tz3) Read Bridge (ac excitation)\r\n"); print2Console(outString); strcpy(outString,"\tz9) TIPD188 Data Collection Mode\r\n"); print2Console(outString); #endif } static inline void LoadInitRegSettings(void) { uint8_t AdcRegData[ADS126x_NUM_REG]; //Stores the register read values uint8_t WriteRegData[ADS126x_NUM_REG]; //Stores the register write values ADS126xReadRegister(ID, ADS126x_NUM_REG, AdcRegData); //Read ALL registers /* Configure Register Settings */ WriteRegData[ID] = AdcRegData[ID]; //ID WriteRegData[POWER] = INTREF; //POWER (RESET = 0, INTREF = 1) WriteRegData[INTERFACE] = STATUS | CRC_ON; //INTERFACE WriteRegData[MODE0] = DELAY_278us; //MODE0 (Set DELAY) WriteRegData[MODE1] = (AdcRegData[MODE1] & FILTER_MASK); //MODE1 WriteRegData[MODE2] = (AdcRegData[MODE2] & ~BYPASS) | GAIN_32; //MODE2 (BYPASS = 0, GAIN = 32 V/V) WriteRegData[INPMUX] = MUXP_AIN1 | MUXN_AIN2; //INPMUX (AINP = AIN1, AINN = AIN2) WriteRegData[OFCAL0] = OFCAL0_DEFAULT_VALUE; //OFCAL0 (reset to default) WriteRegData[OFCAL1] = OFCAL1_DEFAULT_VALUE; //OFCAL1 (reset to default) WriteRegData[OFCAL2] = OFCAL2_DEFAULT_VALUE; //OFCAL2 (reset to default) WriteRegData[FSCAL0] = FSCAL0_DEFAULT_VALUE; //FSCAL0 (reset to default) WriteRegData[FSCAL1] = FSCAL1_DEFAULT_VALUE; //FSCAL1 (reset to default) WriteRegData[FSCAL2] = FSCAL2_DEFAULT_VALUE; //FSCAL2 (reset to default) WriteRegData[IDACMUX] = MUX2_NO_CONM | MUX1_AINCOM; //IDACMUX (IDAC1MUX = AINCOM) WriteRegData[IDACMAG] = MAG2_OFF | MAG1_500uA; //IDACMAG (IDAC1MAG = 500 uA) WriteRegData[REFMUX] = RMUXP_AIN0 | RMUXN_AIN3; //REFMUX (REFP = AIN0, REFN = AIN3) WriteRegData[TDACP] = TDACP_DEFAULT_VALUE; //TDACP (reset to default) WriteRegData[TDACN] = TDACN_DEFAULT_VALUE; //TDACN (reset to default) WriteRegData[GPIOCON] = CON6_AIN09 | CON5_AIN08; //GPIOCON (Enable GPIOs on AIN8 & AIN9) WriteRegData[GPIODIR] = GPIOCON_DEFAULT_VALUE; //GPIODIR (reset to default) WriteRegData[GPIODAT] = DAT5_AIN08; //GPIODAT (Biases bridge with + polarity) #ifdef ADS1263 WriteRegData[ADC2CFG] = ADC2CFG_DEFAULT_VALUE; //ADC2CFG (reset to default) WriteRegData[ADC2MUX] = ADC2MUX_DEFAULT_VALUE; //ADC2MUX (reset to default) WriteRegData[ADC2OFC0] = ADC2OFC0_DEFAULT_VALUE; //ADC2OFC0 (reset to default) WriteRegData[ADC2OFC1] = ADC2OFC1_DEFAULT_VALUE; //ADC2OFC1 (reset to default) WriteRegData[ADC2FSC0] = ADC2FSC0_DEFAULT_VALUE; //ADC2FSC0 (reset to default) WriteRegData[ADC2FSC1] = ADC2FSC1_DEFAULT_VALUE; //ADC2FSC1 (reset to default) #endif ADS126xWriteRegister(ID, ADS126x_NUM_REG, &WriteRegData[0]); //Write ALL registers #ifdef CONSOLE_OUTPUT show_parms('0'); //read back registers and output to console #endif } static inline void run_ReadPosCont(void) { int32_t AdcOutput[NumContReadings]; if (EXC_POS != g_excitationStatus) //Configure Bridge Polarity { set_excitation(EXC_OFF); set_excitation(EXC_POS); } #ifdef CONSOLE_OUTPUT strcpy(outString,"SINGLE,"); print2Console(outString); #endif //Collect 16x data conversions set_adc_START(1); for(int i = 0; i < NumContReadings; ++i) { WaitForDRDY(); AdcOutput[i] = ADS126xReadData(6, 1); } set_adc_START(0); #ifdef CONSOLE_OUTPUT for(int i = 0; i < NumContReadings; ++i) { hex2asc(&AdcOutput[i],8,2,tempString,1); strcpy(outString, tempString); strcat(outString, ","); print2Console(outString); } #endif } static inline void run_ReadChopCont(void) { int32_t AdcChopOutputP[NumContReadings]; int32_t AdcChopOutputN[NumContReadings]; if (EXC_POS != g_excitationStatus) //Configure "+" Bridge Polarity { set_excitation(EXC_OFF); set_excitation(EXC_POS); } __delay_cycles(Delay100ms); #ifdef CONSOLE_OUTPUT strcpy(outString,"DOUBLE(+),"); print2Console(outString); #endif //Collect 16x data conversions and calculate average set_adc_START(1); for(int i = 0; i < NumContReadings; ++i) { WaitForDRDY(); AdcChopOutputP[i] = ADS126xReadData(6, 1); } set_adc_START(0); #ifdef CONSOLE_OUTPUT for(int i = 0; i < NumContReadings; ++i) { hex2asc(&AdcChopOutputP[i],8,2,tempString,1); strcpy(outString, tempString); strcat(outString, ","); print2Console(outString); } #endif //Configure "-" Bridge Polarity set_excitation(EXC_OFF); set_excitation(EXC_NEG); __delay_cycles(Delay100ms); #ifdef CONSOLE_OUTPUT strcpy(outString,"DOUBLE(-),"); print2Console(outString); #endif //Collect 16x data conversions and calculate average set_adc_START(1); for(int i = 0; i < NumContReadings; ++i) { WaitForDRDY(); AdcChopOutputN[i] = ADS126xReadData(6, 1); } set_adc_START(0); #ifdef CONSOLE_OUTPUT for(int i = 0; i < NumContReadings; ++i) { hex2asc(&AdcChopOutputN[i],8,2,tempString,1); strcpy(outString, tempString); strcat(outString, ","); print2Console(outString); } #endif } static inline double get_voltage(void) { uint16_t i; uint8_t WriteRegData; //Stores the register write values uint8_t AdcRegData[ADS126x_NUM_REG]; //Stores the register read values int32_t AdcOutput = 0; const uint8_t Gain = 1; double VoltageReading; const double IntRefVolt = 2.49906; static double ExtRefVolt = 5; //Read ALL registers ADS126xReadRegister(ID, ADS126x_NUM_REG, AdcRegData); //MODE0 (CHOP OFF) WriteRegData = (AdcRegData[MODE0] & DELAY_MASK); ADS126xWriteRegister(MODE0, 1, &WriteRegData); //MODE2 (BYPASS OFF, GAIN = 1 V/V) WriteRegData = (AdcRegData[MODE2] & ~(DR_MASK | GAIN_MASK)) | DR_38400_SPS | GAIN_1; ADS126xWriteRegister(MODE2, 1, &WriteRegData); //Reset OFCAL coefficients WriteRegData = 0x00; ADS126xWriteRegister(OFCAL2, 1, &WriteRegData); //OFCAL2 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL1, 1, &WriteRegData); //OFCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL0, 1, &WriteRegData); //OFCAL0 = 0x00 //Reset FSCAL coefficients WriteRegData = 0x40; ADS126xWriteRegister(FSCAL2, 1, &WriteRegData); //FSCAL2 = 0x40 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL1, 1, &WriteRegData); //FSCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL0, 1, &WriteRegData); //FSCAL0 = 0x00 //INPMUX (AINP = AIN8, AINN = AIN9) WriteRegData = MUXP_AIN8 | MUXN_AIN9; ADS126xWriteRegister(INPMUX, 1, &WriteRegData); //REFMUX WriteRegData = RMUXP_INTP | RMUXN_INTN; ADS126xWriteRegister(REFMUX, 1, &WriteRegData); for(i=0;i<MEASU_COUNT;i++) { //Read one conversion set_adc_START(1); WaitForDRDY(); set_adc_START(0); AdcOutput = ADS126xReadData(6, 1); VoltageReading = (double) AdcOutput * IntRefVolt / ((double) Gain * exp2(31)); double t = exp2(31); ExtRefVolt = VoltageReading; //VREF = Ext IntRefVolt, for bridge readings strcpy(outString, "Voltage Reading = 0x"); hex2asc(&AdcOutput, 8, 2, tempString,1); strcat(outString, tempString); sprintf(tempString, " = %.10f V\r\n", VoltageReading); strcat(outString, tempString); print2Console(outString); } /* //Restore Register Settings ADS126xWriteRegister(OFCAL0, 1, &AdcRegData[OFCAL0]); ADS126xWriteRegister(OFCAL1, 1, &AdcRegData[OFCAL1]); ADS126xWriteRegister(OFCAL2, 1, &AdcRegData[OFCAL2]); ADS126xWriteRegister(FSCAL0, 1, &AdcRegData[FSCAL0]); ADS126xWriteRegister(FSCAL1, 1, &AdcRegData[FSCAL1]); ADS126xWriteRegister(FSCAL2, 1, &AdcRegData[FSCAL2]); ADS126xWriteRegister(INPMUX, 1, &AdcRegData[INPMUX]); ADS126xWriteRegister(REFMUX, 1, &AdcRegData[REFMUX]); ADS126xWriteRegister(MODE2, 1, &AdcRegData[MODE2]) ; ADS126xWriteRegister(MODE0, 1, &AdcRegData[MODE0]) ; */ return ExtRefVolt; } static inline double get_current(void) { uint16_t i; uint8_t WriteRegData; //Stores the register write values uint8_t AdcRegData[ADS126x_NUM_REG]; //Stores the register read values int32_t AdcOutput = 0; const uint8_t Gain = 1; double VoltageReading; double Current = 0; const double IntRefVolt = 2.49906; static double ExtRefVolt = 5; //Read ALL registers ADS126xReadRegister(ID, ADS126x_NUM_REG, AdcRegData); //MODE0 (CHOP OFF) WriteRegData = (AdcRegData[MODE0] & DELAY_MASK); ADS126xWriteRegister(MODE0, 1, &WriteRegData); //MODE2 (BYPASS OFF, GAIN = 1 V/V) WriteRegData = (AdcRegData[MODE2] & DR_MASK ) | DR_38400_SPS; ADS126xWriteRegister(MODE2, 1, &WriteRegData); //Reset OFCAL coefficients WriteRegData = 0x00; ADS126xWriteRegister(OFCAL2, 1, &WriteRegData); //OFCAL2 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL1, 1, &WriteRegData); //OFCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL0, 1, &WriteRegData); //OFCAL0 = 0x00 //Reset FSCAL coefficients WriteRegData = 0x40; ADS126xWriteRegister(FSCAL2, 1, &WriteRegData); //FSCAL2 = 0x40 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL1, 1, &WriteRegData); //FSCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL0, 1, &WriteRegData); //FSCAL0 = 0x00 //INPMUX (AINP = AIN6, AINN = AIN7) WriteRegData = MUXP_AIN6 | MUXN_AIN7; ADS126xWriteRegister(INPMUX, 1, &WriteRegData); //REFMUX WriteRegData = RMUXP_INTP | RMUXN_INTN; ADS126xWriteRegister(REFMUX, 1, &WriteRegData); for(i=0;i<MEASU_COUNT;i++) { //Read one conversion set_adc_START(1); WaitForDRDY(); set_adc_START(0); AdcOutput = ADS126xReadData(6, 1); VoltageReading = (double) AdcOutput * IntRefVolt / ((double) Gain * exp2(31)); Current = VoltageReading / 0.1f; ExtRefVolt = VoltageReading; //VREF = Ext IntRefVolt, for bridge readings strcpy(outString, "Current Reading = 0x"); hex2asc(&AdcOutput, 8, 2, tempString,1); strcat(outString, tempString); sprintf(tempString, " = %.10f V", VoltageReading); strcat(outString, tempString); sprintf(tempString, " = %.10f A\r\n", Current); strcat(outString, tempString); print2Console(outString); } /* //Restore Register Settings ADS126xWriteRegister(OFCAL0, 1, &AdcRegData[OFCAL0]); ADS126xWriteRegister(OFCAL1, 1, &AdcRegData[OFCAL1]); ADS126xWriteRegister(OFCAL2, 1, &AdcRegData[OFCAL2]); ADS126xWriteRegister(FSCAL0, 1, &AdcRegData[FSCAL0]); ADS126xWriteRegister(FSCAL1, 1, &AdcRegData[FSCAL1]); ADS126xWriteRegister(FSCAL2, 1, &AdcRegData[FSCAL2]); ADS126xWriteRegister(INPMUX, 1, &AdcRegData[INPMUX]); ADS126xWriteRegister(REFMUX, 1, &AdcRegData[REFMUX]); ADS126xWriteRegister(MODE2, 1, &AdcRegData[MODE2]) ; ADS126xWriteRegister(MODE0, 1, &AdcRegData[MODE0]) ; */ return ExtRefVolt; } static inline double get_reference(uint8_t print_output) { uint8_t WriteRegData; //Stores the register write values uint8_t AdcRegData[ADS126x_NUM_REG]; //Stores the register read values int32_t AdcOutput = 0; const uint8_t Gain = 1; double VoltageReading; const double IntRefVolt = 2.49906; static double SupplyRefVolt = 5; static double ExtRefVolt = 5; //Read ALL registers ADS126xReadRegister(ID, ADS126x_NUM_REG, AdcRegData); //MODE0 (CHOP OFF) WriteRegData = (AdcRegData[MODE0] & DELAY_MASK); ADS126xWriteRegister(MODE0, 1, &WriteRegData); //MODE2 (BYPASS OFF, GAIN = 1 V/V) WriteRegData = (AdcRegData[MODE2] & DR_MASK); ADS126xWriteRegister(MODE2, 1, &WriteRegData); //Reset OFCAL coefficients WriteRegData = 0x00; ADS126xWriteRegister(OFCAL2, 1, &WriteRegData); //OFCAL2 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL1, 1, &WriteRegData); //OFCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL0, 1, &WriteRegData); //OFCAL0 = 0x00 //Reset FSCAL coefficients WriteRegData = 0x40; ADS126xWriteRegister(FSCAL2, 1, &WriteRegData); //FSCAL2 = 0x40 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL1, 1, &WriteRegData); //FSCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL0, 1, &WriteRegData); //FSCAL0 = 0x00 //INPMUX (AINP = AIN0, AINN = AIN3) WriteRegData = MUXP_DVDD | MUXN_DVDD; ADS126xWriteRegister(INPMUX, 1, &WriteRegData); //REFMUX WriteRegData = RMUXP_INTP | RMUXN_INTN; ADS126xWriteRegister(REFMUX, 1, &WriteRegData); //Read one conversion set_adc_START(1); WaitForDRDY(); set_adc_START(0); AdcOutput = ADS126xReadData(6, 1); VoltageReading = (double) AdcOutput * IntRefVolt / ((double) Gain * exp2(29)); //2^29 to account for 1/4 supply & 1/2 FSR SupplyRefVolt = VoltageReading; //VREF = previous supply reading #ifdef CONSOLE_OUTPUT if(output_mode) { sprintf(tempString, "\r\n%f,", VoltageReading); strcpy(outString, tempString); print2Console(outString); } else if(print_output) { strcpy(outString, "Supply Reading = 0x"); hex2asc(&AdcOutput, 8, 2, tempString,1); strcat(outString, tempString); sprintf(tempString, " = %.10f V\r\n", VoltageReading); strcat(outString, tempString); print2Console(outString); } #endif //INPMUX (AINP = AIN6, AINN = AIN7) WriteRegData = MUXP_AIN6 | MUXN_AIN7; ADS126xWriteRegister(INPMUX, 1, &WriteRegData); //REFMUX WriteRegData = RMUXP_INTP | RMUXN_INTN; ADS126xWriteRegister(REFMUX, 1, &WriteRegData); //Read one conversion set_adc_START(1); WaitForDRDY(); set_adc_START(0); AdcOutput = ADS126xReadData(6, 1); VoltageReading = (double) AdcOutput * SupplyRefVolt / ((double) Gain * exp2(31)); ExtRefVolt = VoltageReading; //VREF = Ext IntRefVolt, for bridge readings #ifdef CONSOLE_OUTPUT if(!output_mode) { if(print_output) { strcpy(outString, "Reference Reading = 0x"); hex2asc(&AdcOutput, 8, 2, tempString,1); strcat(outString, tempString); sprintf(tempString, " = %f V\r\n", VoltageReading); strcat(outString, tempString); print2Console(outString); } } #endif //Restore Register Settings ADS126xWriteRegister(OFCAL0, 1, &AdcRegData[OFCAL0]); ADS126xWriteRegister(OFCAL1, 1, &AdcRegData[OFCAL1]); ADS126xWriteRegister(OFCAL2, 1, &AdcRegData[OFCAL2]); ADS126xWriteRegister(FSCAL0, 1, &AdcRegData[FSCAL0]); ADS126xWriteRegister(FSCAL1, 1, &AdcRegData[FSCAL1]); ADS126xWriteRegister(FSCAL2, 1, &AdcRegData[FSCAL2]); ADS126xWriteRegister(INPMUX, 1, &AdcRegData[INPMUX]); ADS126xWriteRegister(REFMUX, 1, &AdcRegData[REFMUX]); ADS126xWriteRegister(MODE2, 1, &AdcRegData[MODE2]) ; ADS126xWriteRegister(MODE0, 1, &AdcRegData[MODE0]) ; return ExtRefVolt; } static inline double get_temperature(void) { uint8_t WriteRegData; //Stores the register write values uint8_t AdcRegData[ADS126x_NUM_REG]; //Stores the register read values int32_t AdcOutput = 0; const char deg_char[3] = {176,'C','\0'}; double TempReading; //Read ALL registers ADS126xReadRegister(ID, ADS126x_NUM_REG, AdcRegData); //MODE0 (CHOP OFF) WriteRegData = (AdcRegData[MODE0] & DELAY_MASK); ADS126xWriteRegister(MODE0, 1, &WriteRegData); //MODE2 (BYPASS OFF, GAIN = 1 V/V) WriteRegData = (AdcRegData[MODE2] & DR_MASK); ADS126xWriteRegister(MODE2, 1, &WriteRegData); //Reset OFCAL coefficients WriteRegData = 0x00; ADS126xWriteRegister(OFCAL2, 1, &WriteRegData); //OFCAL2 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL1, 1, &WriteRegData); //OFCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(OFCAL0, 1, &WriteRegData); //OFCAL0 = 0x00 //Reset FSCAL coefficients WriteRegData = 0x40; ADS126xWriteRegister(FSCAL2, 1, &WriteRegData); //FSCAL2 = 0x40 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL1, 1, &WriteRegData); //FSCAL1 = 0x00 WriteRegData = 0x00; ADS126xWriteRegister(FSCAL0, 1, &WriteRegData); //FSCAL0 = 0x00 //INPMUX (AINP = Temp, AINN = Temp) WriteRegData = MUXP_TEMP | MUXN_TEMP; ADS126xWriteRegister(INPMUX, 1, &WriteRegData); //REFMUX WriteRegData = RMUXP_INTP | RMUXN_INTN; ADS126xWriteRegister(REFMUX, 1, &WriteRegData); //Read one conversion set_adc_START(1); WaitForDRDY(); AdcOutput = ADS126xReadData(6, 1); set_adc_START(0); TempReading = (double) 25 + ((((double) AdcOutput * (double) 0.00116415321) - (double) 122400) / (double) 420); #ifdef CONSOLE_OUTPUT if(output_mode) { sprintf(tempString, "%.2f,", TempReading); strcpy(outString, tempString); print2Console(outString); } else { strcpy(outString, "Temperature Reading = 0x"); hex2asc(&AdcOutput, 8, 2, tempString,1); strcat(outString, tempString); sprintf(tempString, " = %.2f", TempReading); strcat(outString, tempString); strcat(outString, deg_char); strcat(outString, "\r\n"); print2Console(outString); } #endif //Restore Register Settings ADS126xWriteRegister(OFCAL0, 1, &AdcRegData[OFCAL0]); ADS126xWriteRegister(OFCAL1, 1, &AdcRegData[OFCAL1]); ADS126xWriteRegister(OFCAL2, 1, &AdcRegData[OFCAL2]); ADS126xWriteRegister(FSCAL0, 1, &AdcRegData[FSCAL0]); ADS126xWriteRegister(FSCAL1, 1, &AdcRegData[FSCAL1]); ADS126xWriteRegister(FSCAL2, 1, &AdcRegData[FSCAL2]); ADS126xWriteRegister(INPMUX, 1, &AdcRegData[INPMUX]); ADS126xWriteRegister(REFMUX, 1, &AdcRegData[REFMUX]); ADS126xWriteRegister(MODE2, 1, &AdcRegData[MODE2]) ; ADS126xWriteRegister(MODE0, 1, &AdcRegData[MODE0]) ; return TempReading; } #ifdef CONSOLE_OUTPUT void set_exc(char p1, char p2) { char temp_str[2] = {p2, '\0'}; char exponent = strtoul(temp_str, NULL, 16); if (NULL == p1) { strcpy(outString, "AC Excitation = "); switch(g_excitationStatus) { case (EXC_OFF): strcat(outString, "OFF\r\n"); break; case (EXC_POS): strcat(outString, "Positive\r\n"); break; case (EXC_NEG): strcat(outString, "Negative\r\n"); break; } print2Console(outString); } else { switch (p1) { case '0': set_excitation(EXC_OFF); break; case '1': set_excitation(EXC_POS); break; case '2': set_excitation(EXC_NEG); break; default: printError(); break; } } } #endif static inline void set_excitation(uint8_t excitation_target) { uint8_t RegData = 0x00; switch(excitation_target) { case EXC_OFF: //Turn OFF Bridge Excitation //GPIODAT RegData = 0x00; ADS126xWriteRegister(GPIODAT, 1, &RegData); g_excitationStatus = EXC_OFF; break; case EXC_POS: //Turn On Bridge Excitation (+ Polarity) //GPIOCON ADS126xReadRegister(GPIOCON, 1, &RegData); RegData |= CON5_AIN08; ADS126xWriteRegister(GPIOCON, 1, &RegData); //GPIODAT RegData = DAT5_AIN08; //set bit 5, AIN08 ADS126xWriteRegister(GPIODAT, 1, &RegData); //MODE0 ADS126xReadRegister(MODE0, 1, &RegData); RegData &= ~REFREV; ADS126xWriteRegister(MODE0, 1, &RegData); g_excitationStatus = EXC_POS; break; case EXC_NEG: //Turn On Bridge Excitation (- Polarity) //GPIOCON ADS126xReadRegister(GPIOCON, 1, &RegData); RegData |= CON6_AIN09; ADS126xWriteRegister(GPIOCON, 1, &RegData); //GPIODAT RegData = DAT6_AIN09; //set bit 6, AIN09 ADS126xWriteRegister(GPIODAT, 1, &RegData); //MODE0 ADS126xReadRegister(MODE0, 1, &RegData); RegData |= REFREV; ADS126xWriteRegister(MODE0, 1, &RegData); g_excitationStatus = EXC_NEG; break; default: printError(); break; } }

虾扯蛋


回复

使用道具 举报

7

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-11-12 19:55:58 | 显示全部楼层
littleshrimp 发表于 2016-11-11 11:13
span {
        font-family: 'Courier New';
        font-size: 10pt;
        color: #000000;
}
.sc0 {
}
.sc ...

我发现寄存器能写入啊,我直接写一个0xFF,然后马上读,可以读出来FF。。。找不着错误了。。。AINCOM当恒流源输出,但电流不对啊,设置的1000ua,经过2.4k电阻电压只有1.44V。。。

点评

写00或者FF不如写55或AA 因为有时候通信错误时经常返回这两种结果  详情 回复 发表于 2016-11-12 20:08


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-11-12 20:08:50 | 显示全部楼层
lqz1219 发表于 2016-11-12 19:55
我发现寄存器能写入啊,我直接写一个0xFF,然后马上读,可以读出来FF。。。找不着错误了。。。AINCOM当恒 ...

写00或者FF不如写55或AA
因为有时候通信错误时经常返回这两种结果

点评

写55,读出来的数飘,不准。。。不过之前的1248也一样不准,但没问题。主要现在不知道这个1.44v咋出来的。。。  详情 回复 发表于 2016-11-12 20:29
虾扯蛋


回复

使用道具 举报

7

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-11-12 20:29:46 | 显示全部楼层
littleshrimp 发表于 2016-11-12 20:08
写00或者FF不如写55或AA
因为有时候通信错误时经常返回这两种结果

写55,读出来的数飘,不准。。。不过之前的1248也一样不准,但没问题。主要现在不知道这个1.44v咋出来的。。。

点评

后来解决了吗? 建议还是用官方提供的代码试试,我用的时候正常。  详情 回复 发表于 2016-11-18 21:02


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-11-18 21:02:40 | 显示全部楼层
lqz1219 发表于 2016-11-12 20:29
写55,读出来的数飘,不准。。。不过之前的1248也一样不准,但没问题。主要现在不知道这个1.44v咋出来的 ...

后来解决了吗?
建议还是用官方提供的代码试试,我用的时候正常。

点评

还没解决呢。前一段忙,没来得及调。我照着官方的初始化再试试  详情 回复 发表于 2016-11-30 09:23
虾扯蛋


回复

使用道具 举报

7

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-11-30 09:23:03 | 显示全部楼层
littleshrimp 发表于 2016-11-18 21:02
后来解决了吗?
建议还是用官方提供的代码试试,我用的时候正常。

还没解决呢。前一段忙,没来得及调。我照着官方的初始化再试试


回复

使用道具 举报

6

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-12-1 15:28:34 | 显示全部楼层
非常感谢博主的分享,学习了!谢谢!


回复

使用道具 举报

7

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-12-2 16:48:15 | 显示全部楼层
时序图没错,但是写指令和写寄存器有问题。。。


回复

使用道具 举报

7

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-12-2 17:00:11 | 显示全部楼层
出来了。。。hal库spi自动初始化的错误。。。卡了我两个礼拜

点评

SPI初始化失败了,时序还能正常吗?  详情 回复 发表于 2016-12-2 20:07


回复

使用道具 举报

5293

TA的帖子

9

TA的资源

版主

Rank: 6Rank: 6

 楼主| 发表于 2016-12-2 20:07:26 | 显示全部楼层
lqz1219 发表于 2016-12-2 17:00
出来了。。。hal库spi自动初始化的错误。。。卡了我两个礼拜

SPI初始化失败了,时序还能正常吗?
虾扯蛋


回复

使用道具 举报

6

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-12-24 10:18:45 | 显示全部楼层
版主你好,我因为一直在初级,所以,没法联系上您,能烦请您,加我QQ851157161吗


回复

使用道具 举报

6

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2016-12-24 10:19:26 | 显示全部楼层
楼主你好,我在水,拿经验,混2级联系你


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

  • 论坛活动 E手掌握

    扫码关注
    EEWORLD 官方微信

  • EE福利  唾手可得

    扫码关注
    EE福利 唾手可得

小黑屋|手机版|Archiver|电子工程世界 ( 京ICP证 060456 )

GMT+8, 2018-11-19 16:52 , Processed in 0.661412 second(s), 17 queries , Gzip On, MemCache On.

快速回复 返回顶部 返回列表