milan.rajik
Banned
- Joined
- Apr 1, 2013
- Messages
- 2,524
- Helped
- 540
- Reputation
- 1,078
- Reaction score
- 524
- Trophy points
- 1,393
- Activity points
- 0
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I used the old one and the LED's are not working with new one
Add the LED codes as needed. I have not included them as you didn't care about mentioning the purpose of LEDs and its working.
actually they are some controlling relays
(if the battery is low it must turn OFF irrespective of the switch position)
You mean auto off if battery low that is don't care for switch position if BAT is low?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #define lower_threshold 12.9 #define upper_threshold 14.4 double v = 0.0, v_bckp = 0.0; unsigned char pwmDuty = 255; void main() { ANSEL= 0x01; TRISA = 0xFF; TRISB = 0x00; PORTA = 0x00; PORTB = 0x00; PWM1_Init(2000); PWM1_Set_Duty(0); PWM1_Start(); while(1) { v = ADC_Read(0) * 20.0 / 1023.0; //Max 20 V Delay_ms(20); if(v != v_bckp) { if(v >= upper_threshold) { PWM_Set_Duty(pwmDuty); //Code to execute when BAT V is >= 14.4 //here } else if(v <= lower_threshold) { PWM_Set_Duty(0); //Code to execute when BAT V is <= 12.9 //here } v = v_bckp; } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #define lower_threshold 12.9 #define upper_threshold 14.4 double v = 0.0, v_bckp = 0.0; unsigned char pwmDuty = 255; void main() { ANSEL = 0x01; TRISA = 0xFF; TRISB = 0x00; PORTA = 0x00; PORTB = 0x00; PWM1_Init(2000); PWM1_Set_Duty(255); PWM1_Stop(); while(1) { v = ADC_Read(0) * 20.0 / 1023.0; //Max 20 V Delay_ms(20); if(v != v_bckp) { if(v >= upper_threshold) { PWM_Stop(); //Code to execute when BAT V is >= 14.4 //here } else if(v <= lower_threshold) { PWM_Start(); //Code to execute when BAT V is <= 12.9 //here } v = v_bckp; } } }
but it will be a great deal to short explain the code's work.
/*///////////////////////////////////////////////////////////////////////////////
/ PWM Based Soler Charge controller /
/ CPU: PIC16F88 /
/ Compilor: MikroC /
/ Authour: milan.rajik @ Edaboard.com / Amjad Ali /
Dated: 29/04/2014 */
////////////////////////////////////////////////////////////////////////////////
sbit LCD_RS at RA7_bit; sbit LCD_EN at RA6_bit;
sbit LCD_D7 at RB4_bit; sbit LCD_D6 at RB5_bit;
sbit LCD_D5 at RB6_bit; sbit LCD_D4 at RB7_bit;
sbit LCD_RS_Direction at TRISA7_bit;
sbit LCD_EN_Direction at TRISA6_bit;
sbit LCD_D7_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB7_bit;
#define lower_threshold 24.9 //for 12v change it to 12.4
#define upper_threshold 28.4 // for 12v chnge it to 14.2
double v = 0.0, v_bckp = 0.0;
int v1, j, i;
unsigned int v2,vp;
char *volt = "00.0";
char look(int a)
{
switch(a)
{
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
case 4:
return '4';
case 5:
return '5';
case 6:
return '6';
case 7:
return '7';
case 8:
return '8';
case 9:
return '9';
default:
return '.';
}
}
void chrg(){
Lcd_Out(1,1," CHARGING " );
delay_ms(1);
Lcd_Out(1,1," (CHARGING) ");
delay_ms(1);
Lcd_Out(1,1," ((CHARGING)) ");
delay_ms(1);
Lcd_Out(1,1," (((CHARGING))) ");
delay_ms(1);
Lcd_Out(1,1,"((((CHARGING))))");
delay_ms(1);
}
void lcd() {
v2 = ADC_Read(0);
v2 = ((v2*4.89)/20)*120;
vp = v2;
volt[0] = look(v2/10000);
volt[1] = look((v2/1000)%10);
volt[3] = look((v2/100)%10);
Lcd_Out(2,1,"BATTERY:");
Lcd_Out(2,11,volt);
Lcd_Out(2,16,"V");
}
void main() {
ANSEL= 0x01;
TRISA = 0x01;
TRISB = 0x00;
PORTB = 0x00;
PWM1_Init(4000);
PWM1_Set_Duty(0);
PWM1_Start();
PORTA= 0X32;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,9,"JAMAL SOLAR System Swabi");
LCD_out (2,10,"Ph:03449677909");
for(j=0; j<50; j++)
{
Lcd_Cmd(_LCD_SHIFT_LEFT);
delay_ms (1);
}
lcd_cmd(_lcd_clear);
while(1) {
v = ADC_Read(0) * 30.0 / 1023.0; // " v = ADC_Read(0) * 20.0 / 1023.0; " //for 12v
Delay_ms(20);
if(v != v_bckp) {
if(v >= upper_threshold) {
portb=0x04;
pwm1_set_duty(0);
lcd();
Lcd_Out(1,1,"**BATTERY FULL**"); delay_ms(200);
}
else if(v <= lower_threshold) {
do {
v1=ADC_Read(0) ;
v1=v1/2; // For 24v/ for 12v remove it.
delay_ms(20);
portb=0x03;
lcd(); chrg();
if(v1<=357){
Lcd_Out(1,1,"**BAD CHARGING**");
pwm1_set_duty(0);
portb=0x08; delay_ms (100);
}
else if(v1>358 && v1<=436){ pwm1_set_duty(240); }
else if(v1>437 && v1<=450){pwm1_set_duty(230); }
if(v1>451 && v1<=460){pwm1_set_duty(190); }
else if(v1>461 && v1<487){pwm1_set_duty(30); }
else if (v1>=488 ); } while (v1<=488);
}
v = v_bckp;
}
} }
Any specific reason for not using IntToStr(), LongTostr(), FloatToStr()?