Рефакторинг обработки сигма-дельта

и три файла для отчёта
This commit is contained in:
Eugene 2023-10-12 17:00:15 +03:00
parent 1ffbe89ef4
commit 1bbaaa7f9a
6 changed files with 126 additions and 368 deletions

View File

@ -21,7 +21,7 @@
#define EPWM_DB (EPWM_DB_mkS*SYS_PWM_FREQUENCY/1000000)
#define SDFM_DELAY_mkS 48.0 //mkS
#define SDFM_DELAY_mkS 72.0 //mkS
#define SDFM_DELAY (SDFM_DELAY_mkS*SYS_PWM_FREQUENCY/1000000)
#define PERIOD_2 (PERIOD_MOTOR/2)

View File

@ -32,37 +32,73 @@
//uint16_t gPWM_number = 1; // ePWM 1 for synchronizing SDFM1 filters
int16_t Filter0_Result[MAX_SAMPLES];
int16_t Filter1_Result[MAX_SAMPLES];
int16_t Filter3_Result[MAX_SAMPLES];
int16_t Filter2_Result[MAX_SAMPLES];
int16_t Filter3_Result[MAX_SAMPLES];
int16_t Filter4_Result[MAX_SAMPLES];
int16_t Filter5_Result[MAX_SAMPLES];
int16_t Filter6_Result[MAX_SAMPLES];
int16_t Filter7_Result[MAX_SAMPLES];
int16_t Filter8_Result[MAX_SAMPLES];
#pragma DATA_SECTION(Filter1_Result,"Filter1_RegsFile");
#pragma DATA_SECTION(Filter2_Result,"Filter2_RegsFile");
#pragma DATA_SECTION(Filter3_Result,"Filter3_RegsFile");
#pragma DATA_SECTION(Filter4_Result,"Filter4_RegsFile");
#pragma DATA_SECTION(Filter5_Result,"Filter1_RegsFile");
#pragma DATA_SECTION(Filter6_Result,"Filter2_RegsFile");
#pragma DATA_SECTION(Filter7_Result,"Filter3_RegsFile");
#pragma DATA_SECTION(Filter8_Result,"Filter4_RegsFile");
#pragma DATA_SECTION(Filter0_Result,"Filter1_RegsFile");
#pragma DATA_SECTION(Filter1_Result,"Filter2_RegsFile");
#pragma DATA_SECTION(Filter2_Result,"Filter3_RegsFile");
#pragma DATA_SECTION(Filter3_Result,"Filter4_RegsFile");
#pragma DATA_SECTION(Filter4_Result,"Filter1_RegsFile");
#pragma DATA_SECTION(Filter5_Result,"Filter2_RegsFile");
#pragma DATA_SECTION(Filter6_Result,"Filter3_RegsFile");
#pragma DATA_SECTION(Filter7_Result,"Filter4_RegsFile");
//union SDCPARM1_REG * SDCPARM_Reg_arr[4] = {&Sdfm1Regs.SDCPARM1, &Sdfm1Regs.SDCPARM2, &Sdfm1Regs.SDCPARM3, &Sdfm1Regs.SDCPARM4};
int16_t * FilterResult[8] = {Filter0_Result, Filter1_Result, Filter2_Result, Filter3_Result, Filter4_Result, Filter5_Result, Filter6_Result, Filter7_Result};
union SDCPARM1_REG * SDCPARM_Reg_arr[8] = {
(union SDCPARM1_REG *)(&Sdfm1Regs.SDCPARM1),
(union SDCPARM1_REG *)(&Sdfm1Regs.SDCPARM2),
(union SDCPARM1_REG *)(&Sdfm1Regs.SDCPARM3),
(union SDCPARM1_REG *)(&Sdfm1Regs.SDCPARM4),
(union SDCPARM1_REG *)(&Sdfm2Regs.SDCPARM1),
(union SDCPARM1_REG *)(&Sdfm2Regs.SDCPARM2),
(union SDCPARM1_REG *)(&Sdfm2Regs.SDCPARM3),
(union SDCPARM1_REG *)(&Sdfm2Regs.SDCPARM4)
};
union SDDFPARM1_REG * SDDFPARM_Reg_arr[8] = {
(union SDDFPARM1_REG *)(&Sdfm1Regs.SDDFPARM1),
(union SDDFPARM1_REG *)(&Sdfm1Regs.SDDFPARM2),
(union SDDFPARM1_REG *)(&Sdfm1Regs.SDDFPARM3),
(union SDDFPARM1_REG *)(&Sdfm1Regs.SDDFPARM4),
(union SDDFPARM1_REG *)(&Sdfm2Regs.SDDFPARM1),
(union SDDFPARM1_REG *)(&Sdfm2Regs.SDDFPARM2),
(union SDDFPARM1_REG *)(&Sdfm2Regs.SDDFPARM3),
(union SDDFPARM1_REG *)(&Sdfm2Regs.SDDFPARM4)
};
volatile int16 * SdfmReadData[8] = {
(volatile int16 *)((Uint16)0x5E17),
(volatile int16 *)((Uint16)0x5E27),
(volatile int16 *)((Uint16)0x5E37),
(volatile int16 *)((Uint16)0x5E47),
(volatile int16 *)((Uint16)0x5E97),
(volatile int16 *)((Uint16)0x5EA7),
(volatile int16 *)((Uint16)0x5EB7),
(volatile int16 *)((Uint16)0x5EC7),
};
#define WAIT_STABILITY_SDFM 6
int16_t sdfmAdc[8] = {0,0,0,0,0,0,0,0};
int16_t sdfmAdcErr[8] = {0,0,0,0,0,0,0,0};
int16_t sdfmOffset[8] = {0,0,0,0,0,0,0,0};
uint16_t startInitCurrent = 0;
uint16_t initDone[8] = {3,3,3,3,3,3,3,3};
uint32_t IntFlags1, IntFlags2;
uint16_t initDone[8] = {WAIT_STABILITY_SDFM,WAIT_STABILITY_SDFM,WAIT_STABILITY_SDFM,WAIT_STABILITY_SDFM,WAIT_STABILITY_SDFM,WAIT_STABILITY_SDFM,WAIT_STABILITY_SDFM,WAIT_STABILITY_SDFM};
uint16_t sdfmIndex = 0;
int16_t Test_I[16];
uint16_t loopCounter[8] = {0,0,0,0,0,0,0,0};
@ -262,180 +298,59 @@ void SdfmInit(void)
Sdfm2Regs.SDDFPARM2.bit.FEN = 1;
Sdfm2Regs.SDDFPARM3.bit.FEN = 1;
Sdfm2Regs.SDDFPARM4.bit.FEN = 1;
EDIS;
}
void sdfmGet(uint16_t N)
{
uint16_t i = 0;
int32_t OffsetCount = 0;
FilterResult[N][loopCounter[N]] = *SdfmReadData[N];
sdfmAdc[N] = FilterResult[N][loopCounter[N]] - sdfmOffset[N];
if(loopCounter[N] < MAX_SAMPLES) loopCounter[N]++;
else
{
loopCounter[N] = 0;
if(!initDone[N])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += FilterResult[N][i];
}
sdfmOffset[N] = OffsetCount>>FILTER_BIT;
initDone[N] = 0xFF;
}
else if(initDone[N] != 0xFF) initDone[N]--;
}
EALLOW;
SDCPARM_Reg_arr[N]->bit.MFIE = 1;
SDDFPARM_Reg_arr[N]->bit.AE = 0;
EDIS;
sdfmAdcErr[0] = 0;
}
void sdfmErr(N)
{
sdfmAdc[N] = 0;
EALLOW;
SDCPARM_Reg_arr[N]->bit.MFIE = 0;
EDIS;
sdfmAdcErr[N] = 1;
}
//
// Sdfm1_ISR - SDFM 1 ISR
//
__interrupt void Sdfm1_ISR(void)
sdfm_check_all_measurements_was_done(void)
{
static uint16_t loopCounter1 = 0;
static uint16_t loopCounter2 = 0;
static uint16_t loopCounter3 = 0;
static uint16_t loopCounter4 = 0;
uint16_t i = 0;
int32_t OffsetCount = 0;
IntFlags1 = Sdfm_readFlagRegister(SDFM1);
sdfmIndex |= (IntFlags1 & 0xF000)>>12;
if (IntFlags1 & 0x1000)
{
Filter1_Result[loopCounter1] = SDFM1_READ_FILTER1_DATA_16BIT;
sdfmAdc[0] = Filter1_Result[loopCounter1] - sdfmOffset[0];
if(loopCounter1 < MAX_SAMPLES) loopCounter1++;
else
{
loopCounter1 = 0;
if(!initDone[0])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter1_Result[i];
}
sdfmOffset[0] = OffsetCount>>FILTER_BIT;
initDone[0] = 0xFF;
}
else if(initDone[0] != 0xFF) initDone[0]--;
}
EALLOW;
Sdfm1Regs.SDCPARM1.bit.MFIE = 1;
Sdfm1Regs.SDDFPARM1.bit.AE = 0;
EDIS;
sdfmAdcErr[0] = 0;
}
if (IntFlags1 & 0x2000)
{
Filter2_Result[loopCounter2] = SDFM1_READ_FILTER2_DATA_16BIT;
sdfmAdc[1] = Filter2_Result[loopCounter2] - sdfmOffset[1];
if(loopCounter2 < MAX_SAMPLES) loopCounter2++;
else
{
loopCounter2 = 0;
if(!initDone[1])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter2_Result[i];
}
sdfmOffset[1] = OffsetCount>>FILTER_BIT;
initDone[1] = 0xFF;
}
else if(initDone[1] != 0xFF) initDone[1]--;
}
EALLOW;
Sdfm1Regs.SDCPARM2.bit.MFIE = 1;
Sdfm1Regs.SDDFPARM2.bit.AE = 0;
EDIS;
sdfmAdcErr[1] = 0;
}
if (IntFlags1 & 0x4000)
{
Filter3_Result[loopCounter3] = SDFM1_READ_FILTER3_DATA_16BIT;
sdfmAdc[2] = Filter3_Result[loopCounter3] - sdfmOffset[2];
if(loopCounter3 < MAX_SAMPLES) loopCounter3++;
else
{
loopCounter3 = 0;
if(!initDone[2])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter3_Result[i];
}
sdfmOffset[2] = OffsetCount>>FILTER_BIT;
initDone[2] = 0xFF;
}
else if(initDone[2] != 0xFF) initDone[2]--;
}
EALLOW;
Sdfm1Regs.SDCPARM3.bit.MFIE = 1;
Sdfm1Regs.SDDFPARM3.bit.AE = 0;
EDIS;
sdfmAdcErr[2] = 0;
}
if (IntFlags1 & 0x8000)
{
Gpio15out(1);
Filter4_Result[loopCounter4] = SDFM1_READ_FILTER4_DATA_16BIT;
sdfmAdc[3] = Filter4_Result[loopCounter4] - sdfmOffset[3];
// Test_I[sdfm_index] = sdfmAdc[3];
// sdfm_index++;
// if(sdfm_index >= 15)
// {
// EALLOW;
// Sdfm1Regs.SDDFPARM4.bit.FEN = 0;
// EDIS;
// }
Gpio15out(0);
if(loopCounter4 < MAX_SAMPLES) loopCounter4++;
else
{
loopCounter4 = 0;
if(!initDone[3])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter4_Result[i];
}
sdfmOffset[3] = OffsetCount>>FILTER_BIT;
initDone[3] = 0xFF;
}
else if(initDone[3] != 0xFF) initDone[3]--;
}
EALLOW;
Sdfm1Regs.SDCPARM4.bit.MFIE = 1;
Sdfm1Regs.SDDFPARM4.bit.AE = 0;
EDIS;
sdfmAdcErr[3] = 0;
}
if(IntFlags1 & 0x100)
{
sdfmAdc[0] = 0;
EALLOW;
Sdfm1Regs.SDCPARM1.bit.MFIE = 0;
EDIS;
sdfmAdcErr[0] = 1;
}
if(IntFlags1 & 0x200)
{
sdfmAdc[1] = 0;
EALLOW;
Sdfm1Regs.SDCPARM2.bit.MFIE = 0;
EDIS;
sdfmAdcErr[1] = 1;
}
if(IntFlags1 & 0x400)
{
sdfmAdc[2] = 0;
EALLOW;
Sdfm1Regs.SDCPARM3.bit.MFIE = 0;
EDIS;
sdfmAdcErr[2] = 1;
}
if(IntFlags1 & 0x800)
{
vectorFault();
sdfmAdc[3] = 0;
EALLOW;
Sdfm1Regs.SDCPARM4.bit.MFIE = 0;
EDIS;
sdfmAdcErr[3] = 1;
}
//
// Clear SDFM flag register
//
Sdfm_clearFlagRegister(SDFM1,IntFlags1);
if((sdfmIndex & 0x58) == 0x58)
{
Gpio54out(1);
@ -443,9 +358,22 @@ __interrupt void Sdfm1_ISR(void)
vectorControl(sdfmAdc[6],sdfmAdc[3],sdfmAdc[4]);
Gpio54out(0);
}
//
// Acknowledge this __interrupt to receive more __interrupts from group 5
//
}
__interrupt void Sdfm1_ISR(void)
{
uint16_t i;
uint32_t IntFlags;
IntFlags = Sdfm_readFlagRegister(SDFM1);
sdfmIndex |= (IntFlags & 0xF000)>>12;
for(i = 0; i < 4; i++) if(IntFlags & (0x1000 << i)) sdfmGet(i);
for(i = 0; i < 4; i++) if(IntFlags & (0x100 << i)) sdfmErr(i);
Sdfm_clearFlagRegister(SDFM1,IntFlags);
sdfm_check_all_measurements_was_done();
PieCtrlRegs.PIEACK.all = PIEACK_GROUP5;
}
@ -453,191 +381,18 @@ __interrupt void Sdfm1_ISR(void)
//
__interrupt void Sdfm2_ISR(void)
{
static uint16_t loopCounter5 = 0;
static uint16_t loopCounter6 = 0;
static uint16_t loopCounter7 = 0;
static uint16_t loopCounter8 = 0;
uint16_t i = 0;
int32_t OffsetCount = 0;
uint16_t i;
uint32_t IntFlags;
//
// Wait for result from all the filters (SDIFLG)
//
IntFlags = Sdfm_readFlagRegister(SDFM2);
sdfmIndex |= (IntFlags & 0xF000)>>8;
IntFlags2 = Sdfm_readFlagRegister(SDFM2);
sdfmIndex |= (IntFlags2&0xF000)>>8;
// while((Sdfm_readFlagRegister(gPeripheralNumber) &
// SDFM_INT_MASK) != SDFM_INT_MASK);
for(i = 0; i < 4; i++) if(IntFlags & (0x1000 << i)) sdfmGet(i+4);
for(i = 0; i < 4; i++) if(IntFlags & (0x100 << i)) sdfmErr(i+4);
if (IntFlags2 & 0x1000)
{
Gpio56out(1);
Filter5_Result[loopCounter5] = SDFM2_READ_FILTER1_DATA_16BIT;
sdfmAdc[4] = Filter5_Result[loopCounter5] - sdfmOffset[4];
Gpio56out(0);
if(loopCounter5 < MAX_SAMPLES) loopCounter5++;
else
{
loopCounter5 = 0;
if(!initDone[4])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter5_Result[i];
}
sdfmOffset[4] = OffsetCount>>FILTER_BIT;
initDone[4] = 0xFF;
}
else if(initDone[4] != 0xFF) initDone[4]--;
}
EALLOW;
Sdfm2Regs.SDCPARM1.bit.MFIE = 1;
Sdfm2Regs.SDDFPARM1.bit.AE = 0;
EDIS;
sdfmAdcErr[4] = 0;
}
if (IntFlags2 & 0x2000)
{
Filter6_Result[loopCounter6] = SDFM2_READ_FILTER2_DATA_16BIT;
sdfmAdc[5] = Filter6_Result[loopCounter6] - sdfmOffset[5];
if(loopCounter6 < MAX_SAMPLES) loopCounter6++;
else
{
loopCounter6 = 0;
if(!initDone[5])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter6_Result[i];
}
sdfmOffset[5] = OffsetCount>>FILTER_BIT;
initDone[5] = 0xFF;
}
else if(initDone[5] != 0xFF) initDone[5]--;
}
EALLOW;
Sdfm2Regs.SDCPARM2.bit.MFIE = 1;
Sdfm2Regs.SDDFPARM2.bit.AE = 0;
EDIS;
sdfmAdcErr[5] = 0;
}
if (IntFlags2 & 0x4000)
{
Gpio57out(1);
Filter7_Result[loopCounter7] = SDFM2_READ_FILTER3_DATA_16BIT;
sdfmAdc[6] = Filter7_Result[loopCounter7] - sdfmOffset[6];
Gpio57out(0);
if(loopCounter7 < MAX_SAMPLES) loopCounter7++;
else
{
loopCounter7 = 0;
if(!initDone[6])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter7_Result[i];
}
sdfmOffset[6] = OffsetCount>>FILTER_BIT;
initDone[6] = 0xFF;
}
else if(initDone[6] != 0xFF) initDone[6]--;
}
EALLOW;
Sdfm2Regs.SDCPARM3.bit.MFIE = 1;
Sdfm2Regs.SDDFPARM3.bit.AE = 0;
EDIS;
sdfmAdcErr[6] = 0;
}
if (IntFlags2 & 0x8000)
{
Filter8_Result[loopCounter8] = SDFM2_READ_FILTER4_DATA_16BIT;
sdfmAdc[7] = Filter8_Result[loopCounter8] - sdfmOffset[7];
if(loopCounter8 < MAX_SAMPLES) loopCounter8++;
else
{
loopCounter8 = 0;
if(!initDone[7])
{
for(i = 0; i <= (MAX_SAMPLES-1); i++)
{
OffsetCount += Filter8_Result[i];
}
sdfmOffset[7] = OffsetCount>>FILTER_BIT;
initDone[7] = 0xFF;
}
else if(initDone[7] != 0xFF) initDone[7]--;
}
EALLOW;
Sdfm2Regs.SDCPARM4.bit.MFIE = 1;
Sdfm2Regs.SDDFPARM4.bit.AE = 0;
EDIS;
sdfmAdcErr[7] = 0;
}
if(IntFlags2 & 0x100)
{
vectorFault();
sdfmAdc[4] = 0;
EALLOW;
Sdfm2Regs.SDCPARM1.bit.MFIE = 0;
EDIS;
sdfmAdcErr[4] = 1;
}
if(IntFlags2 & 0x200)
{
sdfmAdc[5] = 0;
EALLOW;
Sdfm2Regs.SDCPARM2.bit.MFIE = 0;
EDIS;
sdfmAdcErr[5] = 1;
}
if(IntFlags2 & 0x400)
{
vectorFault();
sdfmAdc[6] = 0;
EALLOW;
Sdfm2Regs.SDCPARM3.bit.MFIE = 0;
EDIS;
sdfmAdcErr[6] = 1;
}
if(IntFlags2 & 0x800)
{
sdfmAdc[7] = 0;
EALLOW;
Sdfm2Regs.SDCPARM4.bit.MFIE = 0;
EDIS;
sdfmAdcErr[7] = 1;
}
//
// Clear SDFM flag register
//
Sdfm_clearFlagRegister(SDFM2,IntFlags2);
if((sdfmIndex & 0x58) == 0x58)
{
Gpio54out(1);
sdfmIndex = 0;
vectorControl(sdfmAdc[6],sdfmAdc[3],sdfmAdc[4]);
Gpio54out(0);
}
// sdfmIndex &= 0xF;
//
// Acknowledge this __interrupt to receive more __interrupts from group 5
//
Sdfm_clearFlagRegister(SDFM2,IntFlags);
sdfm_check_all_measurements_was_done();
PieCtrlRegs.PIEACK.all = PIEACK_GROUP5;
}
void sdfm_clr_index(void)
@ -650,7 +405,4 @@ int16_t sdfm_get(int16_t N)
return sdfmAdc[N];
}
//Sdfm_clearFlagRegister
//Sdfm_readFlagRegister

View File

@ -79,7 +79,7 @@ void InitPerif(void)
FRMUartInit();
GD25Q16ETIGR_en();
vectorInitCurrLoop();
// Bl25cm1a_en();
vectorInitCurrLoop();
}

BIN
SigmaDelta.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

6
SigmaDelta.txt Normal file
View File

@ -0,0 +1,6 @@
В документе "TMS320F2838x Real-Time Microcontrollers With Connectivity Manager Technical Reference Manual" раздел "28.7 Data (Primary) Filter Unit" содержит таблицу "Table 28-3. Peak Data Values for Different DOSR/Filter Combinations", заполненную по формулам из раздела "28.6 Sinc Filter", где указано время преобразования и разрядность SDFM-модуля в зависимости от параметров настройки.
Для измерения токов в фазах двигателя был выбран фильтр третьего порядка и количество тактов выборки = 32, что обеспечивает время преобразования 9,6 мкС, что является удовлетворительным значением для векторного управления при частоте ШИМ 10 КГц.
Фактически, согласно данным полученным с логического анализатора, между запуском преобразований (по таймеру, синхронизированному с ШИМ) и началом рассчёта веткорного управления проходит не более 8 мкС, сам рассчёт векторного управления производится не более 15 мкС, что даёт возможность рассчитать оптимальное время запуска преобразований, чтобы обновление значений ШИМ происходило сразу по завершении рассчёта.

BIN
SigmaDelta.xlsx Normal file

Binary file not shown.