📄 current.c
字号:
#include "IQmathLib.h"
#include "math.h"
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
void Adc_config(void);
float Current_sensor[6];
float Sensor_V[6];
float Sensor_C[6];
interrupt void ADC_Timer(void);
void compute(float *);
void Ecan_Init();
void EcanTx5(int);
main(){
InitSysCtrl();
EALLOW;
SysCtrlRegs.HISPCP.all = 0x3; // HSPCLK = SYSCLKOUT/6
EDIS;
DINT;
InitPieCtrl();
IER=0x0000;
IFR=0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &ADC_Timer; //int vector
EDIS;
InitAdc();
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EALLOW;
GpioMuxRegs.GPBMUX.bit.T3PWM_GPIOB6 = 0; //confige as I/O
GpioMuxRegs.GPBDIR.bit.GPIOB6 = 1; //confige as output I/O
GpioMuxRegs.GPBMUX.bit.T4PWM_GPIOB7 = 0; //confige as I/O
GpioMuxRegs.GPBDIR.bit.GPIOB7 = 1; //confige as output I/O
EDIS;
EINT; // Enable Global interrupt INTM
ERTM;
LoopCount = 0;
// Configure ADC
Adc_config();
Ecan_Init();
LED2=1;
// Wait for ADC interrupt
EnableInterrupts();
while(1)
{
LoopCount++;
if(LoopCount>0x8888) LoopCount=0;
LED1=0;
DSP28x_usDelay(100000);
LED1=1;
DSP28x_usDelay(100000);
}
}
void Adc_config(){
AdcRegs.ADCTRL3.bit.SMODE_SEL=1; //set to subsequent mode,并发模式
AdcRegs.ADCTRL1.bit.SEQ_CASC=1; //SEQ1 and SEQ2 are devided to two single converter
AdcRegs.ADCMAXCONV.all=0x0007; //8个双重转换(总共16个)
AdcRegs.ADCCHSELSEQ1.bit.CONV00=0x0;//设置转换序列
AdcRegs.ADCCHSELSEQ1.bit.CONV01=0x1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02=0x2;
AdcRegs.ADCCHSELSEQ1.bit.CONV03=0x3;
AdcRegs.ADCCHSELSEQ2.bit.CONV04=0x4;
AdcRegs.ADCCHSELSEQ2.bit.CONV05=0x5;
AdcRegs.ADCCHSELSEQ2.bit.CONV06=0x6;
AdcRegs.ADCCHSELSEQ2.bit.CONV07=0x7;
AdcRegs.ADCTRL2.bit.RST_SEQ1=1; //restore SEQ1
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1=0; //set adc to a mode that after the end of SEQ1, the flag of INT SEQ1 will be set
AdcRegs.ADCTRL1.bit.CONT_RUN=0; //配置ADC工作在启动停止模式
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
//Configure EVA
// Assumes EVA Clock is already enabled in InitSysCtrl();
EvaRegs.T1CMPR = 0x0080; // Setup T1 compare value
EvaRegs.T1PR = 0xFFFF; // Setup period register
EvaRegs.GPTCONA.bit.T1TOADC = 0x2; // Enable EVASOC in EVA
EvaRegs.T1CNT=0x0000;
EvaRegs.T1CON.all = 0x1042; // Enable timer 1 compare (upcount mode)
}
interrupt void ADC_Timer(void){
int i;
LED2= !LED2;
Current_sensor[5]=AdcRegs.ADCRESULT4>>4; //left foot,Use ADCINA
Current_sensor[4]=AdcRegs.ADCRESULT6>>4;
Current_sensor[3]=AdcRegs.ADCRESULT8>>4;
Current_sensor[2]=AdcRegs.ADCRESULT10>>4;
Current_sensor[1]=AdcRegs.ADCRESULT12>>4; //right foot, Use ADCINB
Current_sensor[0]=AdcRegs.ADCRESULT14>>4;
//compute the center of press and Send it to the Linux;
for(i=0;i<=5;i++){
Sensor_V[i]=Current_sensor[i]*3/4095; //maxium 65520
Sensor_C[i]=Sensor_V[i]/0.3;
}
AdcRegs.ADCTRL2.bit.RST_SEQ1=1; //复位SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR=1; //清除INT SEQ1位
//AdcRegs.ADCTRL2.bit.SOC_SEQ1=1; //触发
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -