最近在查找ADI測(cè)量溫度方案,發(fā)現(xiàn)AD7124-8很適合溫度測(cè)量,于是申請(qǐng)了AD7124-8的樣品,設(shè)計(jì)一款5通道K型熱電偶測(cè)溫電路。
電路設(shè)計(jì)參考了UG-856 EVAL-AD7124-8SDZ User Guide上的原理圖,將AD7124-8的模擬通道連接到接線端子上,熱電偶測(cè)量方案也參考UG-856應(yīng)用,冷端使用一個(gè)3線PT100補(bǔ)償,MCU采用ADI ARM CORTEX-M3處理器ADUCM360,調(diào)試時(shí)使用串口打印輸出數(shù)據(jù),為了設(shè)計(jì)通用性以及后續(xù)軟件移植,設(shè)計(jì)時(shí)將ADC部分和MCU部分分成兩個(gè)PCB。原理圖設(shè)計(jì)圖紙大致如下:
圖1 模擬通道濾波電路
圖2 AD7124-8電路
圖3 電源以及外部REF電路
原理圖設(shè)計(jì)完了,就準(zhǔn)備PCB layout,layout參考UG-856上的設(shè)計(jì),按照4層板設(shè)計(jì)。
圖4 頂層絲印圖
圖5 頂層走線圖
圖6 GND層
圖7 電源層
圖8 底層
圖9 底層絲印圖
PCB layout完成后就聯(lián)系板廠加工,期間準(zhǔn)備物料,感謝ADI支持,很多樣品都申請(qǐng)到樣品了。
硬件部分設(shè)計(jì)完成就開始考慮軟件設(shè)計(jì)了,ADI網(wǎng)站上提供參考代碼,在網(wǎng)站上下載了源代碼,看了一遍,感覺(jué)還不錯(cuò),值得借鑒,不過(guò)不是在ADUCM360上開發(fā)的程序,需要將其移植到ADUMC360上
移植部分很簡(jiǎn)單,只需要完成3個(gè)填空題
int8_t SPI_Init(ADI_SPI_TypeDef *pSPI,uint32_t u32Baud);
int8_t SPI_Read(ADI_SPI_TypeDef *pSPI,uint8_t *pBuffer,int32_t i32Len);
int8_t SPI_Write(ADI_SPI_TypeDef *pSPI,uint8_t *pBuffer,int32_t s32Len);
其中SPI_Init完成SPI的初始化,包括SPI號(hào),以及波特率
SPI_Read實(shí)現(xiàn)SPI讀數(shù)據(jù)i32Len數(shù)據(jù)到pBuffer中
SPI_Write則實(shí)現(xiàn)SPI則將pBuffer中長(zhǎng)度為s32Len數(shù)據(jù)再M(fèi)OSI上發(fā)送出去
移植完驅(qū)動(dòng)后續(xù)就是驗(yàn)證是否移植是否正確了,下載的源代碼AD7124.C中也提供了方法。在int32_t AD7124_Setup(ad7124_device *device, int slave_select,ad7124_st_reg *regs)中實(shí)現(xiàn)了AD7124-8配置寄存器以及查詢寄存器操作,驗(yàn)證是否移植正確,就是將配置好的寄存器重新讀出來(lái)進(jìn)行比對(duì)了。寄存器的配置在ad7124_st_reg ad7124_regs[]初始化時(shí)已經(jīng)實(shí)現(xiàn),可以根據(jù)項(xiàng)目需求自行配置。配置值和讀出結(jié)果一致也就表示一致正確了。
按照一路K型熱電偶配置如下,AIN0,AIN1 K型熱電偶差分輸入通道,采用內(nèi)部2.5VREF, AIN12,AIN13 PT100差分通道,AIN10,AIN11 500uA恒流源輸出,采用REF1
ad7124_st_reg ad7124_regs[] =
{
{0x00, 0x00, 1, 2}, /* AD7124_Status */
//REF_EN
{0x01, 0x0100, 2, 1}, /* AD7124_ADC_Control */
{0x02, 0x0000, 3, 2}, /* AD7124_Data */
//IOUT0 -> AIN11, IOUT1 -> AIN10, IOUT0 -> 500uA, IOUT1 -> 500uA
{0x03, 0x24ab, 3, 1}, /* AD7124_IOCon1 */
//VBIAS0
{0x04, 0x0001, 2, 1}, /* AD7124_IOCon2 */
{0x05, 0x02, 1, 2}, /* AD7124_ID */
{0x06, 0x0000, 3, 2}, /* AD7124_Error */
{0x07, 0x0044, 3, 1}, /* AD7124_Error_En */
{0x08, 0x00, 1, 2}, /* AD7124_Mclk_Count */
//AIN0->AINP,AIN1->AINM
{0x09, 0x8001, 2, 1}, /* AD7124_Channel_0 */
// {0x09, 0x818d, 2, 1}, /* AD7124_Channel_0 */
//AIN12->AINP,AIN13->AINM
{0x0A, 0x918d, 2, 1}, /* AD7124_Channel_1 */
//{0x0A, 0x8001, 2, 1}, /* AD7124_Channel_1 */
{0x0B, 0x0001, 2, 1}, /* AD7124_Channel_2 */
{0x0C, 0x0001, 2, 1}, /* AD7124_Channel_3 */
{0x0D, 0x0001, 2, 1}, /* AD7124_Channel_4 */
{0x0E, 0x0001, 2, 1}, /* AD7124_Channel_5 */
{0x0F, 0x0001, 2, 1}, /* AD7124_Channel_6 */
{0x10, 0x0001, 2, 1}, /* AD7124_Channel_7 */
{0x11, 0x0001, 2, 1}, /* AD7124_Channel_8 */
{0x12, 0x0001, 2, 1}, /* AD7124_Channel_9 */
{0x13, 0x0001, 2, 1}, /* AD7124_Channel_10 */
{0x14, 0x0001, 2, 1}, /* AD7124_Channel_11 */
{0x15, 0x0001, 2, 1}, /* AD7124_Channel_12 */
{0x16, 0x0001, 2, 1}, /* AD7124_Channel_13 */
{0x17, 0x0001, 2, 1}, /* AD7124_Channel_14 */
{0x18, 0x0001, 2, 1}, /* AD7124_Channel_15 */
//REFBUF,AINBUF ON,REF_SEL=REFIN2,PGA=32
{0x19, 0x09e5, 2, 1}, /* AD7124_Config_0 */
//REFBUF,AINBUF ON,REF_SEL=REFIN2,PGA=16
//{0x1A, 0x09e5, 2, 1}, /* AD7124_Config_1 */
{0x1A, 0x01ec, 2, 1}, /* AD7124_Config_2 */
{0x1B, 0x0860, 2, 1}, /* AD7124_Config_2 */
{0x1C, 0x0860, 2, 1}, /* AD7124_Config_3 */
{0x1D, 0x0860, 2, 1}, /* AD7124_Config_4 */
{0x1E, 0x0860, 2, 1}, /* AD7124_Config_5 */
{0x1F, 0x0860, 2, 1}, /* AD7124_Config_6 */
{0x20, 0x0860, 2, 1}, /* AD7124_Config_7 */
{0x21, 0x060180, 3, 1}, /* AD7124_Filter_0 */
{0x22, 0x060180, 3, 1}, /* AD7124_Filter_1 */
{0x23, 0x060180, 3, 1}, /* AD7124_Filter_2 */
{0x24, 0x060180, 3, 1}, /* AD7124_Filter_3 */
{0x25, 0x060180, 3, 1}, /* AD7124_Filter_4 */
{0x26, 0x060180, 3, 1}, /* AD7124_Filter_5 */
{0x27, 0x060180, 3, 1}, /* AD7124_Filter_6 */
{0x28, 0x060180, 3, 1}, /* AD7124_Filter_7 */
{0x29, 0x800000, 3, 1}, /* AD7124_Offset_0 */
{0x2A, 0x800000, 3, 1}, /* AD7124_Offset_1 */
{0x2B, 0x800000, 3, 1}, /* AD7124_Offset_2 */
{0x2C, 0x800000, 3, 1}, /* AD7124_Offset_3 */
{0x2D, 0x800000, 3, 1}, /* AD7124_Offset_4 */
{0x2E, 0x800000, 3, 1}, /* AD7124_Offset_5 */
{0x2F, 0x800000, 3, 1}, /* AD7124_Offset_6 */
{0x30, 0x800000, 3, 1}, /* AD7124_Offset_7 */
{0x31, 0x500000, 3, 1}, /* AD7124_Gain_0 */
{0x32, 0x500000, 3, 1}, /* AD7124_Gain_1 */
{0x33, 0x500000, 3, 1}, /* AD7124_Gain_2 */
{0x34, 0x500000, 3, 1}, /* AD7124_Gain_3 */
{0x35, 0x500000, 3, 1}, /* AD7124_Gain_4 */
{0x36, 0x500000, 3, 1}, /* AD7124_Gain_5 */
{0x37, 0x500000, 3, 1}, /* AD7124_Gain_6 */
{0x38, 0x500000, 3, 1}, /* AD7124_Gain_7 */
};
配置完成后,就開始實(shí)現(xiàn)PT100以及熱電偶電壓采集了,AD7124-8可以通過(guò)使能多個(gè)通道寄存器,實(shí)現(xiàn)ADC多通道自動(dòng)切換,注意通道寄存器中的SETUP配置,這是通道寄存器與配置寄存器相關(guān)聯(lián)的地方,通過(guò)3bit Setup位以及16個(gè)通道寄存器可以組合出16*8= 108種組合配置,數(shù)據(jù)手冊(cè)的描述比較難理解
配置完成后,就只需要查詢AD7124-8狀態(tài)寄存器數(shù)據(jù)是否準(zhǔn)備好以及對(duì)應(yīng)的通道數(shù),數(shù)據(jù)如果準(zhǔn)備好,就可以讀取對(duì)應(yīng)通道的數(shù)據(jù),實(shí)現(xiàn)代碼如下:
if( AD7124_WaitForConvReady(&g_ad7124dev,100) >= 0 )
{
u8Ch = AD7124_STATUS_REG_CH_ACTIVE(ad7124_regs[AD7124_Status].value);
AD7124_ReadData(&g_ad7124dev, &s32AdCode[u8Ch]);
switch(u8Ch)
{
case 0:
fVolVal = 2500.0*(s32AdCode[u8Ch] - 0x800000)/(32.0*0x800000);
fK_mv = Temp2K_mv(fTempVal);
//fVolVal += fK_mv;
fK_TempVal = CalculateKTemp(fVolVal + fK_mv);
printf("Thermocouple Temperature: %5.3f C \r\n ",fK_TempVal );
break;
case 1:
//AD7124_ReadData(&g_ad7124dev, &s32AdCode[0]);
fResVal = s32AdCode[u8Ch]*250.0/0xffffff;
fTempVal = CalculateRTDTemp(fResVal);
printf("RTD Temperature: %5.3f C \r\n ",fTempVal );
break;
}
}
數(shù)據(jù)寄存器數(shù)據(jù)讀出來(lái)之后就剩下數(shù)據(jù)處理了,熱電偶的常用處理方式是冷端溫度轉(zhuǎn)換為對(duì)應(yīng)的熱電偶電壓,熱電偶熱端電壓+冷端電壓值得到的電壓值在轉(zhuǎn)換成熱電偶電壓,按照這種算法實(shí)現(xiàn)熱電偶測(cè)溫。軟硬件調(diào)試已經(jīng)完成,需要原理圖和源代碼的朋友可以發(fā)郵件聯(lián)系我leif.dong@avnet.com
附件是該方案的詳細(xì)資料,軟、硬件都有哦~