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

📄 pfc_ctrl.c

📁 boost-pfc升压型功率因素校正程序
💻 C
📖 第 1 页 / 共 2 页
字号:
                    else if(gs_v_haversine_peak>(VIN_CMP_V2))
                        pfc_previous_timer=V_400_S_T2;
                    else  pfc_previous_timer=V_400_S_T3;

                }
                if(fun_lamp_state == START_IGNITION)
                {
                    if(gs_v_haversine_peak>(VIN_CMP_V3))
                        psc_ontime0 =psc_ontime0*PSC_GANE1+PSC_ADJ1;
                    else  psc_ontime0 =psc_ontime0*PSC_GANE2+PSC_ADJ2;
                    psc_deadtime0=0;
                    psc_ontime1=8000/31;
                    psc_deadtime1=0;
                    update_psc0 (psc_deadtime0,psc_ontime0,psc_deadtime1,psc_ontime1);
                }
                else  if(fun_lamp_state == RUN_MODE)
                {
                    Disable_comparator0_interrupt();
                    Disable_psc0_end_of_cycle_interrupt();
                    //! Configure PSC0 in fault mode 8
                    //! ****** PFRC0B
                    //! 7   PCAE0B    : 0 Enable capture disabled
                    //! 6   PISEL0B   : 1 Select PSC0INS1 as input retrigger block
                    //! 5   PELEV0B   : 1 the signicative event for retrigger is the falling edge
                    //! 4   PFLTE0B   : 0 Noise canceler is not used
                    //! 3:0 PRFM0B3:0 : PSC0 Fault mode
                    //!               : 1000 Fault mode 8 (Edge retrigger PSC0)
                    //! ****** END PFRC0B
                    //! PFRC0B = 01101000 //
                    PFRC0B = 0x68;
                    Start_pll_64_mega();
                    Wait_pll_ready();
                    Psc0_use_pll_clock();

                    if(gs_v_haversine_peak>(VIN_CMP_V4))
                          psc_ontime0 =psc_ontime0*PSC_GANE3+PSC_ADJ3;
                    else if(gs_v_haversine_peak>(VIN_CMP_V5))
                          psc_ontime0 =psc_ontime0*PSC_GANE4+PSC_ADJ4;
                    else  psc_ontime0 =psc_ontime0*PSC_GANE5+PSC_ADJ5;

                    pfc_run_start(psc_ontime0);                                      
                    fun_pfc_state = PFC_SOFT_CONTROL;
                    pfc_previous_timer=0;
                    delay=0;
                    PI_ERR=0;//累计误差
										PI_ERR_num=0;//累计误差计数
										gos_err_last=0;
										DALI_init();
                }
            }
            break;
        }
    case PFC_SOFT_CONTROL:   //PFC调整程序
        {
            //PFC调整调整程序
            //============稳压过程=============================
			  	  unsigned int temp_v_bus=AD_v_bus;
						short gine=0;
						signed int gs_error ;
						static unsigned  i_stable_time;						
						//电压过大的时间超过2510MS,,采取强行降压
						if ((temp_v_bus > PFC_V_440V)&&(delay>800)) //243-200 40
						{								
								comparison_ontime0 =40;								
								psc_ontime0=comparison_ontime0;
								delay=0;
						}
						else
						{   
							if ((pfc_previous_timer >=15) )
							{  								  
								  i_stable_time++;
									gs_error= PFC_V_OUT  - temp_v_bus;//PFC_V_OUT=400V
									///////////////////////////
									if((gs_error > 75) || (gs_error < (-75)))
									{
				            //快速调整
										gine=(short)((gs_error)/(2));
										/**/
										gine/=4;										
										pfc_previous_timer =0;//6
									}
								///////////////	
									if((gs_error > 60) || (gs_error < (-60)))
									{
				            //快速调整
										gine=(short)((gs_error)/(3));//2
										/**/
										gine/=3;										
										pfc_previous_timer =0;//6
									}
									else if((gs_error > 45) || (gs_error < (-45)))
									{
										 //中速调整
										 gine=(short)((gs_error)/(2));//4
										 /**/
										 gine/=5;										 
										 pfc_previous_timer =0;//6
									}
									else
									{
											if(((gs_error <=20) && (gs_error >= (-18))))
											{
												 //累计误差计数
												 gine=0;
												 if(++PI_ERR_num>15)
												 {
													 if((PI_ERR>280) ||( PI_ERR<(-280)))
													 {
														 //累计误差调整
														 gine=(PI_ERR>0 ?1:(-1));
													 }
													 PI_ERR_num=0;
													 PI_ERR=0;
												 }
												 else  PI_ERR+=gs_error; //累计误差
											}
											//慢速调整
											else 
											{
												  gine=(short)((gs_error)/(2));//
												  /**/
												  gine/=6;												  
											}
											delay=0;	
											pfc_previous_timer =0;//3
									}
																		//振荡稳定程序
									if((gos_err_last>60)&&(i_stable_time==3))
									{
										  if((gs_error>0) && (gos_err_last>gs_error))
										       ;
										  else 
										  {
										  	gine=gine/3;										  	
										  	pfc_previous_timer=0;
										  }
									}
									else if((gos_err_last<(-60))&&(i_stable_time==2))
									{
										 if((gs_error<0) && (gos_err_last<gs_error))
										      ;
										 else 
										  {
										  	gine=gine/3;										  	
										  	pfc_previous_timer=0;
										  }
									}
									gos_err_last=gs_error;
									comparison_ontime0 = (unsigned int)((comparison_ontime0)+(short)(gine));
									//启动慢速调节
									if(gine<0)
									{
										if(comparison_ontime0<(gine*(-1)))
				                 comparison_ontime0=comparison_ontime0/4;
				            pfc_previous_timer=0;
									}	
							}
							//最大占空比限制
							g_max_pulse_width=800;
							if (comparison_ontime0 > g_max_pulse_width) 
							{
								if(gs_error > 0)
								{
									comparison_ontime0 = g_max_pulse_width;
								}
								else
								{
									comparison_ontime0 = 20;
								}
							}
							else if (comparison_ontime0 <3)
								     comparison_ontime0 = 3;
							if (temp_v_bus > PFC_V_440V)
								      delay++;//过压时间累加
						  else    delay=0;
						}

						psc_ontime0=comparison_ontime0;
			      psc_ontime1=PFC_MAX_PERIOD;
						psc_deadtime0=0;
						psc_deadtime1=0;
						update_psc0 (psc_deadtime0,psc_ontime0,psc_deadtime1,psc_ontime1);
						fun_pfc_state = PFC_SOFT_CONTROL;

            break;

        }
    case SHUT_DOWN_PFC_AND_SLOW_DOWN_UC_SPEED:
        {
            pfc_run_off();
            fun_pfc_state = PFC_OFF;
            break;
        }
    case PFC_PROBLEM:
        {
            Disable_both_psc0_outputs();
            Stop_psc0();
            fun_pfc_state = PFC_PROBLEM;
            break;
        }
    default:
        {

            Disable_both_psc0_outputs();
            Stop_psc0();
            fun_pfc_state = INIT_PFC_CHECK;
            break;
        }

    } // End switch
} // End PFC_task

//主动关闭所有输出
void stop_pfc_con(void)
{
    psc_ontime0=0;
    psc_deadtime0=PFC_START_PULSE;
    psc_ontime1=0;
    psc_deadtime1=PFC_START_PERIOD;
    update_psc0 (psc_deadtime0,psc_ontime0,psc_deadtime1,psc_ontime1);
    Disable_both_psc0_outputs();
    Stop_psc0();
    Disable_comparator0();
    PFC_DDR  &=~(1<<PFC_PIN);
    PFC_PORT &=~(1<<PFC_PIN);
    PFC_DDR  |=(1<<PFC_PIN);
    CLI();

    //8分频---1M
    CLKPR =(1<<CLKPCE);
    CLKPR = (1<<CLKPS0)|(1<<CLKPS1)|(0<<CLKPS2);

    fosck=8;

    SEI();
    TCCR0B = ( (0x08) | (TIMER_0_PRESCALER_LOW_SPEED) );
    fun_pfc_state = PFC_OFF;
}

⌨️ 快捷键说明

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