TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F28035: Problems in using the ADC function of TMS320F28035 to collect the power supply voltage

Part Number:TMS320F28035

There are some problems when using the TMS320F28035 chip:

Objective: To use the ADCINA1 passband of the TMS320F28035 chip (56-pin) for power supply voltage measurement

Tools: Already have TMS320F28035 chip (64 pin) ADCINA1 measure the power supply voltage code (after the test code is correct, can normally read 0-3.3V voltage value), the specific code is as follows:

First, the main.c code:

#include "DSP2803x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2803x_Examples.h" // DSP2833x Examples Include Fi

#include "stdio.h"
#include "Battery.h"
#include "leds.h"
#include "Tim.h"
extern Uint16 RamfuncsLoadSize;
/******************************************************************************
*函数原型:		void main(void)
*函数功能:飞控主函数
*******************************************************************************/
void main(void)
{
	InitSysCtrl();
	DINT;
	InitPieCtrl();
	IER = 0x0000;
	IFR = 0x0000;
	InitPieVectTable();
	memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize);
	LED_Init();// 初始化LED-
	BatteryCheckInit();// 初始化电池检测ADC-
	BatteryCheck();// 检测电池电压;软件触发ADC采集-
	Timer0_init();// 定时器0初始化,1ms周期中断-
	PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
	EINT;
	ERTM;while(1)
	{

/* 电源电压检测及片上温度检测;信号灯提示(100ms为一个周期)*/	if(timer0Base.loop10HzCnt >= 1000)	{		timer0Base.loop10HzCnt=0;		BatteryCheck();// 电源电压监控TemperatureCheck();// 片上温度采集		//LEDFSM();// 信号灯提示LED1_TOGGLE;LED2_TOGGLE;	}
	}
}

Battery.c code

#include "Battery.h"

#include "stdio.h"

Bat_Typedef Battery;
int adcVal[2]={0};//ADC 采样结果
char adcISRFlag=0;//ADC 中断标识
int16 degC; //temperature in deg. C
interrupt void adc_isr(void);
/*******************************************************************************
* 函 数 名:void BatteryCheckInit(void)
* 函数功能:AD初始化;将模拟值输入到A1通道
*******************************************************************************/
void BatteryCheckInit(void)
{
	InitAdc();  // 初始化ADC对应的GPIO
	EALLOW;
	PieVectTable.ADCINT3 = &adc_isr;// AD中断函数映射
	EDIS;
	PieCtrlRegs.PIEIER10.bit.INTx3 = 1;//使能 PIE 的 INT10.3
	IER |= M_INT10;
	EALLOW;
	AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1;  //不允许重叠采样
	AdcRegs.ADCCTL1.bit.TEMPCONV  = 1; 		//设置片上温度传感器
	FlashRegs.FOTPWAIT.bit.OTPWAIT = 1;//设置 flash OTP 等待状态为最小,以保证温度转换函数的性能
	EDIS;
	EALLOW;
	AdcRegs.ADCCTL1.bit.ADCREFSEL	= 0;//Internal Bandgap//内部带隙产生参考电压
	AdcRegs.ADCCTL1.bit.INTPULSEPOS	= 1;	//ADCINT1 trips 产生中断脉冲, 1 个周期后 ADC 锁存到结果寄存器。
	AdcRegs.INTSEL3N4.bit.INT3E= 1;	//Enabled ADCINT3
	AdcRegs.INTSEL3N4.bit.INT3CONT  = 0;	//禁止连续转换模,single conversion mode 直到 ADCINTx 标志 (在 ADCINTFLG 寄存器) 由用户清除, 无进一步的 ADCINTx脉冲产生。
	AdcRegs.INTSEL3N4.bit.INT3SEL	= 1;	//创建EOC1,EOC1 为 ADCINTx 的触发。
	AdcRegs.ADCSOC0CTL.bit.TRIGSEL 	= 0x00; //软件触发,没有 ADCINT 触发 SOCx。 TRIGSEL 位域确定 SOCx 触发。
	AdcRegs.ADCSOC1CTL.bit.TRIGSEL 	= 0x00; //软件触发,没有 ADCINT 触发 SOCx。 TRIGSEL 位域确定 SOCx 触发。
	AdcRegs.ADCSOC0CTL.bit.CHSEL 	= 5;	//片上温度采集,SOCx通道选择
	AdcRegs.ADCSOC1CTL.bit.CHSEL 	= 1;	//电源采集,SOCx 通道选择
	AdcRegs.ADCSOC0CTL.bit.ACQPS 	= 6;	//设置窗口,SOCx 采样预定标, 为 SOCx 控制采样保持窗口, 最小值为6
	AdcRegs.ADCSOC1CTL.bit.ACQPS 	= 6;	//设置窗口,采样窗为7 个周期长 (6 + 1 时钟周期)
	EDIS;
	Battery.ADRef= 3.31;// 实际测量的MCU供电电压
	Battery.Bat_K= 1.0;// 电压校准系数
	Battery.overDischargeCnt = 0;
	Battery.Calisum = 0.0;// 电池的sum校准系数
	printf("\r\nADC(BATTERY) init...OK");
}

/*******************************************************************************
* 函 数 名:void BatteryCheckInit(void)
* 函数功能:AD 中断处理函数
*******************************************************************************/
interrupt void  adc_isr(void)
{
	EALLOW;
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP10;//Acknowledge interrupt to PIE
	EDIS;
	AdcRegs.ADCINTFLGCLR.bit.ADCINT3 = 1;	//Clear ADCINT1 flag
	adcISRFlag = 1;
	adcVal[0]=AdcResult.ADCRESULT0; //温度
	adcVal[1]=AdcResult.ADCRESULT1; //电压
}

/*******************************************************************************
* 函 数 名:int GetBatteryAD(u8 ch)
* 函数功能:获取电池单次的ADC
*******************************************************************************/
int GetBatteryAD(u8 ch)
{
	AdcRegs.ADCSOCFRC1.all = 0X03; //软件触发AD 的 SOC0--SOC1采样
	if(adcISRFlag == 1)
	{
		adcISRFlag = 0;
	}
	return adcVal[ch];
}

/*******************************************************************************
* 函 数 名:int Get_Adc_Average(u8 ch,u8 times)
* 函数功能:获取A1通道的AD值
*******************************************************************************/
int Get_Adc_Average(u8 ch,u8 times)
{
	int temp_val=0;
	u8 t;
	for(t=0;t<times;t++)
	{
		temp_val+=(GetBatteryAD(ch));
	}
	return temp_val/times;
}

/*******************************************************************************
* 函 数 名:void TemperatureCheck(void)
* 函数功能:检测MCU温度
*******************************************************************************/
void TemperatureCheck(void)
{
	degC = GetTemperatureC(Get_Adc_Average(0,5));// 片上温度采样
}

/*******************************************************************************
* 函 数 名:void BatteryCheck(void)
* 函数功能:检测电池电压;过放报警和过放保护
*******************************************************************************/
void BatteryCheck(void)
{
	Battery.BatteryAD  = Get_Adc_Average(1,5);  // 滤波后的电压值
	//printf("\r\n滤波后的电压值:%d\n",Battery.BatteryAD);
	Battery.BatteryVal = (float)(Battery.Bat_K*((Battery.BatteryAD/4096.0)*Battery.ADRef))+Battery.Calisum;//实际电压值计算printf("\r\n实际电压值:%f\n",Battery.BatteryVal);

	if(1)
	{
		if(Battery.BatteryVal <= (BAT_OVERDIS_VAL + 0.03))
		{
			Battery.alarm=1;// 报警位
		}else{
			Battery.alarm=0;
		}

		if(Battery.BatteryVal <= BAT_OVERDIS_VAL)
		{
			Battery.overDischargeCnt++;// 过放保护计数
			if(Battery.overDischargeCnt > 3)
			{
			
			}
		}else
			{
				Battery.overDischargeCnt = 0;
			}
	}
	else
	{
		if(Battery.BatteryVal < BAT_ALARM_VAL) // 3.65V
		{
			Battery.alarm=1;// 报警位
		}else{
			Battery.alarm=0;
		}
	}
}

Battery.h code

#ifndef INC_BATTERY_H_
#define INC_BATTERY_H_

#include "DSP2803x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2803x_Examples.h" // DSP2833x Examples Include Fi

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned long
#define uint64_t unsigned long long
#define int8_t  signed char
#define int16_t signed short
#define int32_t signed long
#define int64_t signed long long

typedef int8_t s8;
typedef uint8_t u8;
typedef int16_t s16;
typedef uint16_t u16;
typedef int32_t s32;
typedef uint32_t u32;



extern int adcVal[];//ADC 采样结果
extern char adcISRFlag;//ADC 中断标识
extern int16 degC;

#define BAT_CHK_PRD500
#define BAT_ALARM_VAL3.65
#define BAT_OVERDIS_VAL 3.15

//电压信息结构体
typedef struct
{
float  ADRef;// AD参考源
float  Bat_K;// 计算电压值
charalarm;// 电池报警位
charchargeSta;// 充电状态
float  BatteryVal;// 电压
intBatteryAD;// 电压
intoverDischargeCnt;// 过放保护计数
float  Calisum;
}Bat_Typedef;
extern Bat_Typedef Battery;

/*函数声明*/
void BatteryCheckInit(void);
int Get_Adc_Average(u8 ch,u8 times);
int GetBatteryAD(u8 ch);
void TemperatureCheck(void);
void BatteryCheck(void);

#endif /* INC_BATTERY_H_ */

After my test, the code in TMS320F28035 (64 pin) can normally collect the power supply voltage through the ADCINA1 channel. Due to work requirements, now I need to switch to the chip TMS320F28035 (56-pin), which also needs to collect the power supply voltage. Using the same code and ADCINA1 channel, I failed to collect the real power supply voltage, and the collected result is displayed as about 0.0V. I have the following problems:

1. The corresponding pin of ADCINA1 of TMS320F28035 (56-pin) is 12, while the corresponding pin of ADCINA1 of (64-pin) is 14. Do I need to configure the pin (or GPIO) in ccs software?

2. The hardware schematic diagram I drew is as follows. It can be seen that the acquisition line of ADCINA1 is directly connected to the battery power line (full voltage 4.2v for 1s lithium battery). I did not use the voltage division circuit for voltage reduction, is it possible that the ADCINA1 interface has been burned out?

3. Run the program in the control board I drew with the above code, and the voltage value collected by the ADC has been changing around 0.055615v (maximum 0.1v). Does this mean that the ADCINA1 acquisition port is grounded?

4. If I place the ADC1 acquisition port behind the capacitor (as shown below), can I use it directly without adding other voltage divider circuits?

5. If the divider circuit must be used, how to draw the detailed schematic diagram of the divider ADC collection divider circuit?

Urgently need to solve, hope to get your reply as soon as possible,thanks!!!

Yale Li:

1. You need to re-route the ADCINA1 pin for 56pin device. It is achieved by modify the code.

2. Yes, this pin will be damaged very likely.

3. Do you mean that you think the circuit is damaged? That means the point ADC1 is shorted to the ground? You can power-off the circuit then check it.

4. It decided by the voltage range that this pin measured.

5. ADC front-end circuit is a large topic. The most simple way is using resistors to divide the voltage. Please refer the following links for further:

https://www.ti.com.cn/zh-cn/design-development/analog-circuits.html

zhcy094a_模拟工程师电路设计指导手册:数据转换器 (Rev. A)

spract6a_ADC Input Circuit Evaluation for C2000 MCUs (using TINA-TI simulation tool) (Rev. A)

Introduction to SAR ADC front-end component selection

,

DSP入门学习:

Hi Yale Li,

Thank you very much for answering my questions. I will carefully study the materials and tutorials you provided.

I have the following questions:

1.Which line of code in which file should I modify to correctly configure a 56pin ADCINA1 channel? (I looked up the code carefully and did not find where to configure a 56pin ADCINA1 channel)

2.What is the maximum voltage that the ADCINA1 channel of TMS320F28035RSHT(56pin) chip can input? (no divider circuit)

3."Do you mean that you think the circuit is damaged?"→Yes, I think my ADCINA1 channel has been burned out. I input about 5v voltage to the ADCINA1 channel (without partial voltage), but when the ADC collection code is correct, the measured voltage value is 0.0, so I suspect that the ADCINA1 channel has been burned out.

4.If I place the ADC1 acquisition port behind the capacitor (as shown below), can I use it directly without adding other voltage divider circuits?

Thank you again and look forward to your reply.

Andy

,

Yale Li:

1. My fault. It doesn't need. In C2000 device, the analog pin is discrete with the digital pin.

2. It is decided by which reference voltage you are using. Pls check the related part in datasheet:

https://www.ti.com/lit/ds/symlink/tms320f28035.pdf

3. You can use routine to check if the device has been damaged.

Which board are you using? TI's demo board? Whatever which board you are using, you need to discrete the external circuit from the ADC pin. The 5V voltage is not applicable on this pin.

4. No. It is same node.

,

DSP入门学习:

Dear Yale Li,

Thank you for your earnest reply, which is very helpful to me.

I now know that my mistake was on the ADCINA1 acquisition port, I should not have connected the acquisition port directly to the positive terminal of the 1S lithium battery without using the voltage divider circuit.

After carefully consulting the information you provided and your detailed answers, I modified my circuit schematic diagram (Figure 1). I think this schematic diagram is correct, and the power supply voltage of 1S lithium battery can be correctly collected.

Do you think it is feasible to modify the circuit in this way? Can I collect a voltage value of 4.2V?

If this circuit is feasible, I will start to submit PCB boards for production.

Looking forward to your reply. Thank you very much

Best wishes

Andy

,

Yale Li:

Yes. At least it provide the correct voltage.

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F28035: Problems in using the ADC function of TMS320F28035 to collect the power supply voltage
分享到: 更多 (0)