There are 3 things. Solar Panel, battery and Load that is light or LED. Now requirement is when solar panel ADC value is near about 0, i.e at evening or night at that time battery charging should be OFF and LOAD should be ON. Now once load is ON, so it should remain ON till panel ADC value is near about 10, assuming that its a day time. Now when Solar panel value is above 9V battery charging will be OFF but if battery is fully charged i.e battery ADC value is near about 462, battery charging should be OFF. Now what happens as you know as battery volt gets down so intensity of LOAD or light reduces so here we have to implement PWM for battery voltage of 13V to atleast 10.50V so that intensity should remain somewhat constant. LOAD is getting ON/OFF only because of Solar panel value and nothing else.
- - - Updated - - -
For this code also, LOAD gets dim near about 9.20V of battery voltage and gets completely OFF at 7V. Now while increasing battery voltage same condition, initially its dim at near about 8V and then intensity goes on increasing. Still LOAD not getting switch OFF at Solar Panel voltage of 9V and above.
//#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#define ON 0
#define OFF 1
#define timer_val 0
#define BATTERY_CHARGE PORTC.B5
#define LOAD PORTC.B4
unsigned int Panel_Value, Battery_Value,FLAG_1=0,FLAG_2=0,FLAG_3,FLAG_4,FLAG_5,FLAG_6,FLAG_7,FLAG_8;
unsigned int count_on,count_off;
//int OnPulse = 217;
//int OffPulse = 38;
//char TOG = 0;
unsigned int i = 305,j=1, factor = 0,divide_val=0,k=14,l=3;
void panel_check();
void battery_check();
void interrupt timer0_ISR()
{
if(INTCON.T0IF)
T0IF_bit = 0;
if(FLAG_1 == 1)
{
TMR0 = 255-divide_val;
LOAD = OFF;
FLAG_1 = 0;
}
else
{
TMR0 = divide_val;
LOAD = ON;
FLAG_1 = 1;
}
}
}
void main()
{
TRISA = 0xff; //port A as input
TRISC = 0x00; //port C as output
PORTC = 0x00; //INITIAL VALUE ON PORTC
ADCON0 = 0b00000000; //Left Justified
ADCON1 = 0b00110000; //Clock derived from internal RC oscilator
ANSEL = 0b00000011; //channel AN0 and AN1 as analog input
// INTCON = 0b10100000;
INTCON.T0IF = 0;
T0CS_bit = 0;
PSA_bit = 0; //Prescaler is assigned to Timer0 module
PS0_bit = 0; //TMR0 rate 1:1
PS1_bit = 0;
PS2_bit = 0;
while(1)
{
Panel_Value = ADC_Read(0);
Battery_Value = ADC_Read(1);
panel_check();
}
}
void panel_check()
{
/**Batterry charge condition**/
if(Panel_value >= 122 && Battery_Value <= 430) //AD Value for 3 volt
BATTERY_CHARGE = ON;
else if(Panel_Value <= 30 || Battery_Value > 430) //Panel AD value for 1v <=40
BATTERY_CHARGE = OFF;
/**LOAD ON/OFF condition**/
if(Panel_Value > 321) //Panel Voltage 9 v
{
LOAD = OFF;
INTCON = 0;
}
else
battery_check();
}
void battery_check()
{
/**Condition for LED brightness adjustment Between 13V and 10.5V battery voltages**/
if(Battery_Value > 310)
{
INTCON = 0b10100000;
divide_val = (Battery_Value-310)*255/425;
if(FLAG_1 == 1)
}
else
/**Battery voltage below 10.5V condition**/
{
LOAD = OFF;
INTCON = 0;
}
}
In battery_check condition do we have to make FLAG_ =0 again? I did that, still not working. Still LOAD getting ON/OFF at undesired voltages but intensity getting manage satisfactorily up to 10.50V.After that it gets dimmer and dimmer and ultimately OFF. Reverse process is there when battery voltage increases. And load not getting OFF when Panel voltage increases. What to do now?
#define ON 0
#define OFF 1
#define timer_val 0
#define BATTERY_CHARGE PORTC.B5
#define LOAD PORTC.B4
unsigned int Panel_Value, Battery_Value,FLAG_1=0,FLAG_2=0,FLAG_3,FLAG_4,FLAG_5,FLAG_6,FLAG_7,FLAG_8;
unsigned int count_on,count_off;
//int OnPulse = 217;
//int OffPulse = 38;
//char TOG = 0;
unsigned int i = 305,j=1, factor = 0,divide_val=0,k=14,l=3;
void panel_check();
void battery_check();
void interrupt ()
{
if(INTCON.T0IF)
T0IF_bit = 0;
if(FLAG_1 == 1)
{
TMR0 = 255-divide_val;
LOAD = OFF;
FLAG_1 = 0;
}
else
{
TMR0 = divide_val;
LOAD = ON;
FLAG_1 = 1;
}
}
void main()
{
TRISA = 0xff; //port A as input
TRISC = 0x00; //port C as output
PORTC = 0x00; //INITIAL VALUE ON PORTC
ADCON0 = 0b00000000; //Left Justified
ADCON1 = 0b00110000; //Clock derived from internal RC oscilator
ANSEL = 0b00000011; //channel AN0 and AN1 as analog input
// INTCON = 0b10100000;
INTCON.T0IF = 0;
T0CS_bit = 0;
PSA_bit = 0; //Prescaler is assigned to Timer0 module
PS0_bit = 0; //TMR0 rate 1:1
PS1_bit = 0;
PS2_bit = 0;
while(1)
{
Panel_Value = ADC_Read(0);
Battery_Value = ADC_Read(1);
panel_check();
}
}
void panel_check()
{
/**Batterry charge condition**/
if(Panel_value >= 122 && Battery_Value <= 430) //AD Value for 3 volt
BATTERY_CHARGE = ON;
else if(Panel_Value <= 30 || Battery_Value > 430) //Panel AD value for 1v <=40
BATTERY_CHARGE = OFF;
/**LOAD ON/OFF condition**/
if(Panel_Value > 321) //Panel Voltage 9 v
{
LOAD = OFF;
INTCON = 0;
}
else
battery_check();
}
void battery_check()
{
/**Condition for LED brightness adjustment Between 13V and 10.5V battery voltages**/
if(Battery_Value > 321)
{
INTCON = 0b10100000;
divide_val = (Battery_Value-321)*255/462;
if(FLAG_1 == 1){
FLAG_1 = 0;
}
}
else if(Battery_Value < 321){
/**Battery voltage below 10.5V condition**/
INTCON = 0;
while(Battery_Value <= 440){
LOAD = OFF;
Battery_Value = ADC_Read(1);
}
}
}
#define ON 0
#define OFF 1
#define timer_val 0
#define BATTERY_CHARGE PORTC.B5
#define LOAD PORTC.B4
unsigned int Panel_Value, Battery_Value,FLAG_1=0,FLAG_2=0,FLAG_3,FLAG_4,FLAG_5,FLAG_6,FLAG_7,FLAG_8;
unsigned int count_on,count_off;
//int OnPulse = 217;
//int OffPulse = 38;
//char TOG = 0;
unsigned int i = 305,j=1, factor = 0,divide_val=0,k=14,l=3;
void panel_check();
void battery_check();
void interrupt ()
{
if(INTCON.T0IF)
T0IF_bit = 0;
if(FLAG_1 == 1)
{
TMR0 = 255-divide_val;
LOAD = OFF;
FLAG_1 = 0;
}
else
{
TMR0 = divide_val;
LOAD = ON;
FLAG_1 = 1;
}
}
void main()
{
TRISA = 0xff; //port A as input
TRISC = 0x00; //port C as output
PORTC = 0x00; //INITIAL VALUE ON PORTC
ADCON0 = 0b00000000; //Left Justified
ADCON1 = 0b00110000; //Clock derived from internal RC oscilator
ANSEL = 0b00000011; //channel AN0 and AN1 as analog input
// INTCON = 0b10100000;
INTCON.T0IF = 0;
T0CS_bit = 0;
PSA_bit = 0; //Prescaler is assigned to Timer0 module
PS0_bit = 0; //TMR0 rate 1:1
PS1_bit = 0;
PS2_bit = 0;
while(1)
{
Panel_Value = ADC_Read(0);
Battery_Value = ADC_Read(1);
panel_check();
}
}
void panel_check()
{
/**Batterry charge condition**/
if(Panel_value >= 122 && Battery_Value <= 430) //AD Value for 3 volt
BATTERY_CHARGE = ON;
else if(Panel_Value <= 30 || Battery_Value > 430) //Panel AD value for 1v <=40
BATTERY_CHARGE = OFF;
/**LOAD ON/OFF condition**/
if(Panel_Value > 122) //Panel Voltage 3 v
{
LOAD = OFF;
INTCON = 0;
}
if(Panel_Value < 35) /*********LOAD should ON below 1V of panel Volt************/
{
LOAD = ON;
INTCON = 0;
}
else
battery_check();
}
void battery_check()
{
/**Condition for LED brightness adjustment Between 13V and 10.5V battery voltages**/
if(Battery_Value > 321)
{
INTCON = 0b10100000;
divide_val = (Battery_Value-321)*255/462;
if(FLAG_1 == 1){
FLAG_1 = 0;
}
}
else if(Battery_Value < 321){
/**Battery voltage below 10.5V condition**/
INTCON = 0;
while(Battery_Value <= 440){
LOAD = OFF;
Battery_Value = ADC_Read(1);
}
}
}
Code C - [expand] 1 if(Panel_Value < 35)
Code C - [expand] 1 CMCON = 0x07;
Hi mathsbe
I am again facing some issue in this program. Requirement is LOAD should get OFF above 3v of panel voltage. I wrote that and its working. Now LOAD should get ON below 1V of panel voltage. In present code LOAD is getting ON at 2.50V of panel voltage. I tried to do that but not working. Here is the code
Code:#define ON 0 #define OFF 1 #define timer_val 0 #define BATTERY_CHARGE PORTC.B5 #define LOAD PORTC.B4 unsigned int Panel_Value, Battery_Value,FLAG_1=0,FLAG_2=0,FLAG_3,FLAG_4,FLAG_5,FLAG_6,FLAG_7,FLAG_8; unsigned int count_on,count_off; //int OnPulse = 217; //int OffPulse = 38; //char TOG = 0; unsigned int i = 305,j=1, factor = 0,divide_val=0,k=14,l=3; void panel_check(); void battery_check(); void interrupt () { if(INTCON.T0IF) T0IF_bit = 0; if(FLAG_1 == 1) { TMR0 = 255-divide_val; LOAD = OFF; FLAG_1 = 0; } else { TMR0 = divide_val; LOAD = ON; FLAG_1 = 1; } } void main() { TRISA = 0xff; //port A as input TRISC = 0x00; //port C as output PORTC = 0x00; //INITIAL VALUE ON PORTC ADCON0 = 0b00000000; //Left Justified ADCON1 = 0b00110000; //Clock derived from internal RC oscilator ANSEL = 0b00000011; //channel AN0 and AN1 as analog input // INTCON = 0b10100000; INTCON.T0IF = 0; T0CS_bit = 0; PSA_bit = 0; //Prescaler is assigned to Timer0 module PS0_bit = 0; //TMR0 rate 1:1 PS1_bit = 0; PS2_bit = 0; while(1) { Panel_Value = ADC_Read(0); Battery_Value = ADC_Read(1); panel_check(); } } void panel_check() { /**Batterry charge condition**/ if(Panel_value >= 122 && Battery_Value <= 430) //AD Value for 3 volt BATTERY_CHARGE = ON; else if(Panel_Value <= 30 || Battery_Value > 430) //Panel AD value for 1v <=40 BATTERY_CHARGE = OFF; /**LOAD ON/OFF condition**/ if(Panel_Value > 122) //Panel Voltage 3 v { LOAD = OFF; INTCON = 0; } if(Panel_Value < 35) /*********LOAD should ON below 1V of panel Volt************/ { LOAD = ON; INTCON = 0; } else battery_check(); } void battery_check() { /**Condition for LED brightness adjustment Between 13V and 10.5V battery voltages**/ if(Battery_Value > 321) { INTCON = 0b10100000; divide_val = (Battery_Value-321)*255/462; if(FLAG_1 == 1){ FLAG_1 = 0; } } else if(Battery_Value < 321){ /**Battery voltage below 10.5V condition**/ INTCON = 0; while(Battery_Value <= 440){ LOAD = OFF; Battery_Value = ADC_Read(1); } } }
Plz guide me on this.
if(Panel_Value < 35) /*********LOAD should ON below 1V of panel Volt************/
{
LOAD = ON;
INTCON = 0b10100000;
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 void interrupt () { if(INTCON.T0IF) T0IF_bit = 0; if(FLAG_1 == 1) { TMR0 = 255-divide_val; LOAD = OFF; FLAG_1 = 0; } else { TMR0 = divide_val; LOAD = ON; FLAG_1 = 1; } }
#define ON 0
#define OFF 1
#define timer_val 0
#define BATTERY_CHARGE PORTC.B5
#define LOAD PORTC.B4
unsigned int Panel_Value, Battery_Value,FLAG_1=0,FLAG_2=0,FLAG_3,FLAG_4,FLAG_5,FLAG_6,FLAG_7,FLAG_8;
unsigned int count_on,count_off;
unsigned int i = 305,j=1, factor = 0,divide_val=0,k=14,l=3;
void panel_check();
void battery_check();
void interrupt ()
{
if(INTCON.T0IF)
T0IF_bit = 0;
if(FLAG_1 == 1)
{
TMR0 = 255-divide_val;
LOAD = OFF;
FLAG_1 = 0;
}
else
{
TMR0 = divide_val;
LOAD = ON;
FLAG_1 = 1;
}
}
void main()
{
TRISA = 0xff; //port A as input
TRISC = 0x00; //port C as output
PORTC = 0x00; //INITIAL VALUE ON PORTC
ADCON0 = 0b00000000; //Left Justified
ADCON1 = 0b00110000; //Clock derived from internal RC oscilator
ANSEL = 0b00000011; //channel AN0 and AN1 as analog input
CMCON = 0x07;
// INTCON = 0b10100000;
INTCON.T0IF = 0;
T0CS_bit = 0;
PSA_bit = 0; //Prescaler is assigned to Timer0 module
PS0_bit = 0; //TMR0 rate 1:1
PS1_bit = 0;
PS2_bit = 0;
while(1)
{
Panel_Value = ADC_Read(0);
Battery_Value = ADC_Read(1);
panel_check();
}
}
void panel_check()
{
/**Batterry charge condition**/
if(Panel_value >= 122 && Battery_Value <= 430) //Panel AD Value for 3 volt
BATTERY_CHARGE = ON;
else if(Panel_Value <= 122 || Battery_Value > 430) //Panel AD value for 3V
BATTERY_CHARGE = OFF;
/**LOAD ON/OFF condition**/
if(Panel_Value > 122) //Panel Voltage 3 v
{
LOAD = OFF;
INTCON = 0;
}
/*if(Panel_Value < 35)
{
//LOAD = ON;
INTCON = 0b10100000;
}*/
else
battery_check();
}
void battery_check()
{
/**Condition for LED brightness adjustment Between 13V and 10.5V battery voltages**/
if(Battery_Value > 321)
{
//FLAG_1 = 1;
INTCON = 0b10100000;
divide_val = (Battery_Value-321)*255/462;
//LOAD = ON;
if(FLAG_1 == 1){
FLAG_1 = 0;
}
}
else if(Battery_Value < 321){
/**Battery voltage below 10.5V condition**/
INTCON = 0;
while(Battery_Value <= 440){
LOAD = OFF;
Battery_Value = ADC_Read(1);
}
}
}
void battery_check()
{
/**Condition for LED brightness adjustment Between 13V and 10.5V battery voltages**/
if(Battery_Value > 321)
{
//FLAG_1 = 1;
INTCON = 0b10100000;//////////////Timer0 interrupt starts/////////////////
divide_val = (Battery_Value-321)*255/462;
//LOAD = ON;
if(FLAG_1 == 1){
FLAG_1 = 0;
}
}
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?