diff --git a/EFC_PlatformC28x/VoltageMonitoring/CLAInit.hpp b/EFC_PlatformC28x/VoltageMonitoring/CLAInit.hpp new file mode 100644 index 0000000..d80a7ff --- /dev/null +++ b/EFC_PlatformC28x/VoltageMonitoring/CLAInit.hpp @@ -0,0 +1,85 @@ +/* + * CLAInit.hpp + * + * Created on: 3 сент. 2024 г. + * Author: sedov + */ + +#ifndef VOLTAGEMONITORING_CLAINIT_HPP_ +#define VOLTAGEMONITORING_CLAINIT_HPP_ + +#include "f2838x_device.h" +#include "cla_shared.h" +#include "f2838x_examples.h" +#include "f28x_project.h" +#include + + +#define MAX_SIZE 50 +#define SDFM_VOLTAGE_MAX 320.0 //mV +#define R_DRW 4.0 //mOM +#define BIT_MAX 32768//4096 +#define FACTOR_CURRENT_MOTOR_A (SDFM_VOLTAGE_MAX/R_DRW) +#define FACTOR_CURRENT_MOTOR (FACTOR_CURRENT_MOTOR_A/BIT_MAX) +namespace umlib { namespace imp { +class CLAInit { +public: + CLAInit(const CLAInit &) = delete; + CLAInit & operator=(const CLAInit &) = delete; + CLAInit & operator=(const CLAInit &) volatile = delete; + bool initCLA(); + bool CLA_runTest(); + void clear() volatile; + void clear(); + ~CLAInit(); + void configClaMemory(); + void initCpu1Cla1(); +private: + + +#ifdef __cplusplus + // Переменные класса (при необходимости) +#pragma DATA_SECTION("CpuToCla1MsgRAM"); + float CurrentA; // Ток в фазе A +#pragma DATA_SECTION("CpuToCla1MsgRAM"); + float CurrentB; // Ток в фазе B +#pragma DATA_SECTION("CpuToCla1MsgRAM"); + float CurrentC; // Ток в фазе C +#pragma DATA_SECTION("CpuToCla1MsgRAM"); + float currentCoefK; // Коэффициент преобразования +#pragma DATA_SECTION("CpuToCla1MsgRAM"); + float currentCoefB; // Коэффициент сдвига +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + float dataList[MAX_SIZE]; // Коэффициент сдвига +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + int dataSize; // Коэффициент сдвига + +// Переменные, которые будут переданы от CLA к CPU +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + volatile float currentIa; // Ток в фазе A +#pragma DATA_SECTION( "Cla1ToCpuMsgRAM"); + volatile float currentIb; // Ток в фазе B +#pragma DATA_SECTION( "Cla1ToCpuMsgRAM"); + volatile float currentIc; // Ток в фазе C +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + volatile float currentAlpha; // Ток в оси альфа +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + volatile float currentBeta; // Ток в оси бета +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + volatile float currentOffset; // Смещение нуля тока +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + volatile float currentRms; // Среднеквадратичное значение тока +#pragma DATA_SECTION( "Cla1ToCpuMsgRAM"); + volatile float currentLength; // Амплитудное значение тока +#pragma DATA_SECTION("Cla1ToCpuMsgRAM"); + volatile float currentSqrlen; // Квадрат амплитудного значения тока +#endif //__cplusplus +uint16_t pass=0; +uint16_t fail=0; + + +}; +}} + + +#endif /* VOLTAGEMONITORING_CLAINIT_HPP_ */ diff --git a/EFC_PlatformC28x/VoltageMonitoring/CLAinit.cpp b/EFC_PlatformC28x/VoltageMonitoring/CLAinit.cpp new file mode 100644 index 0000000..1a9e5c6 --- /dev/null +++ b/EFC_PlatformC28x/VoltageMonitoring/CLAinit.cpp @@ -0,0 +1,130 @@ +/* + * CLAinut.cpp + * + * Created on: 3 сент. 2024 г. + * Author: sedov + */ +#include "CLAinit.hpp" + + + bool umlib::imp::CLAInit::CLA_runTest(){ + int16_t i; + float error; + int pass = 0, fail = 0; + + for (i = 1; i < BUFFER_SIZE; i++) { + // Передаем входные значения от CPU к CLA + CurrentA =i; + CurrentB = i+1; + CurrentC = i-1; + currentCoefK = FACTOR_CURRENT_MOTOR; + currentCoefB=0; + Cla1ForceTask1andWait(); + } + } + + + void umlib::imp::CLAInit::configClaMemory() + { + extern uint32_t Cla1funcsRunStart, Cla1funcsLoadStart, Cla1funcsLoadSize; + EALLOW; + + #ifdef _FLASH + // + // Copy over code from FLASH to RAM + // + memcpy((uint32_t *)&Cla1funcsRunStart, (uint32_t *)&Cla1funcsLoadStart, + (uint32_t)&Cla1funcsLoadSize); + #endif //_FLASH + + // + // Initialize and wait for CLA1ToCPUMsgRAM + // + MemCfgRegs.MSGxINIT.bit.INIT_CLA1TOCPU = 1; + while(MemCfgRegs.MSGxINITDONE.bit.INITDONE_CLA1TOCPU != 1){}; + + // + // Initialize and wait for CPUToCLA1MsgRAM + // + MemCfgRegs.MSGxINIT.bit.INIT_CPUTOCLA1 = 1; + while(MemCfgRegs.MSGxINITDONE.bit.INITDONE_CPUTOCLA1 != 1){}; + + // + // Select LS5RAM to be the programming space for the CLA + // First configure the CLA to be the master for LS5 and then + // set the space to be a program block + // + MemCfgRegs.LSxMSEL.bit.MSEL_LS7 = 1; + MemCfgRegs.LSxCLAPGM.bit.CLAPGM_LS7 = 1; + + // + // Next configure LS0RAM and LS1RAM as data spaces for the CLA + // First configure the CLA to be the master for LS0(1) and then + // set the spaces to be code blocks + // + MemCfgRegs.LSxMSEL.bit.MSEL_LS0 = 1; + MemCfgRegs.LSxCLAPGM.bit.CLAPGM_LS0 = 0; + + MemCfgRegs.LSxMSEL.bit.MSEL_LS1 = 1; + MemCfgRegs.LSxCLAPGM.bit.CLAPGM_LS1 = 0; + + EDIS; + } + + + void umlib::imp::CLAInit::initCpu1Cla1() + { + // + // Suppressing #770-D conversion from pointer to smaller integer + // The CLA address range is 16 bits so the addresses passed to the MVECT + // registers will be in the lower 64KW address space. Turn the warning + // back on after the MVECTs are assigned addresses + // + #pragma diag_suppress=770 + EALLOW; + Cla1Regs.MVECT1 = (uint16_t)(&Cla1Task1); + Cla1Regs.MVECT2 = (uint16_t)(&Cla1Task2); + Cla1Regs.MVECT3 = (uint16_t)(&Cla1Task3); + Cla1Regs.MVECT4 = (uint16_t)(&Cla1Task4); + Cla1Regs.MVECT5 = (uint16_t)(&Cla1Task5); + Cla1Regs.MVECT6 = (uint16_t)(&Cla1Task6); + Cla1Regs.MVECT7 = (uint16_t)(&Cla1Task7); + Cla1Regs.MVECT8 = (uint16_t)(&Cla1Task8); + #pragma diag_warning=770 + + // + // Enable the IACK instruction to start a task on CLA in software + // for all 8 CLA tasks. Also, globally enable all 8 tasks (or a + // subset of tasks) by writing to their respective bits in the + // MIER register + // + Cla1Regs.MCTL.bit.IACKE = 1; + Cla1Regs.MIER.all = 0x00FF; + + // + // Configure the vectors for the end-of-task interrupt for all + // 8 tasks + // + PieVectTable.CLA1_1_INT = &cla1Isr1; + PieVectTable.CLA1_2_INT = &cla1Isr2; + PieVectTable.CLA1_3_INT = &cla1Isr3; + PieVectTable.CLA1_4_INT = &cla1Isr4; + PieVectTable.CLA1_5_INT = &cla1Isr5; + PieVectTable.CLA1_6_INT = &cla1Isr6; + PieVectTable.CLA1_7_INT = &cla1Isr7; + PieVectTable.CLA1_8_INT = &cla1Isr8; + + + + /// Enable CLA Task1 to SDFM1 Iterput + DmaClaSrcSelRegs.CLA1TASKSRCSEL1.bit.TASK1 = 95U; + // + // Enable CLA interrupts at the group and subgroup levels + // + PieCtrlRegs.PIEIER11.all = 0xFFFF; + IER |= (M_INT11 ); + } + bool umlib::imp::CLAInit::initCLA(){ + configClaMemory(); + initCpu1Cla1(); + } diff --git a/EFC_PlatformC28x/VoltageMonitoring/cla.cla b/EFC_PlatformC28x/VoltageMonitoring/cla.cla new file mode 100644 index 0000000..4671fc3 --- /dev/null +++ b/EFC_PlatformC28x/VoltageMonitoring/cla.cla @@ -0,0 +1,162 @@ +//############################################################################# +// \file cla_ex1_asin_cla.cla +// +// \brief SDFM Example +// +//############################################################################# + + +// +// Included Files +// +#include "cla_shared.h" +#include "f28x_project.h" + +// +// Defines +// + +// +// Globals +// + + +#define MAX_SIZE 50 +#define SDFM_VOLTAGE_MAX 320.0 //mV +#define R_BRAKE 220.0 //mOM +#define R_DRW 4.0 //mOM +#define R_VDC 806.0 //Om +#define R_DEL_VDC 2000000.0 //Om + +#define BIT_MAX 32768//4096 +#define IMAX_A 25.0 //A +#define IMAX (IMAX_A*BIT_MAX/FACTOR_CURRENT_MOTOR_A) + +#define FACTOR_VDC (SDFM_VOLTAGE_MAX/R_VDC*(R_DEL_VDC+R_VDC)/1000) + +#define FACTOR_CURRENT_BRAKE_A (SDFM_VOLTAGE_MAX/R_BRAKE) //A +#define FACTOR_CURRENT_MOTOR_A (SDFM_VOLTAGE_MAX/R_DRW) //A + +#define FACTOR_CURRENT_BRAKE (FACTOR_CURRENT_BRAKE_A/BIT_MAX) +#define FACTOR_CURRENT_MOTOR (FACTOR_CURRENT_MOTOR_A/BIT_MAX) + + + +float mySqrt(float number) { + if (number < 0) { + + return -1.0f; + } + + if (number == 0) { + return 0; + } + + float guess = number / 2.0f; + float epsilon = 0.00001f; + + while (fabs(guess * guess - number) >= epsilon) { + guess = (guess + number / guess) / 2.0f; + } + + return guess; +} + +void addToList(float value) { + int i; + if (dataSize < MAX_SIZE) { + dataList[dataSize++] = value; + } else { + for ( i = 1; i < MAX_SIZE; ++i) { + dataList[i - 1] = dataList[i]; + } + dataList[MAX_SIZE - 1] = value; + } +} + +float sumList() { + int i; + float total = 0.0f; + for ( i = 0; i < dataSize; ++i) { + total += dataList[i]; + } + return total; +} + +int getListSize() { + return dataSize; +} + +void convertCurrentToAmps(float currentCode, float offset, float factor, float* current) { + *current = (currentCode * factor) + offset; +} + +void calculateMainParameters(float currentA, float currentB, float currentC, + float* currentAlpha, float* currentBeta, float* currentOffset) { + *currentAlpha = currentA; + *currentBeta = (currentA + 2 * currentB) * 0.577350269f; + *currentOffset = currentA + currentB + currentC; +} + +void calculateStatisticalParameters(float a, float b, + float* currentRms, float* currentLength, float* currentSqrlen) { + *currentSqrlen = (a * a + b * b); + addToList(*currentSqrlen); + addToList( *currentSqrlen); + *currentRms = mySqrt(sumList() / getListSize()); + *currentLength = mySqrt(a * a + b * b); + +} +__interrupt void Cla1Task1 ( void ) +{ + + + convertCurrentToAmps(CurrentA, currentCoefB, currentCoefK, ¤tIa); + convertCurrentToAmps(CurrentB, currentCoefB, currentCoefK, ¤tIb); + convertCurrentToAmps(CurrentC, currentCoefB, currentCoefK, ¤tIc); + + calculateMainParameters(currentIa, currentIb, currentIc, ¤tAlpha, ¤tBeta, ¤tOffset); + + calculateStatisticalParameters(currentAlpha, currentBeta, ¤tRms, ¤tLength, ¤tSqrlen); + + addToList(currentLength * currentLength); +} + +interrupt void Cla1Task2 ( void ) +{ + +} + +interrupt void Cla1Task3 ( void ) +{ + +} + +interrupt void Cla1Task4 ( void ) +{ + +} + +interrupt void Cla1Task5 ( void ) +{ + +} + +interrupt void Cla1Task6 ( void ) +{ + +} + +interrupt void Cla1Task7 ( void ) +{ + +} + +interrupt void Cla1Task8 ( void ) +{ + +} + +// +// End of file +// diff --git a/EFC_PlatformC28x/VoltageMonitoring/cla_shared.h b/EFC_PlatformC28x/VoltageMonitoring/cla_shared.h new file mode 100644 index 0000000..7839710 --- /dev/null +++ b/EFC_PlatformC28x/VoltageMonitoring/cla_shared.h @@ -0,0 +1,165 @@ +#ifndef _CLA_ASIN_SHARED_H_ +#define _CLA_ASIN_SHARED_H_ +//############################################################################# +// +// FILE: cla_shared.h +// +// TITLE: CLA arcsine example header file. +// +// +// Included Files +// + +#include "f28x_project.h" + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +// +// Defines +// +#define BUFFER_SIZE 64 +#define TABLE_SIZE 64 +#define TABLE_SIZE_M_1 TABLE_SIZE-1 +#define PIBYTWO 1.570796327 +#define PI 3.141592653589 +#define INV2PI 0.159154943 + + + +// +// Globals +// +// +//Task 1 (C) Variables +// +#define MAX_SIZE 50 +extern float dataList[MAX_SIZE]; +extern float CurrentA; +extern float CurrentB; +extern float CurrentC; +extern float currentCoefK; +extern float currentCoefB; +extern int dataSize; +// ����������� ������� ���������� �� CLA +extern volatile float currentIa; // ��� � ���� A +extern volatile float currentIb; // ��� � ���� B +extern volatile float currentIc; // ��� � ���� C + +extern volatile float currentAlpha; // ��� � ��� ����� +extern volatile float currentBeta; // ��� � ��� ���� +extern volatile float currentOffset; // �������� ���� ���� +extern volatile float currentRms; // ������������������ �������� ���� +extern volatile float currentLength; // ����������� �������� ���� + extern volatile float currentSqrlen; // ������� ������������ �������� ���� + + // + // cla1Isr1 - CLA1 ISR 1 + // + __interrupt void cla1Isr1 () + { + // + // Acknowledge the end-of-task interrupt for task 1 + // + PieCtrlRegs.PIEACK.all = M_INT11; + + // + // Uncomment to halt debugger and stop here + // + // asm(" ESTOP0"); + } + + // + // cla1Isr2 - CLA1 ISR 2 + // + __interrupt void cla1Isr2 () + { + asm(" ESTOP0"); + } + + // + // cla1Isr3 - CLA1 ISR 3 + // + __interrupt void cla1Isr3 () + { + asm(" ESTOP0"); + } + + // + // cla1Isr4 - CLA1 ISR 4 + // + __interrupt void cla1Isr4 () + { + asm(" ESTOP0"); + } + + // + // cla1Isr5 - CLA1 ISR 5 + // + __interrupt void cla1Isr5 () + { + asm(" ESTOP0"); + } + + // + // cla1Isr6 - CLA1 ISR 6 + // + __interrupt void cla1Isr6 () + { + asm(" ESTOP0"); + } + + // + // cla1Isr7 - CLA1 ISR 7 + // + __interrupt void cla1Isr7 () + { + asm(" ESTOP0"); + } + + // + // cla1Isr8 - CLA1 ISR 8 + // + __interrupt void cla1Isr8 () + { + // + // Acknowledge the end-of-task interrupt for task 8 + // + PieCtrlRegs.PIEACK.all = M_INT11; + + // + // Uncomment to halt debugger and stop here + // + // asm(" ESTOP0"); + } +// + +// +// Function Prototypes +// +// The following are symbols defined in the CLA assembly code +// Including them in the shared header file makes them +// .global and the main CPU can make use of them. +// +__interrupt void Cla1Task1(); +__interrupt void Cla1Task2(); +__interrupt void Cla1Task3(); +__interrupt void Cla1Task4(); +__interrupt void Cla1Task5(); +__interrupt void Cla1Task6(); +__interrupt void Cla1Task7(); +__interrupt void Cla1Task8(); + +#ifdef __cplusplus +} +#endif // extern "C" + +#endif //end of _CLA_ASIN_SHARED_H_ definition + +// +// End of file +//