#define ON 1
#define OFF 0
sbit low_led at GP4_bit;
sbit charge_led at GP5_bit;
sbit RELAY at GP1_bit;
sbit MOSFET at GP2_bit;
unsigned int adc_value =0;
unsigned char led_blink = 0;
double mains_voltage = 0.0;
void delay_start()
{
int i;
for(i=0; i<6; i++){
charge_led = ~charge_led;
delay_ms(1000);
}
}
void InitTimer1(){
T1CON = 0x21;
TMR1IF_bit = 0;
TMR1H = 0x0B;
TMR1L = 0xDC;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
void Interrupt() {
if (TMR1IE_bit && TMR1IF_bit) {
TMR1L = 0xDC;
TMR1H = 0x0B;
if (led_blink) { // use this to switch on-off the blinking in main()
charge_led = ~charge_led;
}
TMR1IF_bit = 0;
}
}
void main() {
asm clrwdt
OPTION_REG = 0x8F;
CMCON = 0x07;
ANSEL = 0x51;
ADCON0 = 0x80;
TRISIO = 0x09;
GPIO = 0x00;
delay_ms(50);
InitTimer1();
delay_start();
ADC_Init();
do{
adc_value = ADC_Read(0);
delay_ms(5);
mains_voltage = (double)adc_value * 5.0 / 1023.0;
if(mains_voltage <= 2.15)
{
led_blink = 1;
RELAY = ON;
MOSFET = ON;
low_led = OFF;
}
delay_ms(100);
if(mains_voltage > 2.15)
{
charge_led = ON;
led_blink = 0;
RELAY = OFF;
MOSFET = ON;
low_led = OFF;
}
else if(mains_voltage < 1.58)
{
charge_led = OFF;
led_blink = 0;
RELAY = OFF;
MOSFET = ON;
low_led = ON;
}
delay_ms(50);
} while(1);
}
Now What should I do?
if(GP3_bit == 1){
if(adc_voltage <= 2.120){
led_blink = 1;
RELAY = ON;
MOSFET = ON;
low_led = OFF;
}
else {
charge_led = ON;
led_blink = 0;
RELAY = OFF;
MOSFET = ON;
low_led = OFF;
}
}
if(GP3_bit == 0){
if(adc_voltage <= 1.58100){
charge_led = OFF;
led_blink = 0;
RELAY = OFF;
MOSFET = ON;
low_led = ON;
}
else
led_blink = 0;
charge_led = OFF;
RELAY = OFF;
MOSFET = OFF;
low_led = OFF;
}
}
The chattering is probably because you have an absolute threshold voltage that operates the relay. When the voltage drops slightly the relay is turned on but doing so increases the voltage and turns it off again. You need to define two thresholds, a slightly higher one for turning the relay off then the one for turning it on again. Instead of chattering it will then cycle slowly between the two voltages, as the battery drops (say 0.25V) it gets recharged and as the voltage reaches maximum the charge is turned off again.
Brian.
Is there any way that will stop the relay after the full charged is complete?
if(GP3_bit == 1){
if(adc_voltage <= 2.000){
led_blink = 1;
RELAY = ON;
MOSFET = ON;
low_led = OFF;
}
else if (adc_voltage > 2.150 {
charge_led = ON;
led_blink = 0;
RELAY = OFF;
MOSFET = ON;
low_led = OFF;
}
else;
}
if(GP3_bit == 0){
if(adc_voltage <= 1.58100){
charge_led = OFF;
led_blink = 0;
RELAY = OFF;
MOSFET = ON;
low_led = ON;
}
else
led_blink = 0;
charge_led = OFF;
RELAY = OFF;
MOSFET = OFF;
low_led = OFF;
}
}
Normally a fully charged battery has a slightly higher terminal voltage than it is rated at. For example a fully charged 12V battery may measure 13V before the load stabilizes it at 12V until it has discharged. What you have to do is decide what the fully charged voltage will be and disconnect the relay when it is reached. The relay shouldn't operate again until the voltage has dropped low enough that recharging is needed. As I posted earlier, you need two thresholds, one is the "I'm fully charged so turn off" voltage and the other is "I'm running low so charge me again" voltage.Hi Brian, Is there any way that will stop the relay after the full charged is complete?
It's turning off the relay for some times but it is not a permanent solution.
In my original circuit relay will be off when the battery is fully charged and remains off until the circuit restart
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?