📄 f280xileg.c
字号:
/* ==================================================================================
File name: F280XILEG.C
Originator: Digital Control Systems Group
Texas Instruments
Description: This file contains source for the F280X Two leg current measurement driver.
Target: TMS320F280x family
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20: Using DSP280x v. 1.10 or higher
------------------------------------------------------------------------------------*/
#include "DSP280x_Device.h"
#include "f280xileg.h"
#define CPU_CLOCK_SPEED 10.000L // for a 100MHz CPU clock speed
#define ADC_usDELAY 10000L
#define DELAY_US(A) DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_CLOCK_SPEED) - 9.0L) / 5.0L)
extern void DSP28x_usDelay(unsigned long Count);
void F280X_ileg2_drv_init(ILEG2MEAS *p)
{
DELAY_US(ADC_usDELAY);
AdcRegs.ADCTRL1.all = ADC_RESET_FLAG; // Reset the ADC Module
asm(" NOP ");
asm(" NOP ");
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3; // Power up bandgap/reference circuitry
DELAY_US(ADC_usDELAY); // Delay before powering up rest of ADC
AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // Power up rest of ADC
DELAY_US(ADC_usDELAY);
AdcRegs.ADCTRL3.bit.ADCCLKPS = 16; // Set up ADCTRL3 register
AdcRegs.ADCTRL1.all = ADCTRL1_INIT_STATE_ILEG2; // Set up ADCTRL1 register
AdcRegs.ADCTRL2.all = ADCTRL2_INIT_STATE_ILEG2; // Set up ADCTRL2 register
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 1; // Specify two conversions
AdcRegs.ADCCHSELSEQ1.all = p->ChSelect; // Configure channel selection
AdcRegs.ADCREFSEL.all = 39; // Set up the ADC reference select register
AdcRegs.ADCOFFTRIM.all = 65534; // Set up the ADC offset trim register
// Set up Event Trigger with CNT_zero enable for Time-base of EPWM1
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOCA
EPwm1Regs.ETSEL.bit.SOCASEL = 1; // Enable CNT_zero event for SOCA
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate SOCA on the 1st event
EPwm1Regs.ETCLR.bit.SOCA = 1; // Clear SOCA flag
}
void F280X_ileg2_drv_read(ILEG2MEAS *p)
{
int16 DatQ15;
int32 Tmp;
// Wait until ADC conversion is completed
while (AdcRegs.ADCST.bit.SEQ1_BSY == 1)
{};
DatQ15 = AdcRegs.ADCRESULT0^0x8000; // Convert raw result to Q15 (bipolar signal)
Tmp = (int32)p->ImeasAGain*(int32)DatQ15; // Tmp = gain*dat => Q28 = Q13*Q15
p->ImeasA = (int16)(Tmp>>13); // Convert Q28 to Q15
p->ImeasA += p->ImeasAOffset; // Add offset
p->ImeasA *= -1; // Positive direction, current flows to motor
DatQ15 = AdcRegs.ADCRESULT1^0x8000; // Convert raw result to Q15 (bipolar signal)
Tmp = (int32)p->ImeasBGain*(int32)DatQ15; // Tmp = gain*dat => Q28 = Q13*Q15
p->ImeasB = (int16)(Tmp>>13); // Convert Q28 to Q15
p->ImeasB += p->ImeasBOffset; // Add offset
p->ImeasB *= -1; // Positive direction, current flows to motor
p->ImeasC = -(p->ImeasA + p->ImeasB); // Compute phase-c current
AdcRegs.ADCTRL2.all |= 0x4040; // Reset the sequence
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -