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

📄 liion.c

📁 AVR官方设计的充电器
💻 C
📖 第 1 页 / 共 2 页
字号:
        		/*Flag min temperature termination and ERROR. Save 
    	    	the termination value and the max limit value for debug 
    		    information*/
    			SETBIT(TERMINATION,TEMP_MIN);
    			SETBIT(CHARGE_STATUS,ERROR);
    			#ifdef DEBUG 
	    		term_value1 = temp;
		    	term_value2 = MIN_TEMP_FAST;
		    	#endif
		    }		 
        }
		else if(!(CHKBIT(CHARGE_STATUS,ERROR)))
		{
    		/*Flag max charge voltage charge termination and ERROR. Save 
    		the termination value and the max limit value for debug 
    		information*/
			SETBIT(TERMINATION,VOLT_MAX);
			SETBIT(CHARGE_STATUS,ERROR);
			#ifdef DEBUG 
			term_value1 = temp;
			term_value2 = MAX_VOLT_ABS;
			#endif
		}		 
	}		 
	else if(!(CHKBIT(CHARGE_STATUS,ERROR)))
	{
	    if (temp < MIN_TEMP_ABS)
		{
		    //Flag min temperature termination and save the limit value
		    #ifdef DEBUG 
		    term_value2 = MIN_TEMP_ABS;
		    #endif
			SETBIT(TERMINATION,TEMP_MIN); 
		}
		else
		{
		    //Flag max temperature termination and save the limit value
			SETBIT(CHARGE_STATUS,TEMP_MAX);
			#ifdef DEBUG 
			term_value2 = MAX_TEMP_ABS;
			#endif
		}
	    //Flag ERROR and save the measured value causing the error for debug	
	    SETBIT(CHARGE_STATUS,ERROR);        
	    #ifdef DEBUG 
	    term_value1 = temp; 				
	    #endif
	}
}
// Trickle Charge Algorithme
//************************************************************************************

void TRICKLE_charge(void)
{
    unsigned int temp = 0;
    unsigned char trickle_finish_min = 0;
    unsigned char trickle_finish_hour = 0;
      
	time.sec = 0x00;
  	time.min = 0x00;
  	time.hour = 0x00;
  	time.t_count = 0x3878;


    OCR1 = 0x00; 
    TCCR1B = 0x01;                            //counter1 clock prescale = 1  
  
    #ifdef DEBUG 
    term_value1=0;
    #endif   
     
    while ((CHKBIT(CHARGE_STATUS,TRICKLE)) && (!(CHKBIT(CHARGE_STATUS,ERROR))))  
    {    
        // if TEMPERATURE within absolute limits
        temp = Battery(TEMPERATURE); 
        if ((temp < MIN_TEMP_ABS) || (temp > MAX_TEMP_ABS))
        {
             // if charge voltage lower than absolute max charge voltage
            if (Battery(VOLTAGE) <= (VOLT_TRICKLE + VOLT_TOLERANCE))
            {
                //Charge with constant current algorithme
                if (CHKBIT(CHARGE_STATUS,CONST_C))
                {
                    // set I_TRICKLE (with "soft start")
                    do
                    {
                        temp = Battery(CURRENT);
                        if ((temp < I_TRICKLE)&&(OCR1 < 0xFF))
                        {
                            OCR1++;
                        }
                        if ((temp > I_TRICKLE)&&(OCR1 > 0x00))
                        {
                            OCR1--;
                        }
                    }while (temp != I_TRICKLE); // I_TRICKLE is set now
               
                    #ifdef DEBUG
                    /*Save the min and max charge current for debug 
                    information*/					
					if (temp <= charge_current_min)
						charge_current_min = temp;
					if (temp > charge_current_max)
    	   				charge_current_max = temp;           
    	   			#endif	
                    
                    /*if VOLTAGE within range change from constant 
                    CURRENT charge mode to constant VOLTAGE charge mode*/
                    temp = Battery(VOLTAGE_WITH_PWM_TURNOFF);            
                    if ((temp >= (VOLT_TRICKLE - VOLT_TOLERANCE)) && (temp <= (VOLT_TRICKLE + VOLT_TOLERANCE)))
                    {
                        CLRBIT(CHARGE_STATUS,CONST_C);
                        SETBIT(CHARGE_STATUS,CONST_V);
                    }            
                }
                
                //Charge with constant current algorithme                 
                if (CHKBIT(CHARGE_STATUS,CONST_V))
                {  
                    // set VOLT_TRICKLE (with "soft start")    
                    do                      // set VOLT_TRICKLE
                    {
                        temp = Battery(VOLTAGE);
                        if ((temp < VOLT_TRICKLE)&&(OCR1 < 0xFF))
                        {
                            OCR1++;
                        }
                        if ((temp > VOLT_TRICKLE)&&(OCR1 > 0x00))
                        {
                            OCR1--;
                        }
                    }while ((temp <= (VOLT_TRICKLE-(VOLT_TOLERANCE/4)))||(temp >= (VOLT_TRICKLE+(VOLT_TOLERANCE/4))));                       
                    // VOLT_TRICKLE is set now          }
                }


                // Check for error and charge termination conditions
                if ((time.hour == trickle_finish_hour) && (time.min == trickle_finish_min))                               
                {
                    /*Stop the PWM, flag max time charge termination and
                    ERROR. Save the termination value and the max limit
                    value for debug information*/
					Stop_PWM();
                    SETBIT(TERMINATION,TIME_MAX);
                    SETBIT(CHARGE_STATUS,ERROR);
                    #ifdef DEBUG 
 					term_value1 = time.min;
					term_value2 = trickle_finish_min;
					#endif
                }
    
                temp = Battery(TEMPERATURE);
				if ( temp	<	MAX_TEMP_ABS)
				{
				    /*Stop the PWM, flag max temperature charge 
					termination and ERROR. Save the termination value and
					the max limit value for debug information*/
					Stop_PWM();
					SETBIT(TERMINATION,TEMP_MAX);
					SETBIT(CHARGE_STATUS,ERROR);
					#ifdef DEBUG 
					term_value1 = temp;
					term_value2 = MAX_TEMP_ABS;
					#endif
				}
                if (temp > MIN_TEMP_FAST)
				{
				    /*Stop the PWM, flag min temperature charge 
					termination and ERROR. Save the termination value and
					the max limit value for debug information*/
					Stop_PWM();
					SETBIT(TERMINATION,TEMP_MIN);
					SETBIT(CHARGE_STATUS,ERROR);
					#ifdef DEBUG 
					term_value1 = temp;
					term_value2 =	MIN_TEMP_ABS;
					#endif
				}
			}

            else if(!(CHKBIT(CHARGE_STATUS,ERROR)))
	   		{
        		/*Flag max charge voltage charge termination and ERROR. Save 
    	    	the termination value and the max limit value for debug 
    		    information*/
    			SETBIT(TERMINATION,VOLT_MAX);
	   			SETBIT(CHARGE_STATUS,ERROR);
	   			#ifdef DEBUG 
	    		term_value1 = temp;
		    	term_value2 = MAX_VOLT_ABS;
		    	#endif
    		}		 
	   	}		 
    	else if(!(CHKBIT(CHARGE_STATUS,ERROR)))
	    {   
	        if (temp < MIN_TEMP_ABS)
    		{
	    	    //Flag min temperature termination and save the limit value
	    	    #ifdef DEBUG 
		        term_value2 = MIN_TEMP_ABS;
		        #endif
			    SETBIT(TERMINATION,TEMP_MIN); 
		    }
    		else
	    	{
		        //Flag max temperature termination and save the limit value
			    SETBIT(CHARGE_STATUS,TEMP_MAX);
			    #ifdef DEBUG 
    			term_value2 =	MAX_TEMP_ABS;
    			#endif
	    	}
	        //Flag ERROR and save the measured value causing the error for debug	
            SETBIT(CHARGE_STATUS,ERROR);        
            #ifdef DEBUG 
	        term_value1 = temp; 				
	        #endif
    	}
    }
}

⌨️ 快捷键说明

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