370 lines
9.6 KiB
C
370 lines
9.6 KiB
C
|
||
#include <281xEvTimersInit.h>
|
||
#include <project_setup.h>
|
||
#include <PWMTMSHandle.h>
|
||
|
||
#include "DSP281x_Device.h"
|
||
#include "MemoryFunctions.h"
|
||
#include "Spartan2E_Adr.h"
|
||
#include "x_wdog.h"
|
||
#include "project.h"
|
||
|
||
#pragma CODE_SECTION(pause_10,".fast_run");
|
||
void pause_10(unsigned long t)
|
||
{
|
||
unsigned long i;
|
||
|
||
for (i = 0; i < t; i++)
|
||
{
|
||
asm(" NOP");
|
||
}
|
||
}
|
||
|
||
|
||
void test_impulse(unsigned int impulse_channel,long impulse_time)
|
||
{
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel);
|
||
pause_10(impulse_time);
|
||
i_WriteMemory(ADR_PWM_DIRECT,0xffff);
|
||
}
|
||
|
||
#pragma CODE_SECTION(test_double_impulse,".fast_run");
|
||
void test_double_impulse(unsigned int impulse_channel_1,unsigned int impulse_channel_2,long impulse_time,long middle_impulse_time,long last_impulse_time, int soft_off_enable, int soft_on_enable)
|
||
{
|
||
project.disable_all_interrupt();
|
||
// i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2);
|
||
// pause_10(middle_impulse_time);
|
||
|
||
if (soft_on_enable)
|
||
{
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2);
|
||
pause_10(last_impulse_time);
|
||
}
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_1);
|
||
// pause_10(impulse_time);
|
||
pause_10(impulse_time);
|
||
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2);
|
||
pause_10(middle_impulse_time);
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT, impulse_channel_1);
|
||
pause_10(last_impulse_time);
|
||
|
||
if (soft_off_enable)
|
||
{
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2);
|
||
pause_10(last_impulse_time);
|
||
}
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT,0xffff);
|
||
|
||
project.enable_all_interrupt();
|
||
}
|
||
|
||
void test_sin_impulse(unsigned int impulse_channel_1,unsigned int impulse_channel_2, unsigned int impulse_channel_3, long impulse_time,long middle_impulse_time)
|
||
{
|
||
project.disable_all_interrupt();
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2);
|
||
pause_10(middle_impulse_time);
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_1);
|
||
pause_10(impulse_time);
|
||
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_2);
|
||
pause_10(middle_impulse_time);
|
||
|
||
i_WriteMemory(ADR_PWM_DIRECT,impulse_channel_3);
|
||
pause_10(impulse_time);
|
||
i_WriteMemory(ADR_PWM_DIRECT,0xffff);
|
||
|
||
project.enable_all_interrupt();
|
||
}
|
||
|
||
|
||
void test_tk_ak_one_impulse(int tk0, int tk1, int tk2, int tk3, int period, int periodMiddle, int periodLast, int doubleImpulse, int sinImpulse, int soft_off_enable, int soft_on_enable)
|
||
{
|
||
long p2 = 0, pM = 0, pL = 0;
|
||
float pf;
|
||
unsigned int tk0_0 = 0, tk0_1 = 0, tk0_2 = 0, tk0_3 = 0, tk0_4 = 0, tk0_5 = 0, tk0_6 = 0, tk0_7 = 0;
|
||
unsigned int tk1_0 = 0, tk1_1 = 0, tk1_2 = 0, tk1_3 = 0, tk1_4 = 0, tk1_5 = 0, tk1_6 = 0, tk1_7 = 0;
|
||
unsigned int tk2_0 = 0, tk2_1 = 0, tk2_2 = 0, tk2_3 = 0, tk2_4 = 0, tk2_5 = 0, tk2_6 = 0, tk2_7 = 0;
|
||
unsigned int tk3_0 = 0, tk3_1 = 0, tk3_2 = 0, tk3_3 = 0, tk3_4 = 0, tk3_5 = 0, tk3_6 = 0, tk3_7 = 0;
|
||
unsigned int break1 = 0, break2 = 0, break3 = 0, break4 = 0,key0 = 0, key1 = 0, key2 = 0, key3 = 0, key4 = 0, key5 = 0, key6 = 0, key7 = 0, key8 = 0,key9 = 0,key10 = 0,key11 = 0;
|
||
unsigned int Dkey0 = 0xffff, Dkey1 = 0xffff, Dkey2 = 0xffff;
|
||
unsigned int currentPWMMode1, currentPWMMode0, currPWMPeriod;
|
||
|
||
|
||
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //////////
|
||
#if (XPWMGEN==1)
|
||
i_WriteMemory(ADR_PWM_DRIVE_MODE, 3);
|
||
// pause_1000(100000L);
|
||
i_WriteMemory(ADR_PWM_DIRECT,0xffff);
|
||
i_WriteMemory(ADR_TK_MASK_0, 0);
|
||
|
||
#endif
|
||
stop_eva_timer2();
|
||
IER &= ~M_INT9; //stop CAN
|
||
////////////////////////////////////
|
||
|
||
if (period<=1)
|
||
period=1;
|
||
if (period>=1000)
|
||
period=1000;
|
||
pf = (float)(period) *11.724;/// 2.8328173374613003095975232198142;//(periodMiddle)*12;
|
||
p2 = pf;
|
||
// p2=(period) * 19 / 10;//(period)*12;
|
||
|
||
if (periodMiddle<=1)
|
||
periodMiddle=1;
|
||
if (periodMiddle>=1000)
|
||
periodMiddle=1000;
|
||
// pM=(periodMiddle) * 19 / 10;//(periodMiddle)*12;
|
||
pf = (float)(periodMiddle)*11.724;// / 2.8328173374613003095975232198142;//(periodMiddle)*12;
|
||
pM = pf;
|
||
|
||
if (periodLast<=1)
|
||
periodLast=1;
|
||
if (periodLast>=1000)
|
||
periodLast=1000;
|
||
// pM=(periodMiddle) * 19 / 10;//(periodMiddle)*12;
|
||
pf = (float)(periodLast)*11.724;// / 2.8328173374613003095975232198142;//(periodMiddle)*12;
|
||
pL = pf;
|
||
|
||
|
||
|
||
tk0_0 = (tk0 >> 0) & 0x1;
|
||
tk0_1 = (tk0 >> 1) & 0x1;
|
||
tk0_2 = (tk0 >> 2) & 0x1;
|
||
tk0_3 = (tk0 >> 3) & 0x1;
|
||
tk0_4 = (tk0 >> 4) & 0x1;
|
||
tk0_5 = (tk0 >> 5) & 0x1;
|
||
tk0_6 = (tk0 >> 6) & 0x1;
|
||
tk0_7 = (tk0 >> 7) & 0x1;
|
||
|
||
tk1_0 = (tk1 >> 0) & 0x1;
|
||
tk1_1 = (tk1 >> 1) & 0x1;
|
||
tk1_2 = (tk1 >> 2) & 0x1;
|
||
tk1_3 = (tk1 >> 3) & 0x1;
|
||
tk1_4 = (tk1 >> 4) & 0x1;
|
||
tk1_5 = (tk1 >> 5) & 0x1;
|
||
tk1_6 = (tk1 >> 6) & 0x1;
|
||
tk1_7 = (tk1 >> 7) & 0x1;
|
||
|
||
tk2_0 = (tk2 >> 0) & 0x1;
|
||
tk2_1 = (tk2 >> 1) & 0x1;
|
||
tk2_2 = (tk2 >> 2) & 0x1;
|
||
tk2_3 = (tk2 >> 3) & 0x1;
|
||
tk2_4 = (tk2 >> 4) & 0x1;
|
||
tk2_5 = (tk2 >> 5) & 0x1;
|
||
tk2_6 = (tk2 >> 6) & 0x1;
|
||
tk2_7 = (tk2 >> 7) & 0x1;
|
||
|
||
tk3_0 = (tk3 >> 0) & 0x1;
|
||
tk3_1 = (tk3 >> 1) & 0x1;
|
||
tk3_2 = (tk3 >> 2) & 0x1;
|
||
tk3_3 = (tk3 >> 3) & 0x1;
|
||
tk3_4 = (tk3 >> 4) & 0x1;
|
||
tk3_5 = (tk3 >> 5) & 0x1;
|
||
tk3_6 = (tk3 >> 6) & 0x1;
|
||
tk3_7 = (tk3 >> 7) & 0x1;
|
||
|
||
if(doubleImpulse)
|
||
{
|
||
if(tk0_0 && tk0_7){
|
||
Dkey0 = 0xfff6;
|
||
Dkey1 = 0xfff0;
|
||
}
|
||
else if(tk0_4 && tk0_3){
|
||
Dkey0 = 0xfff9;
|
||
Dkey1 = 0xfff0;
|
||
}
|
||
else if(tk1_3 && tk0_0){
|
||
Dkey0 = 0xffde;
|
||
Dkey1 = 0xffcc;
|
||
}
|
||
else if(tk1_0 && tk0_3){
|
||
Dkey0 = 0xffed;
|
||
Dkey1 = 0xffcc;
|
||
}
|
||
else if(tk0_4 && tk1_3){
|
||
Dkey0 = 0xffdb;
|
||
Dkey1 = 0xffc3;
|
||
}
|
||
else if(tk0_7 && tk1_0){
|
||
Dkey0 = 0xffe7;
|
||
Dkey1 = 0xffc3;
|
||
}/////
|
||
else if(tk1_4 && tk2_3){
|
||
Dkey0 = 0xFDBF;
|
||
Dkey1 = 0xFC3F;
|
||
}
|
||
else if(tk1_7 && tk2_0){
|
||
Dkey0 = 0xFE7F;
|
||
Dkey1 = 0xFC3F;
|
||
}
|
||
else if(tk1_4 && tk2_7){
|
||
Dkey0 = 0xF7BF;
|
||
Dkey1 = 0xF33F;
|
||
}
|
||
else if(tk1_7 && tk2_4){
|
||
Dkey0 = 0xFB7F;
|
||
Dkey1 = 0xF33F;
|
||
}
|
||
else if(tk2_0 && tk2_7){
|
||
Dkey0 = 0xF6FF;
|
||
Dkey1 = 0xF0FF;
|
||
}
|
||
else if(tk2_3 && tk2_4){
|
||
Dkey0 = 0xF9FF;
|
||
Dkey1 = 0xF0FF;
|
||
}
|
||
else if (tk0_0){
|
||
Dkey0 = 0xfffe;
|
||
Dkey1 = 0xfffc;
|
||
}
|
||
else if (tk0_3){
|
||
Dkey0 = 0xfffd;
|
||
Dkey1 = 0xfffc;
|
||
}
|
||
else if (tk0_4){
|
||
Dkey0 = 0xfffb;
|
||
Dkey1 = 0xfff3;
|
||
}
|
||
else if (tk0_7){
|
||
Dkey0 = 0xfff7;
|
||
Dkey1 = 0xfff3;
|
||
}
|
||
else if (tk1_0){
|
||
Dkey0 = 0xffef;
|
||
Dkey1 = 0xffcf;
|
||
}
|
||
else if (tk1_3){
|
||
Dkey0 = 0xffdf;
|
||
Dkey1 = 0xffcf;
|
||
}
|
||
else if (tk1_4){
|
||
Dkey0 = 0xffbf;
|
||
Dkey1 = 0xff3f;
|
||
}
|
||
else if (tk1_7){
|
||
Dkey0 = 0xff7f;
|
||
Dkey1 = 0xff3f;
|
||
}
|
||
else if (tk2_0){
|
||
Dkey0 = 0xfeff;
|
||
Dkey1 = 0xfcff;
|
||
}
|
||
else if (tk2_3){
|
||
Dkey0 = 0xfdff;
|
||
Dkey1 = 0xfcff;
|
||
}
|
||
else if (tk2_4){
|
||
Dkey0 = 0xfbff;
|
||
Dkey1 = 0xf3ff;
|
||
}
|
||
else if (tk2_7){
|
||
Dkey0 = 0xf7ff;
|
||
Dkey1 = 0xf3ff;
|
||
}
|
||
|
||
}
|
||
else if(sinImpulse)
|
||
{
|
||
if(tk0_0){
|
||
Dkey0 = 0xfff6;
|
||
Dkey1 = 0xfff0;
|
||
Dkey2 = 0xfff9;
|
||
}
|
||
else if(tk0_7){
|
||
Dkey0 = 0xfff9;
|
||
Dkey1 = 0xfff0;
|
||
Dkey2 = 0xfff6;
|
||
}
|
||
else if(tk1_0){
|
||
Dkey0 = 0xffde;
|
||
Dkey1 = 0xffcc;
|
||
Dkey2 = 0xffed;
|
||
}
|
||
else if(tk0_4){
|
||
Dkey0 = 0xffed;
|
||
Dkey1 = 0xffcc;
|
||
Dkey2 = 0xffde;
|
||
}
|
||
else if(tk1_4){
|
||
Dkey0 = 0xffdb;
|
||
Dkey1 = 0xffc3;
|
||
Dkey2 = 0xffe7;
|
||
}
|
||
else if(tk1_7){
|
||
Dkey0 = 0xffe7;
|
||
Dkey1 = 0xffc3;
|
||
Dkey2 = 0xffdb;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
key0 = !(((tk0_0 == 1) && (tk0_1 == 1) && (tk0_2 == 0) && (tk0_3 == 0)) ||
|
||
((tk0_0 == 0) && (tk0_1 == 1) && (tk0_2 == 1) && (tk0_3 == 0)));
|
||
|
||
key1 = !(((tk0_0 == 0) && (tk0_1 == 1) && (tk0_2 == 1) && (tk0_3 == 0)) ||
|
||
((tk0_0 == 0) && (tk0_1 == 0) && (tk0_2 == 1) && (tk0_3 == 1)));
|
||
|
||
key2 = !(((tk0_4 == 1) && (tk0_5 == 1) && (tk0_6 == 0) && (tk0_7 == 0)) ||
|
||
((tk0_4 == 0) && (tk0_5 == 1) && (tk0_6 == 1) && (tk0_7 == 0)));
|
||
|
||
key3 = !(((tk0_4 == 0) && (tk0_5 == 1) && (tk0_6 == 1) && (tk0_7 == 0)) ||
|
||
((tk0_4 == 0) && (tk0_5 == 0) && (tk0_6 == 1) && (tk0_7 == 1)));
|
||
|
||
key4 = !(((tk1_0 == 1) && (tk1_1 == 1) && (tk1_2 == 0) && (tk1_3 == 0)) ||
|
||
((tk1_0 == 0) && (tk1_1 == 1) && (tk1_2 == 1) && (tk1_3 == 0)));
|
||
|
||
key5 = !(((tk1_0 == 0) && (tk1_1 == 1) && (tk1_2 == 1) && (tk1_3 == 0)) ||
|
||
((tk1_0 == 0) && (tk1_1 == 0) && (tk1_2 == 1) && (tk1_3 == 1)));
|
||
|
||
key6 = !(((tk1_4 == 1) && (tk1_5 == 1) && (tk1_6 == 0) && (tk1_7 == 0)) ||
|
||
((tk1_4 == 0) && (tk1_5 == 1) && (tk1_6 == 1) && (tk1_7 == 0)));
|
||
|
||
key7 = !(((tk1_4 == 0) && (tk1_5 == 1) && (tk1_6 == 1) && (tk1_7 == 0)) ||
|
||
((tk1_4 == 0) && (tk1_5 == 0) && (tk1_6 == 1) && (tk1_7 == 1)));
|
||
|
||
key8 = !(((tk2_0 == 1) && (tk2_1 == 1) && (tk2_2 == 0) && (tk2_3 == 0)) ||
|
||
((tk2_0 == 0) && (tk2_1 == 1) && (tk2_2 == 1) && (tk2_3 == 0)));
|
||
|
||
key9 =!(((tk2_0 == 0) && (tk2_1 == 1) && (tk2_2 == 1) && (tk2_3 == 0)) ||
|
||
((tk2_0 == 0) && (tk2_1 == 0) && (tk2_2 == 1) && (tk2_3 == 1)));
|
||
|
||
key10 = !(((tk2_4 == 1) && (tk2_5 == 1) && (tk2_6 == 0) && (tk2_7 == 0)) ||
|
||
((tk2_4 == 0) && (tk2_5 == 1) && (tk2_6 == 1) && (tk2_7 == 0)));
|
||
|
||
key11 = !(((tk2_4 == 0) && (tk2_5 == 1) && (tk2_6 == 1) && (tk2_7 == 0)) ||
|
||
((tk2_4 == 0) && (tk2_5 == 0) && (tk2_6 == 1) && (tk2_7 == 1)));
|
||
|
||
break1 = !tk3_1;
|
||
break2 = !tk3_2;
|
||
break3 = !tk3_3;
|
||
break4 = !tk3_4;
|
||
|
||
Dkey0 &= ((break4 << 15)|(break3 << 14)|(break2 << 13)|(break1 << 12)| (key11 << 11) | (key10 << 10) | (key9 << 9) | (key8 << 8)| (key7 << 7)| (key6 << 6)| (key5 << 5)| (key4 << 4)| (key3 << 3)| (key2 << 2)| (key1 << 1)| (key0 << 0));
|
||
|
||
}
|
||
if(doubleImpulse)
|
||
test_double_impulse(Dkey0, Dkey1, p2, pM, pL, soft_off_enable, soft_on_enable);
|
||
else if(sinImpulse)
|
||
test_sin_impulse(Dkey0, Dkey1, Dkey2, p2, pM);
|
||
else
|
||
test_impulse(Dkey0,p2);
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||
start_eva_timer2();
|
||
IER |= M_INT9; //start CAN
|
||
#if (XPWMGEN==1)
|
||
i_WriteMemory(ADR_PWM_DIRECT,0xffff);
|
||
i_WriteMemory(ADR_PWM_DRIVE_MODE, 0);
|
||
#endif
|
||
return;
|
||
}
|