Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Please help me to correct the code(I am using PIC16F688)

Status
Not open for further replies.
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.
 

Attachments

  • mikroC PRO PIC 6 Code + Proteus Sim rev1.rar
    62.4 KB · Views: 52

Thank you.I have edited and updated the program and it was working fine with simulator but when I tried the circuit on a breadboard,a portion of the program is not working.So I upgraded the PIC16F688 to PIC16F690,now its working fine( I am not sure about the program is perfect or not,but it is working fine),and there are some extra pins are available in 16F690 and I can use it to add some extra features in future.Now the only problem is with the load switch,the switch that I connected is an ON/OFF switch I want to replace it with a push button switch( I want to turn on the load in first pressing and turn off it in next pressing).if you don't mind could you please tell me about how can I do it?.I sending you the program,a working video and circuit
 

Attachments

  • ccu new1.rar
    764.3 KB · Views: 57

Which pin load controlling relay in connected to? Why you posted the old code when I have given you a new code yesterday? Does load controlling relay controlled manually through switch and also automatically depending upon adc value?
 

I have connected load controlling relay to RA4 and controlling switch to RA5.I am sorry but I don't know how to add these things in new program ,that is why I used the old one and the LED's are not working with new one,that LED's are very important actually they are some controlling relays(now I just used an LED for the ease of use,but when I design a final circuit I will use that LED connections to drive a MOSFET).Yeah,but the priority is for the adc value and also I want to control it with a manual switch(if the battery is low it must turn OFF irrespective of the switch position) .
 

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

How many Relays are there?

(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?
 

currently there are two relays in the circuit,one is for the solar charging ON/OFF and next one is for Load ON/OFF.And if possible I would like to add one extra load cicruit because in 16F690 there are extra 6 pins are avalable as compared with 16f688,so I think I can add one more load circuit with switch.SO there will be 3 realys

1-solar charging ON/OFF
2-Load1(output 1) ON/OFF
3-Load2(output2) ON/OFF

I want separate push button switches for load1 and load2 to control them
 

The details provided is not enough. Provide new circuit which has all the required components in PDF format. Then explain in detail how the system should work and what message(s) should be displayed on LCD and when. If both Loads are ON or OFF or one is ON and other OFF then what does the LCD display?

How the buttons work?

Read my previous 2 posts and answer to everything that has been asked. It seems that you need some free code to make some commercial product and you don't care about answering the questions asked.

Question asked in previous post

You mean auto off if battery low that is don't care for switch position if BAT is low?

Manual ON/OFF switch turn ON/OFF load irrespective of BAT voltage i.e., can the button turn ON Load if BAT V is < 10.8 and turn OFF Load if BAT V is > 10.8?
 

I am totally new to C. I am stuck as same, I was trying for a PWM Charging Controller but stumbled at battery full cut off. when my battery reach 14.4 the PWM = 0 but the moment the battery lowers then 14.4 the charger starts again.. off again and so on. the question is how can I:
when the battery reach 14.4 then the charger should stay off till 12.9 and start again at lower then 12.9???

int v1;
int v2;




void main() {
int a;
trisa= 0xff;
trisb = 0x00;
portb= 0x00;
adcon0= 0b00000001;
ANSEL= 0b00000001;
v1 = ADC_Read(0);


do {
v1 = ADC_Read(0);
delay_ms (20);
portb= 0xff; }
while (v1>=500);

do {
v2= adc_read(0);
delay_ms (20);
portb= 0;}
while (v2<=400);
while (1) ;

}
 

Try this...


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;
        }
    }
}

 
vola knock dead!!!! work like magic. but it will be a great deal to short explain the code's work.
thanks Milan.......:) you are the man.
 
Last edited:

pradeep hope i kno u..did u get the answer?
 

There was a mistake in previous code. The charging was stopping when BAT V is < 12.9. I have corrected it.


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;
        }
    }
}

 
I thought of that and was corrected as required of my own. thanks man!
 

but it will be a great deal to short explain the code's work.

1. 5V ADC input means 20V. So, You can make a voltage divider and divide 20V to 15 and 5 volts and provide 5V to ADC.

2. If V is >= 14.4 then Charging stops.

3. If V <= 12.9 Charging starts.
 
@Vignesh..Yeah ofc u know me...about 70% completed,but still there are some problems...
 

milan, citation needed... work fine for me, any other improvements?

12/24v PWM Based solar charge controller. PIC16f88/LCD/LED
Code:
/*///////////////////////////////////////////////////////////////////////////////
/                      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;
        }
    }      }
 

Needs some changes...

24.9 should be 24.8

Lcd_Out(1,9,"JAMAL SOLAR System Swabi");
LCD_out (2,10,"Ph:03449677909");

The string length exceeds 16X2 LCD length

Zip and post mikroC projects files so that changes can be done.
 

acknowledged attachment....
 

Attachments

  • pwm solar.rar
    2 KB · Views: 52

Any specific reason for not using IntToStr(), LongTostr(), FloatToStr()?
 

Any specific reason for not using IntToStr(), LongTostr(), FloatToStr()?

No, I am in learning stage.....

(actually I am an analogue guy and had a hand on Flow code, have just started C and still long way to cover the ground. its really difficult for my age, expertises and understandings. I think it's a long shot for me. but I'm obliged for your support and consideration. thanks indeed).
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top