calc_fft

/******************************************************0x005E******************************************************/
/*
 *  sw  三相电流不平衡度
 */
void CurrentUnbanceShell(slot_enum _no)
{
    TSlotState SlotInfo = {.Io1Set = 1, .Io4Set = 0, .Io4Out = 1,  .VddVol = 1, .AD0En = 1,  .AD1En = 1};
    unsigned char ADId[3][2] = {  {15, 13}, {16, 4}, {11, 3} }; 
    uint16_t Input_u16[256];
    float Input_f32[256], Kp = 19.96008;//1000/50.1;
    FFTRunData _fft; SUnbalance _sun;
    float Am[256]; float Phase[256]; float AmHarm[10]; float PhaseHarm[10]; float FreqHarm[10];
    float abc[3][2], unbalanceBasic[3], unbalZero, unbalNega;    
    SensorSlotCreate(_no, &SlotInfo);
    osDelay(500);
/* FFT算出基波和相位 */        
    GPIO4[_no]->BSRR = 1<<  (GPIOPos4[_no] + 16);//ADC_AII0 - ADC_AII2
    osDelay(500);
    GeneralGetADSamples(ADId[_no][0], 500, Input_u16, 256);
    for(int i = 0; i < 256; i++) { Input_f32[i] = (float)(Kp*(AD_CLAC(Input_u16[i]) - 1650.0));}
    
    for(int i=0;i<256;i++)//生成信号序列
    {
        Input_f32[i]=230*arm_sin_f32(2*PI*i*49.5/2000+5*PI/3); //生成实部
    }
    
    FFT_NEW(&_fft, 2000, Input_f32, Am, Phase, AmHarm, PhaseHarm, FreqHarm);
    FFT_RUN(_fft);
    abc[0][0] = AmHarm[0]*0.70710678;//基波有效值
    abc[0][1] = PhaseHarm[0];//基波相位
    MSG_LOG("Ia_rms is %f, Ia_phase is %f\r\n", abc[0][0], abc[0][1]);
    
    GeneralGetADSamples(ADId[_no][1], 500, Input_u16, 256);
    for(int i = 0; i < 256; i++) { Input_f32[i] = (float)(Kp*(AD_CLAC(Input_u16[i]) - 1650.0));}

    for(int i=0;i<256;i++)//生成信号序列
    {
        Input_f32[i]=228*arm_sin_f32(2*PI*i*49.5/2000+PI/3); //生成实部
    }
    
    FFT_NEW(&_fft, 2000, Input_f32, Am, Phase, AmHarm, PhaseHarm, FreqHarm);
    FFT_RUN(_fft);
    abc[2][0] = AmHarm[0]*0.70710678;
    abc[2][1] = PhaseHarm[0];
    MSG_LOG("Ic_rms is %f, Ic_phase is %f\r\n", abc[2][0], abc[2][1]);

    
    GPIO4[_no]->BSRR = 1<<  GPIOPos4[_no];//ADC_AII1 - ADC_AII3
    osDelay(500);
    GeneralGetADSamples(ADId[_no][0], 500, Input_u16, 256);
    for(int i = 0; i < 256; i++) { Input_f32[i] = (float)(Kp*(AD_CLAC(Input_u16[i]) - 1650.0));}
    
    for(int i=0;i<256;i++)//生成信号序列
    {
        Input_f32[i]=230*arm_sin_f32(2*PI*i*49.5/2000+PI); //生成实部
    }
    
    FFT_NEW(&_fft, 2000, Input_f32, Am, Phase, AmHarm, PhaseHarm, FreqHarm);
    FFT_RUN(_fft);
    abc[1][0] = AmHarm[0]*0.70710678;
    abc[1][1] = PhaseHarm[0];
    MSG_LOG("Ib_rms is %f, Ib_phase is %f\r\n", abc[1][0], abc[1][1]);

/* 对称分量法算出正序负序和零序分量 */        
   _sun.a.real = abc[0][0]*cos(abc[0][1]*0.0174533);//PI/180
   _sun.a.image =  abc[0][0]*sin(abc[0][1]*0.0174533);
   
   _sun.b.real = abc[1][0]*cos(abc[1][1]*0.0174533);
   _sun.b.image = abc[1][0]*sin(abc[1][1]*0.0174533);
   
   _sun.c.real = abc[2][0]*cos(abc[2][1]*0.0174533);
   _sun.c.image = abc[2][0]*sin(abc[2][1]*0.0174533);   
   SymmetryWeight(&_sun);

/* 按国标算出零序不平衡和负序不平衡 */
    unbalanceBasic[1] = sqrt(_sun.z1.real*_sun.z1.real + _sun.z1.image*_sun.z1.image);
    unbalanceBasic[2] = sqrt(_sun.z2.real*_sun.z2.real + _sun.z2.image*_sun.z2.image);        
    unbalanceBasic[0] = sqrt(_sun.z0.real*_sun.z0.real + _sun.z0.image*_sun.z0.image);
    
    unbalNega = unbalanceBasic[2]/unbalanceBasic[1];
    unbalZero = unbalanceBasic[0]/unbalanceBasic[1];

   MSG_LOG("unbalance Zero is %f, unbalance Nega is %f\r\n", unbalZero, unbalNega);
   
   

    
    
}    
    
    TSlotState SlotInfo = {.Io1Set = 1, .Io4Set = 0, .Io4Out = 1,  .VddVol = 1, .AD0En = 1,  .AD1En = 1};
    unsigned char ADId[3][2] = {  {15, 13}, {16, 4}, {11, 3} }; 
    uint16_t Input_u16[256*2], Input_u16_A[256], Input_u16_C[256],fs = 2000;;
    float Input_f32[256], Kp = 0.1996008;//1000/50.1;
    FFTRunData _fft; SUnbalance _sun;
    float Am[256]; float Phase[256]; float AmHarm[10]; float PhaseHarm[10]; float FreqHarm[10];
    float abc[3][3], unbalanceBasic[3], unbalZero, unbalNega;    
    SensorSlotCreate(_no, &SlotInfo);
    osDelay(500);
/* FFT算出基波和相位 */        
    GPIO4[_no]->BSRR = 1<<  (GPIOPos4[_no] + 16);//ADC_AII0 - ADC_AII2
    osDelay(500);
    GeneralGetADSamples(&ADId[_no][0], 2, 500, Input_u16, 256);
#if 1
    for(int i= 0; i<256; i++)
    {
        Input_u16_A[i] = Input_u16[2*i];
        Input_u16_C[i] = Input_u16[2*i+1];
    }
#endif    
    for(int i = 0; i < 256; i++) { Input_f32[i] = (float)(Kp*(AD_CLAC(Input_u16_A[i]) - 1650.0));}
    
    FFT_NEW(&_fft, fs, Input_f32, Am, Phase, AmHarm, PhaseHarm, FreqHarm);
    FFT_RUN(_fft);
    abc[0][0] = AmHarm[0]*0.70710678;//基波有效值
    abc[0][1] = PhaseHarm[0];//基波相位
    abc[0][2] = FreqHarm[0];//基波频率
    MSG_LOG("Ia_rms is %f, Ia_phase is %f, Ia_freq is %f\r\n", abc[0][0], abc[0][1], abc[0][2]);

    for(int i = 0; i < 256; i++) { Input_f32[i] = (float)(Kp*(AD_CLAC(Input_u16_C[i]) - 1650.0));}
    
    FFT_NEW(&_fft, fs, Input_f32, Am, Phase, AmHarm, PhaseHarm, FreqHarm);
    FFT_RUN(_fft);
    abc[2][0] = AmHarm[0]*0.70710678;
    abc[2][1] = PhaseHarm[0];
    abc[2][2] = FreqHarm[0];//基波频率
    MSG_LOG("Ic_rms is %f, Ic_phase is %f, Ic_freq is %f\r\n", abc[2][0], abc[2][1], abc[2][2]);
    

 

上一篇:【go语言学习笔记】回调函数


下一篇:react dva框架 使用less 和css modules