智能电池管理系统应用

来源:互联网 发布:在淘宝怎么图片搜索 编辑:程序博客网 时间:2024/04/29 08:39

硬件接口:

本项目硬件接口采用ARM处理器s3c6410的ADC和触摸屏复用功能的接口,因为触摸屏我们选择的是一线触摸式的,而不是四线电阻式的。所以复用接口可以被复用为ADC。

ADC接口功能描述:

这里要用到ADC接口,所以只描述接口ADC功能。

接口操作:


当触摸屏装置被使用,触摸屏的I/F,XM或YM只接地。当触摸屏的装置未被使用,为正常ADC转换,XM或YM是连接模拟输入信号的。


1. A\D转换时间

当GCLK频率为50Mhz,预分频值为49时,10位转换的所有时间如下:

A/D转换频率= 50MHz(49+1)= 1MHz

转换时间 = 1/(1MHz / 5 周期) = 1/200 kHz = 5 us

A/D转换器可运行最大2.5MHz时钟频率,因此转换率高达500kbps。

2. 待机模式

当ADCCON[2]被设定为‘1’时,待机模式被激活。在此模式下,A/D转换操作停止,并且ADCDAT0,ADCDAT1寄存器包含先前转换的数据。

3. 编程记录

(1)该A/D转换的数据通过中断或轮询的方法被访问。中断方法——整个转换时间是从ADC开始到数据转换读取,因为中断服务程序的返回时间和数据存取时间,可能会有延时。轮询方法用来检查ADCCON[15]位,交换最后的特征位。该读取时间通过ADCDAT寄存器才能确定。

(2)启动A/D转换的另一种方法。ADCCON[1]——A/D转换的启动读取方式,设置为1。A/D转换开始时,同时转换成数据读取。即读取数据的同时,转换同时开始。

4. ADC接口相关的特殊寄存器

(1)ADC的控制寄存器(ADCCON)






第二位置1,表示启动AD转换的另一种方式。

(2)ADC开始延迟寄存器(ADCDLY)——6410与2410区别:6410有时钟初始化选择,2410应该是默认的两种当中的一个。



注:在ADC的转换,触摸屏使用的X_tal时钟(3.68MHz)。在ADC转换使用GCLK(最大50MHz)。2410中使用时钟PCLK也为50MHz。

(3)ADC数据转换寄存器(ADCDAT0)



(4)ADC的数据转换寄存器(ADCDAT1)




电池的电压、电流、温度相关参数主要通过ADC的4个通道采集,采集到的参数值供主程序判断充电状态。

ADC.c

/*********************************************************************************************************************************

* 文件名:ADC.c

* 功能描述:S3C2410处理器ADC测试

********************************************************************************************************************************/

#define REQCNT 100

#define ADC_FREQ 2500000

#define LOOP 10000


volatile U32 preScaler;

INT16U Temperature_1=0; //used by save the first way Battery temperature

INT16U Temperature_2=0;//used by save the second way Battery temperature


INT16S Current_1 = 0; //used by save the first way Battery current

INT16S Current_2=0;//used by save the second way Battery current


INT16U Volatile_1 = 0; //used by save the first way Battery volatile

INT16U Volatile_2=0;//used by save the second way Battery volatile


//read ADC chanel

int ReadAdc(int ch)

{

int i;

static int prevCh=-1;

rADCCON=(1<<14)+(preScaler<<6)+(ch<<3);//setup number of chanels 

if(prevCh! = ch)

{

rADCCON=(1<<14)+(preScaler<<6)+(ch<<3);//setup chanel

for(i=0;i<LOOP;i++)

prevCh=ch; //setup another chanel by delay

}


rADCTSC=rADCTSC & 0xfb;//normal ADC conversion and not touchscreen operations

rADCCON|=0x1; //start ADC

while(rADCCON & 0x1);//check  out whether  Enable_start is low 

while(!(rADCCON & 0x8000));//check out whether the flag bit of EC(end of conversion) is high

return((int)rADCDAT0 & 0x3ff);

}


//test data for each chanel

void Test_Adc(void)

{

int a0= 0,a1,a2,a3,a4,a5,a6,a7;//init variable,start 8 chanel,a6 and a7 not use;

U32 rADCCON_save= rADCCON;

Uart_Printf("ADC INPUT Test,press ESC key to exit !\n");

preScaler= ADC_FREQ;

Uart_Printf("ADC conv.freq. = %dHz \n",preScaler);

preScaler= 50000000/ADC_FREQ - 1;//PCLK:50.7MHz

Uart_Printf("PCLK/ADC_FREQ - 1 = %d\n",preScaler);

while(Uart_GetKey()! = ESC_KEY)

{

a0 = ReadAdc(0);//first way battery voltage

Uart_Printf("AIN0: %04d\n",a0);

Voltage_1 = a0;


a1 = ReadAdc(1);//first way battery current

Uart_Printf("AIN1: %04d\n",a1);

Curret_1 = a1;


a2 = ReadAdc(2);//first way battery test temperature

Uart_Printf("AIN2: %04d\n",a2);

Temperature_1 = a2;


a3 = ReadAdc(3);//second way battery test temperature

Uart_Printf("AIN3: %04d\n",a3);

Voltage_2 = a3;

a4 = ReadAdc(4);//second way battery current

Uart_Printf("AIN4: %04d\n",a4);

Curret_2 = a4;


a5 = ReadAdc(5);//second way battery test temperature

Uart_Printf("AIN5: %04d\n",a5);

Temperature_2 = a5;

Delay(500);

}


rADCCON = rADCCON_save;

Uart_Printf("\nrADCCON = 0x % x\n",rADCCON); 


}