📄 f300_highspeed_bc.c
字号:
BULK = 0; // Prepare to exit BULK mode
LOWCURRENT = 1; // Prepare to enter LOWCURRENT Mode
if (Current < IMIN)
I_MIN = 1; // Indicate Specific Error for Debug
else
I_MAX = 1; // Indicate Specific Error for Debug
}
else if ((Current < IMAX) && (Current > IMIN))
{ I_MAX = 0; // Reset Error Flag
I_MIN = 0; // Reset Error Flag
Regulate_Voltage(); // Charge with Constant Voltage
}
}
// Now, Check for error and charge termination conditions
// If above max charge time, flag error
// Test for BULK Charge Time Out
// Monitor Time
if ((TIME.hour == bulk_finish_hour) && (TIME.min == bulk_finish_min)
&& (DELAY == 0))
{
Turn_PWM_Off(); // Turn Off PWM
TIME_MAX = 1; // Set Time max error flag
ERROR = 1; // Set general error flag
}
// Monitor Temperature
temp = Monitor_Battery(TEMPERATURE);
if ((temp < MIN_TEMP_ABS) && (temp > MAX_TEMP_ABS))
{
Turn_PWM_Off(); // Turn Off PWM
if (temp < MIN_TEMP_ABS)
TEMP_MIN = 1; // Set Temperature below minimum flag
else
TEMP_MAX = 1; // Set Temperature exceeds maximum flag
ERROR = 1; // Set general error flag
}
// Minute elapsed?
// Check for minimum current
// if reached, enter last DELAY charge
if (TIME.min != last_min)
{
last_min = TIME.min;
if ((CONST_V == 1) && (DELAY == 0) && (Monitor_Battery(CURRENT)
<= MIN_I_BULK))
{
// Calculate TOP OFF Battery Time finish time
delay_min = (TIME.min + BULK_TIME_DELAY);
delay_hour = TIME.hour;
while (delay_min > 60)
{
delay_min = delay_min - 60;
delay_hour++;
}
DELAY = 1; // Set Delay Flag
}
// Monitor Delay time, time up?
if ((TIME.hour == delay_hour)&&(TIME.min == delay_min) &&
(DELAY == 1))
{
Turn_PWM_Off(); // Turn Off PWM
CONST_V = 0; // Exit CONST_V
CONST_C = 1; // Prepare to enter CONST_C
BULK = 0; // Prepare to exit BULK mode
LOWCURRENT = 1; // Prepare to enter LOWCURRENT Mode
}
}
} // End Main While loop
}
else if(ERROR == 0)
{
if (temp > (MAX_VOLT_ABS + VOLT_TOLERANCE))
{ VOLT_MAX = 1; // Set Max Voltage error flag
ERROR = 1; // Set general error flag
}
else if(temp < MIN_VOLT_BULK)
{ VOLT_MIN = 1; // Set Minimum bulk voltage error flag
LOWCURRENT = 1; // Switch to LOWCURRENT mode
BULK = 0; // Exit Bulk Charge mode
} // battery's voltage very low
}
}
else if(ERROR == 0) // Absolute temperature out of range?
{
if (temp < MIN_TEMP_ABS)
TEMP_MIN = 1; // Set Temperature below minimum flag
else
TEMP_MAX = 1; // Set Temperature exceeds maximum flag
ERROR = 1; // Set general error flag
}
}
//-----------------------------------------------------------------------------
// Lowcurrent_Charge
//-----------------------------------------------------------------------------
void Lowcurrent_Charge(void)
{
unsigned int temp = 0;
unsigned int lowcurrent_finish_min = 0;
unsigned int lowcurrent_finish_hour = 0;
Reset_Time_Base(); // Reset Time base to zero
// Calculate LOWCURRENT finish time
lowcurrent_finish_min = (TIME.min + MAX_TIME_LOWCURRENT);
lowcurrent_finish_hour = TIME.hour;
while (lowcurrent_finish_min > 60)
{
lowcurrent_finish_min = lowcurrent_finish_min - 60;
lowcurrent_finish_hour++;
}
// Enter Main Lowcurrent Loop.
// Only exits are upon error and full charge
while ((LOWCURRENT == 1) && (ERROR == 0))
{
temp = Monitor_Battery(TEMPERATURE);// Get Temperature Reading
// Is TEMPERATURE within limits
if ((temp > MIN_TEMP_ABS) && (temp < MAX_TEMP_ABS))
{
// Is Battery's Charge Voltage below max charge voltage
temp = Monitor_Battery(VOLTAGE); // Get Voltage Reading
if (temp <= (VOLT_LOWCURRENT + VOLT_TOLERANCE))
{
if (CONST_C == 1) // CONST_C ?, charge w/ constant current
Regulate_Current(I_LOWCURRENT);
if (CONST_V == 1) // CONST_V?, charge w/ constant voltage
Regulate_Voltage();
if ((temp >= MIN_VOLT_BULK) && (DELAY == 0))// Bulk Threshold voltage met?
{ LOWCURRENT = 0; // Exit LOWCURRENT mode
BULK = 1; // Switch to Bulk Charge mode
}
// Check elapsed time
if ((TIME.hour == lowcurrent_finish_hour) &&
( TIME.min == lowcurrent_finish_min))
{
TIME_MAX = 1; // Set Time MAX error flag
ERROR = 1; // Set general error flag
}
}
else if(ERROR == 0) // Voltage to high?
{
VOLT_MAX = 1; // Set Max voltage error flag
ERROR = 1; // Set general error flag
}
}
else if(ERROR == 0) // Absolute temperature out of range?
{
if (temp < MIN_TEMP_ABS)
TEMP_MIN = 1; // Set Temperature below minimum flag
else
TEMP_MAX = 1; // Set Temperature exceeds maximum flag
ERROR = 1; // Set general error flag
}
}
}
//-----------------------------------------------------------------------------
// Main Function
//-----------------------------------------------------------------------------
void main(void)
{
EA = 0; // Disable All Interrupts
Reset_Time_Base();
Config_F300(); // Config F300
//Turn_PWM_Off(); // Turn PWM off before Calibration
//CalibrateADCforMeasurement(); // Calibrate F300
EA = 1; // Enable All Active Interrupts
while(1)
{
LED0 = 0; // Turn LED0 off
TERMINATION = 0x00; // Reset Termination Flags
CHARGE_STATUS = 0x00; // Reset Charge Status Flags
LOWCURRENT = 0;
BULK = 1; // Start in LOWCURRENT Charge Mode
CONST_C = 1;
while (ERROR == 0)
{
if (BULK == 1)
{
Bulk_Charge(); // Enter Bulk Charge Mode
}
if (LOWCURRENT == 1)
Lowcurrent_Charge(); // Enter Lowcurrent_Charge function
// Toggle LED0 at 1 Hz rate via ISR
}
if (ERROR == 1)
{
Turn_PWM_Off();; // Turn PWM Off
EA = 0; // Disable All Interrupts
while (1); // Enter a eternal loop
// No recovery except "reset-button"
}
}
}
//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// PCA_ISR
//-----------------------------------------------------------------------------
// This routine counts the elapsed time in seconds, minutes, hours.
// It also toggles LED0 every second when in Lowcurrent Charge Mode.
// This routine interrupts every time the PCA counter overflows, every 256
// SYSCLK cycles. After SYSCLK/256 interrupts, one second has elapsed.
//
void PCA_OVERFLOW_ISR (void) interrupt 9
{ int time_sec;
PCA0CN = 0x40; // Reset all PCA Interrupt Flags
PCA0H = 0x00; // Reset High Byte of PCA Counter
// of 8-bit PWM we are using Module1
if (0x0000 == --TIME.t_count)
{
TIME.t_count = PWM_CLOCK; // Reset 1 Second Clock
if ( 60 == ++TIME.sec ) // Account for elapsed seconds
{ // Reset second counter every minute
TIME.sec = 0x00;
if ( 60 == ++TIME.min ) // Account for elapsed minutes
{ // Reset minute counter every hour
TIME.min = 0x00;
if ( 24 == ++TIME.hour ) // Account for elapsed hours
TIME.hour = 0x00; // Reset hour counter every day
}
}
time_sec = TIME.sec;
if ((LOWCURRENT == 1) && (ERROR == 0))
{ // Blink LED0 at 1 Hz if in Lowcurrent
//if (TIME.sec % 2)
// LED0 = 0; // Turn on LED every odd second
//else
// LED0 = 1; // Turn on LED every even second
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -