0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

DS2760 1-Wire高精度鋰離子電池監(jiān)視和保護IC在微控制器環(huán)境中的接口

星星科技指導(dǎo)員 ? 來源:ADI ? 作者:ADI ? 2023-03-01 15:22 ? 次閱讀

本應(yīng)用筆記為讀者提供如何將Maxim DS2760電池監(jiān)視器和保護器IC連接至微控制器信息。DS5000微控制器模塊用于示例目的。解決了硬件和軟件問題,包括框圖和示例C代碼,以便DS2760和微控制器之間通過Maxim 1-Wire?通信協(xié)議進(jìn)行通信。該器件提供了所有常用1-Wire命令的軟件例程,因此可用于任何采用1-Wire協(xié)議進(jìn)行通信的Maxim器件。此外,還提供常用電池監(jiān)測功能的例程,可與其它Maxim電池監(jiān)測器(如DS2761)配合使用。

介紹

將1-Wire器件連接至微控制器的過程非常簡單。本應(yīng)用說明 將介紹C語言的源代碼,為用戶提供簡單的嵌入式控制器1-Wire解決方案 應(yīng)用。

在下面的例子中,我們將演示一種從 微控制器向DS1K評估板讀取電壓、電流、累積電流和 溫度寄存器。DS2760K硬件用于簡化通信,因為它是一個 完整的電路,可輕松驗證源代碼。

硬件配置

本例使用DS5000(兼容8051)微控制器,工作頻率為11.059MHz。主持人 微控制器使用單線,上拉至V抄送通過一個4.7K電阻連接到DQ DS2760的輸入/輸出引腳其他微控制器可以很容易地被替換,一旦定時 已考慮到各種因素。對于一些更快的 微處理器。

接口時序

與DS2760的每個通信序列必須以1-Wire復(fù)位開始。定義復(fù)位脈沖 作為總線主控器將1-Wire總線(或DQ線)從非活動高電平狀態(tài)拉低480μs 到960μs,然后釋放它。如果總線上有1-Wire器件,它將通過將DQ線拉低來響應(yīng) 以指示其在1-Wire總線上的存在。1-Wire復(fù)位時序如圖1所示。

當(dāng)總線主控器將 DQ 拉低時,將啟動寫入時隙。所有寫入和讀取時隙都必須 持續(xù)時間為 60μs 至 120μs,周期之間的最短恢復(fù)時間為 1μs。在寫入“0”時間內(nèi) 時隙,總線主站將在該時隙的持續(xù)時間內(nèi)將線路拉低。但是,在寫入“1”期間 時隙,總線主站將線路拉低,最長15μs,如果持續(xù)<>μs,則釋放 的時間段。

當(dāng)總線主控器將1-Wire總線拉低時啟動讀取時隙。線路必須保持低電平 1μs,然后釋放,使DS2760能夠控制線路并呈現(xiàn)有效數(shù)據(jù)。如果“0”是 DS2760放在總線上,當(dāng)主機釋放數(shù)據(jù)電平時,它將保持DQ線路為低電平。如果 DS2760放置一個“1”,當(dāng)總線主控釋放總線時,DQ將被允許走高。這 然后,master 將對 DQ 行進(jìn)行采樣,以確定是從設(shè)備讀取“0”還是“1”。1-Wire 寫入和讀取時隙如圖 2 所示。

軟件控制

為了精確控制1-Wire接口的時序要求,某些關(guān)鍵功能必須 首先要成立。創(chuàng)建的第一個函數(shù)必須是“延遲”函數(shù),它是所有讀取不可或缺的函數(shù) 和寫入控制。此功能將完全取決于微控制器的速度。為此 例如,使用了工作頻率為5000.8051MHz的DS11(兼容059)微控制器。示例 下面說明了用于創(chuàng)建時序延遲的 C 原型函數(shù)。調(diào)用此例程需要 24μs 然后每次計數(shù)需要另外 16μs。

// DELAY - with an 11.059MHz crystal.
// Calling the routine takes about 24μs, and then each count takes another 16μs.
void delay(int μseconds)
{
int s;
for (s=0; s<μseconds;s++);
}

復(fù)位時隙為480μs,詳見下文C語言。DQ 線被拉低并保持低電平 延遲為“29”,實際上是488μs的延遲。然后,DQ 行被釋放到高狀態(tài)。延遲后 “3”,即72μs,主站對DQ線進(jìn)行采樣,以查看設(shè)備是否通過拉動DQ進(jìn)行響應(yīng) 行低表示設(shè)備“存在”。讀取的每個位都遵循與1-Wire復(fù)位類似的順序,但沒有延遲。DQ 生產(chǎn)線 被拉低然后釋放,然后主控對 DQ 線進(jìn)行采樣,然后返回值。當(dāng)寫入一個位時,主機將線路拉低1μs(對于寫入“1”)或104μs(在本例中為a 寫“0”。讀取和寫入一個字節(jié)只是從最少的開始一個接一個地讀取或?qū)懭?8 位 重要的位。

// OW_RESET - performs a reset on the one-wire bus and returns the presence detect. 
// Reset is 480μs, so delay value is (480-24)/16 = 28.5 - we use 29. 
// Presence checked another 70μs later, so delay is (70-24)/16 = 2.875 - we use 3.
//
unsigned char ow_reset(void)
{
unsigned char presence;
DQ = 0; //pull DQ line low
delay(29); // leave it low for 480μs
DQ = 1; // allow line to return high
delay(3); // wait for presence
presence = DQ; // get presence signal
delay(25); // wait for end of timeslot
return(presence); // presence signal returned
} // 0=presence, 1 = no part

//////////////////////////////////////////////////////////////////////////////
// READ_BIT - reads a bit from the one-wire bus. The delay
// required for a read is 15μs, so the DELAY routine won't work.
// We put our own delay function in this routine in the form of a
// for() loop.
//
unsigned char read_bit(void)
{
unsigned char i;
DQ = 0; // pull DQ low to start timeslot
DQ = 1; // then return high
for (i=0; i<3; i++); // delay 15μs from start of timeslot
return(DQ); // return value of DQ line
}

//////////////////////////////////////////////////////////////////////////////
// WRITE_BIT - writes a bit to the one-wire bus, passed in bitval.
void write_bit(char bitval)
{
DQ = 0; // pull DQ low to start timeslot
if(bitval==1) DQ =1; // return DQ high if write 1
delay(5); // hold value for remainder of timeslot
DQ = 1;
}// Delay provides 16μs per loop, plus 24μs. Therefore delay(5) = 104μs

//////////////////////////////////////////////////////////////////////////////
// READ_BYTE - reads a byte from the one-wire bus.
//
unsigned char read_byte(void)
{
unsigned char i;
unsigned char value = 0;
for (i=0;i<8;i++)
{
if(read_bit()) value|=0x01<
//////////////////////////////////////////////////////////////////////////////
// WRITE_BYTE - writes a byte to the one-wire bus.
//
void write_byte(char val)
{
unsigned char i;
unsigned char temp;
for (i=0; i<8; i++) // writes byte, one bit at a time
{
temp = val>>i; // shifts val right 'i' spaces
temp &= 0x01; // copy that bit to temp
write_bit(temp); // write bit in temp into
}
delay(5);
}

讀取網(wǎng)絡(luò)地址

每個DS2760都有一個唯一的64位凈地址?!白x取網(wǎng)絡(luò)地址”命令用于查找 64- 1-Wire總線上只有一個器件時,位網(wǎng)絡(luò)地址。多個設(shè)備需要使用 此處未顯示的搜索網(wǎng)絡(luò)地址功能。DS2760可配置為使用讀取網(wǎng)絡(luò) 地址為 0x33h 或 0x39h。

unsigned char Read_NetAddress(void)
{
int n;
char dat[9];
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0x33); //Read Net Address Command (0x33h)
for (n=0;n<8;n++)
dat[n]=read_byte(); //Read 8 bytes of Net Address
printf("\n Net Address Code %X%X%X%X\n",dat[7],dat[6],dat[5],dat[4],dat[3],dat[2],dat[1],dat[0]);
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}

讀取實時數(shù)據(jù)

如果1線總線上有單個器件,則實時讀取電壓、電流、累積 電流和溫度可以直接使用,如下所示。如果存在 1 臺以上的設(shè)備,則匹配 必須使用網(wǎng)絡(luò)地址例程。所有這些功能都可以通過以下方式組合成一個例程 只需從電壓寄存器地址開始,然后繼續(xù)發(fā)出 read_byte() 命令 直到讀取所有所需的字節(jié)。

unsigned char Read_ Voltage (void)
{
int lsb, msb, temp;
float Voltage; //This value may be declared globally
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0xCC); // Skip Net Address Command
write_byte(0x69); // Read Registers Command
write_byte(0x0C); // Voltage Register Address
msb = read_byte(); // Read msb
lsb = read_byte() & 0xE0; // Read lsb and mask off lower 5 bits
if((msb & 0x80) == 0x80) //if sign bit is set
temp = (msb<<8 + lsb) - 65536;
else
temp = msb<<8 + lsb;
Voltage = (temp>>5) * 0.00488; //Voltage in Volts
printf("\nVoltage = &d", Voltage);
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}
unsigned char Read_NetAddress(void)
{
int n;
char dat[9];
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0x33); //Read Net Address Command (0x33h)
for (n=0;n<8;n++)
dat[n]=read_byte(); //Read 8 bytes of Net Address
printf("\n Net Address Code %X%X%X%X\n",dat[7],dat[6],dat[5],dat[4],dat[3],dat[2],dat[1],dat[0]);
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}
unsigned char Read_Current (void)
{
int lsb, msb, temp;
float Current; //This value may be declared globally
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0xCC); // Skip Net Address Command
write_byte(0x69); // Read Registers Command
write_byte(0x0E); //Current Register Address
msb = read_byte(); // Read msb
lsb = read_byte() & 0xF8; // Read lsb and mask off lower 3 bits
if((msb & 0x80) == 0x80) //if sign bit is set
temp = (msb<<8 + lsb) - 65536;
else
temp = msb<<8 + lsb;
Current = (temp>>3) * 0.000015625 / .025; //Current in mAmps
//assuming a 25mOhm Sense Resistor
printf("\nCurrent = &d", Current);
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}
unsigned char Read_ACR(void)
{
int lsb, msb, temp;
float ACR; //This value may be declared globally
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0xCC); // Skip Net Address Command
write_byte(0x69); // Read Registers Command
write_byte(0x10); //ACR Register Address
msb = read_byte(); // Read msb
lsb = read_byte(); // Read lsb
if((msb & 0x80) == 0x80) //if sign bit is set
temp = (msb<<8 + lsb) - 65536;
else
temp = msb<<8 + lsb;
ACR = temp * 0.00625 / .025; //Capacity in mAhrs
//assuming a 25mOhm Sense Resistor
printf("\nACR = &d", ACR);
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}
unsigned char Read_Temperature(void)
{
int lsb, msb,temp;
float temp_f,temp_c; //These values may be declared globally
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0xCC); // Skip Net Address Command
write_byte(0x69); // Read Registers Command
write_byte(0x18); //Temperature Register Address
msb = read_byte(); // Read msb
lsb = (read_byte() & 0xE0); // Read lsb, mask off lower 5 bits
if((msb & 0x80) == 0x80) //if sign bit is set
temp = (msb<<8 + lsb) - 65536;
else
temp = msb<<8 + lsb;
temp_c = (temp>>5) * 0.125; //temperature in Degrees C
temp_f = ((temp_c)* 9)/5 + 32; //temperature in Degrees F
printf("\nTemp C = &d", temp_c);
printf("\nTemp F = &d", temp_f);
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}
unsigned char Read_UserMemory(void)
{
int j;
int Memory[32]; //This value may be declared globally
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0xCC); // Skip Net Address Command
write_byte(0x69); // Read Registers Command
write_byte(0x20); // Block 0 Address
for (j=0;j<32;j++) //Read all 32 Bytes
{
Memory[j]=read_byte();
printf("\n%X , " , Memory[j]);
}
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}

讀取用戶內(nèi)存

DS2760包含32字節(jié)的用戶EEPROM,可以使用以下代碼讀取。

unsigned char Read_UserMemory(void)
{
int j;
int Memory[32]; //This value may be declared globally
if(ow_reset()==0) //If a presence is detected, continue to read
{
write_byte(0xCC); // Skip Net Address Command
write_byte(0x69); // Read Registers Command
write_byte(0x20); // Block 0 Address
for (j=0;j<32;j++) //Read all 32 Bytes
{
Memory[j]=read_byte();
printf("\n%X , " , Memory[j]);
}
return(0); //Return 0 if no error
}
return(1); //Return 1 if no presence detected
}

審核編輯:郭婷


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 微控制器
    +關(guān)注

    關(guān)注

    48

    文章

    7334

    瀏覽量

    150080
  • Maxim
    +關(guān)注

    關(guān)注

    8

    文章

    859

    瀏覽量

    86944
  • 電池
    +關(guān)注

    關(guān)注

    84

    文章

    10183

    瀏覽量

    127008
收藏 人收藏

    評論

    相關(guān)推薦

    鋰離子電池保護器及監(jiān)控 (圖)

    系統(tǒng)連接,可對鋰離子電池組成的電源進(jìn)行管理及控制,即實現(xiàn)與內(nèi)部存儲進(jìn)行讀/寫訪問及控制。該器件功耗低,工作狀態(tài)時最大電流80μA,節(jié)能狀態(tài)(睡眠模式)時小于2μA?! ?/div>
    發(fā)表于 09-12 11:01

    鋰離子電池保護器及監(jiān)控 (圖)

    系統(tǒng)連接,可對鋰離子電池組成的電源進(jìn)行管理及控制,即實現(xiàn)與內(nèi)部存儲進(jìn)行讀/寫訪問及控制。該器件功耗低,工作狀態(tài)時最大電流80μA,節(jié)能狀態(tài)(睡眠模式)時小于2μA?! ?/div>
    發(fā)表于 09-16 16:21

    鋰離子電池保護器

    鋰離子電池保護器IC有適用于單節(jié)的及2~4節(jié)電池組的。這里介紹這類保護器的要求,并重點介紹單節(jié)鋰離子電池
    發(fā)表于 05-27 13:14

    鋰離子電池集成保護電路的基本功能

    正常工作狀態(tài)下,保護電路的FET都為接通狀態(tài)。為了提高鋰離子電池放電電流及充電電流的利用效率,F(xiàn)ET應(yīng)采用導(dǎo)通阻抗較小的功率MOS管。(1)過充電保護當(dāng)
    發(fā)表于 05-24 10:54

    微控制器1-Wire溫度傳感的軟件接口

    圖見圖0所示。 目前有數(shù)種方法,可將1-Wire器件,如DSl8B20、DSl822或DSl8S20與微控制器接口。這些方法包括:從簡單的軟件方案,到串行接口芯片,如
    發(fā)表于 12-17 11:29

    基于鋰離子電池的過充保護方案

    免受損壞。 JDT高分子PTC熱敏電阻產(chǎn)品,高電流密度的鋰離子電池及其管理電路的過流、過溫、短路保護具有突出的優(yōu)勢,JDT高分子PTC熱敏電阻又叫自復(fù)位過載
    發(fā)表于 11-04 06:37

    TWL2213鋰離子電池充電控制器相關(guān)資料推薦

    概述:TWL2213是一款鋰離子電池充電控制器,它為四面48腳封裝。絕對最大額定參數(shù)值:VCHG(腳32)電壓為-0.3V到12V,其它所有引腳上的電壓為-0.3V到65V,工作環(huán)境溫度為-25
    發(fā)表于 05-18 07:38

    鋰離子電池保護IC定義和工作原理

    鋰離子電池的電壓和電流。異常的情況下,它將通過控制保護電路控制鋰離子電池的狀態(tài)。
    發(fā)表于 03-22 10:57

    DS2790可編程、1 節(jié)鋰離子電池電量計與保護器

    DS2790可編程、1 節(jié)鋰離子電池電量計與保護器 DS2790為單節(jié)鋰離子電池提供完整的
    發(fā)表于 04-12 16:01 ?52次下載

    Interfacing the DS2760 1-Wire

    the Maxim DS2760 Battery Monitor and Protector IC to a microcontroller. The DS5000 microcontroller module is used
    發(fā)表于 04-23 14:43 ?1188次閱讀
    Interfacing the <b class='flag-5'>DS2760</b> <b class='flag-5'>1-Wire</b>

    接口DS2760 1高精度鋰離子電池監(jiān)控和保護IC單片

    the Maxim DS2760 Battery Monitor and Protector IC to a microcontroller. The DS5000 microcontroller module is used
    發(fā)表于 04-29 11:34 ?977次閱讀
    <b class='flag-5'>接口</b>的<b class='flag-5'>DS2760</b> <b class='flag-5'>1</b>線<b class='flag-5'>高精度</b><b class='flag-5'>鋰離子電池</b>監(jiān)控和<b class='flag-5'>保護</b><b class='flag-5'>IC</b><b class='flag-5'>在</b>單片

    DS2760DS2761電池監(jiān)測多節(jié)電池中的應(yīng)用

    DS2760DS2761電池監(jiān)控和保護器電池管理IC,主要用于單節(jié)
    的頭像 發(fā)表于 01-11 14:58 ?1051次閱讀
    <b class='flag-5'>DS2760</b>或<b class='flag-5'>DS</b>2761<b class='flag-5'>電池</b>監(jiān)測<b class='flag-5'>器</b><b class='flag-5'>在</b>多節(jié)<b class='flag-5'>電池</b>中的應(yīng)用

    DS18X20/DS1822 1-Wire溫度傳感微控制器環(huán)境接口

    本應(yīng)用向用戶介紹簡單的1-Wire軟件,用于將微控制器連接至DS18B20、DS18S20和DS1822
    的頭像 發(fā)表于 03-01 14:34 ?1543次閱讀
    <b class='flag-5'>DS</b>18X20/<b class='flag-5'>DS</b>1822 <b class='flag-5'>1-Wire</b>溫度傳感<b class='flag-5'>器</b><b class='flag-5'>在</b><b class='flag-5'>微控制器</b><b class='flag-5'>環(huán)境</b><b class='flag-5'>中</b>的<b class='flag-5'>接口</b>

    測試和校準(zhǔn)DS2760鋰離子電池監(jiān)測和保護器電路

    本應(yīng)用筆記向讀者介紹如何正確測試包含達(dá)拉斯半導(dǎo)體DS2760電池監(jiān)測保護器的電路板和電池組。提供了分步測試程序,可以遵循該程序以確保電路
    的頭像 發(fā)表于 03-09 14:24 ?734次閱讀
    測試和校準(zhǔn)<b class='flag-5'>DS2760</b><b class='flag-5'>鋰離子電池</b>監(jiān)測和<b class='flag-5'>保護器</b>電路

    DS2760 1-Wire高精度鋰離子電池監(jiān)視保護IC微控制器環(huán)境接口

    本應(yīng)用筆記為讀者提供如何將Maxim DS2760電池監(jiān)視器保護器IC連接至微控制器的信息。
    的頭像 發(fā)表于 03-10 11:35 ?717次閱讀