⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emeter_3ph_setup_44x.c

📁 基于MSPF449的三相电压表功率的开发程序
💻 C
📖 第 1 页 / 共 2 页
字号:
chan1_int_params[FIR_GAIN]=FIR_COEFF[chan1_int_params[FIR_POINTER]+1];
chan2_int_params[FIR_BETA]=FIR_COEFF[chan2_int_params[FIR_POINTER]];
chan2_int_params[FIR_GAIN]=FIR_COEFF[chan2_int_params[FIR_POINTER]+1];
chan3_int_params[FIR_BETA]=FIR_COEFF[chan3_int_params[FIR_POINTER]];
chan3_int_params[FIR_GAIN]=FIR_COEFF[chan3_int_params[FIR_POINTER]+1];
    #endif

if (CH1_FLASH_INFO_POWER_SCALE_FACTOR==0xffffffff)
  {
  f_ptr=(float *) &chan1_long_params[POWER_SCALE_FACTOR];
  *f_ptr =(float) 3.017485141754e-2;
  }
else
  {
  chan1_long_params[POWER_SCALE_FACTOR]=CH1_FLASH_INFO_POWER_SCALE_FACTOR;
  }
if (CH2_FLASH_INFO_POWER_SCALE_FACTOR==0xffffffff)
  {
  f_ptr=(float *) &chan2_long_params[POWER_SCALE_FACTOR];
  *f_ptr=(float) 3.017485141754e-2;
  }
else
  {
  chan2_long_params[POWER_SCALE_FACTOR]=CH2_FLASH_INFO_POWER_SCALE_FACTOR;
  }  
if (CH3_FLASH_INFO_POWER_SCALE_FACTOR==0xffffffff)
  {
  f_ptr=(float *) &chan3_long_params[POWER_SCALE_FACTOR];
  *f_ptr=(float) 3.017485141754e-2;
  }
else
  {
  chan3_long_params[POWER_SCALE_FACTOR]=CH3_FLASH_INFO_POWER_SCALE_FACTOR; 
  }
 
 // f_ptr=(float *) &chan1_long_params[POWER_SCALE_FACTOR];
 // *f_ptr=(float) 3.017485141754e-2;
 // f_ptr=(float *) &chan2_long_params[POWER_SCALE_FACTOR];
 // *f_ptr=(float) 3.017485141754e-2;
 // f_ptr=(float *) &chan3_long_params[POWER_SCALE_FACTOR];
 // *f_ptr=(float) 3.017485141754e-2;    

chan1_int_params[V_bias]=2048;
chan1_int_params[I_bias]=2048;

chan2_int_params[V_bias]=2048;
chan2_int_params[I_bias]=2048;

chan3_int_params[V_bias]=2048;
chan3_int_params[I_bias]=2048;

//chan1_long_params[E_accum_threshold]=0x13D661AC;
if(CH1_FLASH_INFO_E_accum_threshold==0xffffffff)                       //if no calibration before, assume value
  chan1_long_params[E_accum_threshold]=0x22917E40/2;
else
  chan1_long_params[E_accum_threshold]=CH1_FLASH_INFO_E_accum_threshold;
  
if(CH2_FLASH_INFO_E_accum_threshold==0xffffffff)                       //if no calibration before, assume value
  chan2_long_params[E_accum_threshold]=0x22917E40/2;
else
  chan2_long_params[E_accum_threshold]=CH2_FLASH_INFO_E_accum_threshold;
  
if(CH3_FLASH_INFO_E_accum_threshold==0xffffffff)                       //if no calibration before, assume value
  chan3_long_params[E_accum_threshold]=0x22917E40/2;
else
  chan3_long_params[E_accum_threshold]=CH3_FLASH_INFO_E_accum_threshold;    

chan1_high_gain_threshold=chan1_low_gain_threshold=chan1_long_params[E_accum_threshold];
chan2_high_gain_threshold=chan2_low_gain_threshold=chan2_long_params[E_accum_threshold];    
chan3_high_gain_threshold=chan3_low_gain_threshold=chan3_long_params[E_accum_threshold];  

  #if  0
chan1_long_params[E_accum_threshold]*=2;
chan2_long_params[E_accum_threshold]*=2;
chan3_long_params[E_accum_threshold]*=2;
  #endif

samples_write_index=0;
samples_read_index=0;

/*temperature and VextREF range*/
if(FLASH_INFO_average_VeREF_range==0xffff)
  average_VeREF_range=1024;
else
  average_VeREF_range=FLASH_INFO_average_VeREF_range;
  
average_temperature=0;            //not used yet

/*LCD setup*/

LCDCTL=LCDSG0_5+LCD4MUX+LCDON;
for (i=0;i<21;i++)
{
LCDMEM[i]=0x00;
}

/*Basic Timer Setup*/

BTCTL=BTFRFQ0+BT_fCLK2_DIV256+BT_fCLK2_ACLK_DIV256;     //set ticker to 32768/(256*256)
IE2|=BTIE;                                              //enable 2 seconds counter interrupt
ticker=seconds=minutes=hours=days=0;

/* ADC12 Settings: */     
     ADC12CTL0 &=~ ENC;     //  0x02;   // Disable conversion before changing
                           // the ADC12 settings!!!

                        /* selection of reference and input */
     ADC12MCTL0  = 0x13;    // Ref = AVss, VRef+; Input = A3  V1
     #if DEFAULT_USE_VREFPLUS
     ADC12MCTL1  = 0x10;    // Ref = AVss, VRef+; Input = A0  I1
     #else
     ADC12MCTL1  = 0x60;    // Ref = AVss, VRef+; Input = A0  I1 
     #endif    
     ADC12MCTL2  = 0x13;    // Ref = AVss, VRef+; Input = A3  V1   
     
     ADC12MCTL3  = 0x14;    // Ref = AVss, VRef+; Input = A4  V2
     #if DEFAULT_USE_VREFPLUS        
     ADC12MCTL4  = 0x11;    // Ref = AVss, VRef+; Input = A1  I2
     #else     
     ADC12MCTL4  = 0x61;    // Ref = AVss, VRef+; Input = A1  I2     
     #endif
     ADC12MCTL5  = 0x14;    // Ref = AVss, VRef+; Input = A4  V2

     ADC12MCTL6  = 0x15;    // Ref = AVss, VRef+; Input = A5  V3
     #if DEFAULT_USE_VREFPLUS     
     ADC12MCTL7  = 0x12;    // Ref = AVss, VRef+; Input = A2  I3
     #else     
     ADC12MCTL7  = 0x62;    // Ref = AVss, VRef+; Input = A2  I3
     #endif     
     ADC12MCTL8  = 0x15;    // Ref = AVss, VRef+; Input = A5  V3
     
     ADC12MCTL9  = 0x1A;    // Ref = AVss, VRef+; Input = A10 (temperature)
     ADC12MCTL10 = 0x18;    // Ref = AVss, VRef+; Input = A8  VeREF+
     ADC12MCTL11 = 0x99;    // Ref = AVss, VRef+; Input = A9  VeREF- 
                            // ADC12MCTL15 is end of sequence 
                            // (EOS bit is set!)

     ADC12CTL1 = SHS_3+CONSEQ_3;  //0x0d06;    
                            /* first conv. result is stored in ADC12MEM0*/
                            /* ADC12SC bit triggers Sample&Hold*/
                            /* ISSH trigger is NOT inverted*/
                            /* sample pulse is generated by Sampling Timer*/
                            /* Clock Source: TIMER_B OUT 1*/
                            /* Clock divider: 1*/
                            /* repeated sequence of conversion*/

     ADC12CTL0 = ADC12ON+REFON+MSC+REF2_5V;   //0x0072;    /* Sample&Hold Time 0*/
                            /* Sample&Hold Time 1*/
                            /* Multiple Sample&Hold OFF*/
                            /* reference voltage is on*/
                            /* ADC12 module is switched on*/
                            /* Interrupt at the end of every ADC conversion*/
     
     ADC12CTL0 |= ENC;      //0x02;     // enable conversion

     #if !DEFAULT_USE_VREFPLUS     
chan1_int_params[channel_status]|=CURRENT_HIGH_GAIN;
chan2_int_params[channel_status]|=CURRENT_HIGH_GAIN;
chan3_int_params[channel_status]|=CURRENT_HIGH_GAIN;
     #endif
     
//TIMER_B sample timing setting
 TBCCR0=SAMPLE_PERIOD;        //CCR0 determines the sample period
 TBCCR1=RESULT_READY_TIME;    //give enough time for the ADC12 to work and then start
                              //processing
 TBCCTL0=CCIE;                //enables interrupt at CCR0 equ                              
 TBCCTL1=OUTMOD_3;            //EQU1 sets OUT1, EQU0 resets OUT1
 TBCTL=TBCLR+MC_1+TBSSEL_1;   //0x0214;                
                              // start TIMER_B up mode, ACLK as input clock */
                              
//TIMER_A set up, for calibration

TACCTL1=CAP+CM_1;             //This is local pulse, not used anymore
TACCTL0=CAP+CCIS0+CM_1;       //reference pulse comes in to P1.1/TA0 
P1SEL |= BIT1+BIT2;                                
TACTL=TACLR+MC_2+TASSEL_1+ID1+ID0; 
                                  // start TIMER_A continous mode, ACLK as input clock 
                                  // DIV by 8 to give 16 seconds maximum duration
 
  
 P2SEL|=BIT2;             // select P2.2 waveform output for TB1*/
 P2DIR|=BIT2;            
 
 P2SEL|=BIT6;               //select P2.6 as CAOUT
 P2DIR|=BIT6; 
 
 //P1DIR |= 0x2;              //select MClk

  
 P1DIR|=BIT0;              //use P1.0 as indicator
 P1OUT|=BIT0;
                          //these LEDs are used for counting power pulses
 //P1DIR|=BIT4;
 //P1SEL|=BIT4;
                          //these LEDs are used for counting power pulses 
 P3DIR|=CHAN1_PULSE+CHAN2_PULSE+CHAN3_PULSE;    //P3.0,P3.1,P3.2
 P3OUT|=CHAN1_PULSE+CHAN2_PULSE+CHAN3_PULSE;
 P3DIR|=BIT3+BIT4+BIT5;                         //P3.3,P3.4,P3.5
 
}
//************************************************************************
//     This is the pattern used in testing small signals
//      By programming channel 1 to V1 I1 using external reference range
//        and programming channel 2 to VI TI using internal reference range
//************************************************************************
//     ADC12MCTL0  = 0x13;    // Ref = AVss, VRef+; Input = A3  V1
//     ADC12MCTL1  = 0x60;    // Ref = AVss, VeREF+ VeREF-; Input = A0  I1
//     ADC12MCTL2  = 0x13;    // Ref = AVss, VRef+; Input = A3  V1
     
//     ADC12MCTL3  = 0x13;    // Ref = AVss, VRef+; Input = A4  V2        
//     ADC12MCTL4  = 0x60;    // Ref = AVss, VRef+; Input = A1  I2
//     ADC12MCTL5  = 0x13;    // Ref = AVss, VRef+; Input = A4  V2  

//chan1_long_params[E_accum_threshold]*=2;    //chan1 set to higher gain so need to
                                            //double the threshold level
//chan2_long_params[E_accum_threshold]*=2;    //chan1 set to higher gain so need to
                                            //double the threshold level  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -