avrsanju
Junior Member level 3
hai,
after a lot of requests from the readers side, i am posting the sine wave ups source code written in mplab c-30 here.. this product is widely marketed by 2 persons in my country. as i am not a business man, i can share my know how to all without any charge. the another versions of these types up to 72 volt and transformer less hybrid modes are also developed and redy to share here. SOLAR zero drop charger, dspic based M.P.PT, and many more i have developed already and any body can download and use it...and one more thing, ask me for any droughts in my software.
[edit: removed mail address]
iam living in kerala(india)and doing hobby in electronics last 20 years.
- - - Updated - - -
the main file is here.
after a lot of requests from the readers side, i am posting the sine wave ups source code written in mplab c-30 here.. this product is widely marketed by 2 persons in my country. as i am not a business man, i can share my know how to all without any charge. the another versions of these types up to 72 volt and transformer less hybrid modes are also developed and redy to share here. SOLAR zero drop charger, dspic based M.P.PT, and many more i have developed already and any body can download and use it...and one more thing, ask me for any droughts in my software.
[edit: removed mail address]
iam living in kerala(india)and doing hobby in electronics last 20 years.
- - - Updated - - -
hai,
after a lot of requests from the readers side, i am posting the sine wave ups source code written in mplab c-30 here.. this product is widely marketed by 2 persons in my country. as i am not a business man, i can share my know how to all without any charge. the another versions of these types up to 72 volt and transformer less hybrid modes are also developed and redy to share here. SOLAR zero drop charger, dspic based M.P.PT, and many more i have developed already and any body can download and use it...and one more thing, ask me for any droughts in my software.
[edit: removed mail address]
iam living in kerala(india)and doing hobby in electronics last 20 years.
the main file is here.
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 //////////////////////////////////////////////////////////////////////18-7-overtime/ok all #include <p30f2010.h> #include <libpic30.h> #include "DataEEPROM.h" _FOSC(CSW_ON_FSCM_OFF & XT_PLL16); _FWDT(WDT_OFF); _FBORPOR(MCLR_EN & PBOR_ON & BORV_42 & RST_PWMPIN & PWMxH_ACT_HI & PWMxL_ACT_HI); _FGS (CODE_PROT_ON); #define faultin LATEbits.LATE8 #define buzzer LATEbits.LATE4 #define change LATDbits.LATD1 #define stbyinv 1 #define upsmode 2 #define invmode 3 #define modekey 4 #define upkey 5 #define downkey 6 #define stbyups 7 #define fanheat 640 /////////////////////////////////////////////////////////////////////////////////////////// const signed int sine_table[91]={0,174,348,523,697,871,1045,1218,1391,1564,1736,1908,2079,2249,2419,2588,2756,2923,3090, 3255,3420,3583,3746,3907,4067,4226,4383,4539,4694,4848,5000,5150,5299,5446, 5591,5735,5877,6018,6156,6293,6427,6560,6691,6819,6946,7071,7193,7313,7431,7547,7660,7771, 7880,7986,8090,8191,8290,8386,8480,8571,8660,8746,8829,8910,8987,9063,9135,9205,9271,9335, 9396,9455,9510,9563,9612,9659,9702,9743,9781,9616,9848,9876,9902,9925,9945,9961,9975,9986, 9993,10000,10000}; signed int factory[16]={0,0,100,350,220,80,265,180,270,100,142,108,100,115,5000}; signed int setting[16]; char arr[4]; struct { unsigned int frstdisp:1; unsigned int setup:1; unsigned int gravity:1; unsigned int onflag:1; unsigned int vcorrect:1; unsigned int chrcorrect:1; unsigned int chon:1; unsigned int swon:1; unsigned int nofeed:1; unsigned int shorttrip:1; unsigned int zincfail:1; unsigned int mainsok:1; unsigned int lbwarn:1; unsigned int olwarn:1; unsigned int olcut:1; unsigned int lbcut:1; unsigned int fault:1; unsigned int hiload:1; unsigned int msgrtn:1; unsigned int chrmsgrtn:1; unsigned int firston:1; }flags; int chshoot; int chshootdly=0; int flicker=0; int *adjust; int *ptr; int adj; int *value; int chadj; int champs1; signed int duty_cycle_1; signed int p=0,flag=1,rising=1; signed int pr=0,kflag=1,rising1=1; int amplitude=0; int pb,qb,cth,ctl; //////////////////////////////// unsigned int setdly; unsigned int menudelay; unsigned int lcdtmr; unsigned int counter; unsigned int resumedelay; unsigned int buzzcount; unsigned int buzzdelay; unsigned int buzzoftme; unsigned int buzzontme; unsigned int peakfail; unsigned int oldelay; unsigned int tripdly; unsigned int round; unsigned int chrdly; unsigned int slowdly; unsigned int fbdly; unsigned int ctfaildly; unsigned int deadshortdly; unsigned int lbdly; unsigned int acdly; unsigned int keydly; unsigned int msgrtndly; unsigned int gravitydly; unsigned int fltdly; unsigned int blinkdly; unsigned int startdly; //////////////////////////////// unsigned long endtimer; unsigned long controlavg; unsigned long mainsavg; unsigned long outavg; unsigned long wattsavg; unsigned long batavg; unsigned long keyavg; unsigned long heatavg; unsigned int modeavg; ///////////////////////////////// unsigned int indummy; unsigned int outdummy; unsigned int ctdummy; unsigned int keys; unsigned int ntcvalue; unsigned int batts; unsigned int batrecharge; ////////////////////////////////// unsigned int loaddisp; unsigned int acoutdisp; unsigned int mainsdisp; unsigned int battdisp; unsigned int battvolts; unsigned int batrestart; unsigned int loadpercent; unsigned int champs; unsigned int chdisp; unsigned int mainsvolt; unsigned int acout; unsigned int keyvalue; unsigned int key; unsigned int heat; unsigned int post; unsigned int err; unsigned int cherr; unsigned int prect; /////////////////////////////////// signed int upspeak; signed int acpeak; signed int ctpeak; signed int batclb; signed int mainsclb; unsigned int chrclb; unsigned int loadclb; unsigned int pdctemp; //////////////////////////////////// unsigned int deadshort; unsigned int controlvolt; unsigned int setvout; unsigned int setchramp; unsigned int setoverload; unsigned int setupshi; unsigned int setupslo; unsigned int setinvhi; unsigned int setinvlo; unsigned int setbatful; unsigned int setbatwrn; unsigned int setbatlo; unsigned int setbatres; unsigned int defaults; ///////////////////////////////////// unsigned int x,y,u; unsigned long Ax,bx; unsigned int aclo; unsigned int achi; unsigned int zinc; ///////////////////////////////////// void InitADC1(); extern void Eeprom_WriteWord(unsigned short pushAddressOffset, unsigned short value); extern unsigned short Eeprom_ReadWord(unsigned short pushAddressOffset); void delay_ms(unsigned int gs); void delay_us(unsigned int gs); /////////////////////////////////////////////// const char str0[17]= "CALIBRATION MENU"; const char str20[17]="BATTERY V: V"; const char str21[17]="INVERTER MODE ON"; const char str22[17]=" U.P.S MODE ON "; const char str23[17]=" SBY SWITCH OFF "; const char str24[17]=" SBY SWITCH ON "; const char str25[17]="MAINS VOLT: V"; const char str26[17]="INVERTER V: V"; const char str27[17]="TOTAL LOAD: %"; ////////////////////////////////////////// //const char str28[17]=" TRIP:C-T FAULT "; const char str29[17]="TRIP:LOW-BATTERY"; const char str30[17]=" TRIP:OVERLOAD "; const char str31[17]="SHORT CKT FAULT"; const char str32[17]="WARN:LOW-BATTERY"; const char str33[17]=" WARN:OVERLOAD "; const char str34[17]=" TRIP:F-B FAULT "; const char str35[17]="TRIP:SYNC FAULT "; const char str36[17]="AC CHARGR: A"; const char str38[17]=" DSP SINEWAVE "; #include "lcdsoft.h" #include "functions.h" void clear_flag(); void trip(int s); int getvalue(int ch); void chargeron(); void chroff(); void invon(); void invoff(); void stabilise(); void Modulate(); void find_key(); int findpeak(int ct); void mains_stat_check(); void find_mainsvolt(); void find_batvolt(); void find_champs(); void find_upsvolt(); void find_load(); void overload_check(); void lobat_check(); void chr_stabilize(); //////////////////////////////////// void feed_buzz(int a,int b,int c) { buzzdelay=0; buzzoftme=b; buzzontme=a; buzzcount=c; } ////////////////////////////////////////////////////// void __attribute__((__interrupt__,no_auto_psv)) _FLTAInterrupt(void) { _FLTAIF = 0; } ////////////////////////////////////////////////////////// void __attribute__((__interrupt__, __auto_psv__)) _T1Interrupt(void) { _T1IF = 0; // Clear interrupt flag if(PORTEbits.RE8==0) { fltdly++; if(fltdly>3000) { flags.olcut=1; __asm__ volatile ("reset"); } } counter++; acpeak=getvalue(0); //4.4 us indummy=acpeak; acpeak=indummy-508; if(acpeak<0) { acpeak=508-indummy; if(!flags.onflag) { rising=0; flag=0; } } mainsavg+=acpeak; if(flags.setup) { OVDCON= 0X0000; change=0; buzzer=0; } if(!flags.setup) { if((indummy<600)&&(indummy>400)&&(flags.swon)) { if(peakfail<150) { peakfail++; } if(peakfail==149) { if(flags.vcorrect) { invon(150); } } } else { peakfail=0; } if(flags.onflag) { Modulate(); //4.4 us upspeak=getvalue(1); //4.4 us outdummy=upspeak; upspeak=outdummy-508; if(upspeak<0) upspeak=508-outdummy; outavg+=upspeak; if(upspeak<150) { fbdly++; if(fbdly>30000) { flags.fault=1; trip(5); } } else fbdly=0; } else { rising=1; flag=1; loadpercent=0; acout=0; } ctpeak=getvalue(2); if(flags.onflag) { if((ctpeak>750)||(ctpeak<250)) { deadshortdly++; if(deadshortdly>1500) { deadshort=1; OVDCON= 0X0000; trip(1); } } } else { if(flags.chon==1) { if((ctpeak<508)||(ctpeak>512)) ctfaildly=0; else { ctfaildly++; if(ctfaildly>10000) { chroff(); } } } } if(ctpeak>506) { pb=ctpeak-506; if(cth<pb) cth=pb; } if(ctpeak<506) { qb=506-ctpeak; if(ctl<qb) ctl=qb; } wattsavg+=cth+ctl; ctl=cth=0; heat=getvalue(3); } batavg+=getvalue(5); lcdtmr++; if(counter==359)////////////////////// 20 milli sec { mainsvolt=__builtin_divud(mainsavg,288)+mainsclb; //2.2 microseconds mainsavg=0; if(mainsvolt<90) { mainsvolt=0; mainsdisp=0; } else { if((indummy>180)&&(indummy<900)) { if(mainsdisp==0) { mainsdisp=mainsvolt-80; } if(mainsdisp<mainsvolt-2) { mainsdisp++; } if(mainsdisp>mainsvolt+2) { mainsdisp--; } } } find_batvolt(); keyavg+=getvalue(4); keydly++; if(keydly==10) find_key(); if(!flags.setup) { mains_stat_check(); if(flags.onflag==1) { acout=__builtin_divud(outavg,285); outavg=0; if(acoutdisp<acout-2) acoutdisp++; if(acoutdisp>acout+2) acoutdisp--; find_load(); overload_check(); lobat_check(); } } wattsavg=0; if(buzzcount>0) { buzzdelay++; if(buzzdelay<=buzzontme) buzzer=1; else { buzzer=0; if(buzzdelay>=buzzoftme) { buzzdelay=0; buzzcount--; fltdly=0; } } } else { FLTACON=0x0001; IEC2bits.FLTAIE = 1; if(round>0) { if((!flags.onflag)&&(flags.swon)&&(round<4)) { if(mainsvolt<110) { clear_flag(); invon(0); } } } if(round==4) change=0; } if(!flags.setup) { if((resumedelay==200)||(flags.mainsok==1)) { LCD_DB6=1; if(flags.swon==1) { blinkdly++; if(blinkdly<30) LCD_DB7=1; else LCD_DB7=0; if(blinkdly>60) blinkdly=0; } else LCD_DB7=0; } else { LCD_DB6=0; if(flags.onflag==1) LCD_DB7=1; else LCD_DB7=0; } } counter=0; if((key==modekey)&&(flags.setup==0)) { menudelay++; if(menudelay>124) flags.setup=1; } else menudelay=0; if(flags.setup==1) { setdly++; if(setdly>3000) __asm__ volatile ("reset"); } } cherr=mainsvolt; } ////////////////////////////////////// void init_PWM() { PTCON= 0XE003; PTMR = 0x0000; PTPER = PDC1=PDC2= 1230; SEVTCMP = 0x0000; PWMCON1 = 0x0033; PWMCON2 = 0x0000; DTCON1= 0X0059; FLTACON = 0x0000; OVDCON= 0X0000; PTCONbits.PTEN = 1; IEC2bits.PWMIE = 0; // disable PWM interrupts T1CON = 0XE000; TMR1 = 0; PR1 = 1355; _T1IF = 0; _T1IE = 1; } ///////////////////////////////////////////////// void memread() { int x; for(x=0;x<15;x++) { setting[x]=Eeprom_ReadWord(x); } } ////////////////////////////////////////////////////////// void memwrite() { int x; for(x=0;x<15;x++) { if(flags.setup==0) Eeprom_WriteWord(x,factory[x]); else Eeprom_WriteWord(x,setting[x]); } } ////////////////////////////////////////////// void modedisp() { if(flags.msgrtn) return; if((key==upsmode)||(key==stbyups)) { printmes(str22,100); //"\fU.P.S MODE ON"; if(key==upsmode) { aclo=setupslo; achi=setupshi; } } if((key==invmode)||(key==stbyinv)) printmes(str21,100); //"\fINVERTER MODE ON"; } ////////////////////////////////////////////////////// void swdisp() { if(flags.msgrtn) return; if((key==stbyinv)||(key==stbyups)) //"\fSBY SWITCH OFF"; { printmes(str23,100); aclo=setinvlo; achi=setinvhi; } if((key==upsmode)||(key==invmode)) printmes(str24,100); //"\fSBY SWITCH ON"; } // MAIN ROUTINE //*****************************************************************************/ int main() { TRISF=0X0000; TRISE=0X010F; TRISD=0X0000; TRISC=0X0000; TRISB=0XFFFF; OVDCON=0X0000; PWMCON1 = 0x0000; PTCONbits.PTEN = 0; buzzer=0; lcd_init(); InitADC1(); init_PWM(); keyvalue=getvalue(4); if(((keyvalue>660)&&(keyvalue<680))||((keyvalue>560)&&(keyvalue<575))) { flags.swon=1; flags.firston=1; } prect=getvalue(2); flags.frstdisp=0; defaults=Eeprom_ReadWord(14); if(defaults!=50) { memwrite(); } memread(); batclb=setting[0]; mainsclb=setting[1]; chrclb=setting[2]; loadclb=700-setting[3]; setvout=setting[4]; setchramp=setting[5]; chshoot=setchramp; setchramp+=30; setupshi=setting[6]; setupslo=setting[7]; setinvhi=setting[8]; setinvlo=setting[9]; setbatful=setting[10]; setbatwrn=setting[11]; setbatlo=setting[12]; setbatres=setting[13]; defaults=setting[14]; battdisp=90; aclo=setinvlo; achi=setinvhi; batrestart=setbatful-13; menudelay=0; while(1) { //lcd_init(); // //while(1) //{ //lcd_init(); //printmes(str36,3); //"AC CHARGR:"; //flags.msgrtn=0; ////printmes(str20,1); //"\fBATTERY V:"; // //printmes(str25,2); //"\fMAINS VOLT:"; //printmes(str27,4); //"\fTOTAL LOAD:"; // ////printmes(str23,0); //// //printmes(str24,100); //"\fSBY SWITCH ON"; //// //// //// //printmes(str26,0); //"\fINVERTER V:"; //// ////printmes(str27,4); //"\fTOTAL LOAD:"; // // // // // //} // while(PORTEbits.RE8==0) { flags.msgrtn=0; printmes(str31,100); // SHORT CKT FAULT if(flags.swon==0) __asm__ volatile ("reset"); } while(flags.nofeed==1) { flags.msgrtn=0; printmes(str34,100); // NO FEED BACK if(flags.swon==0) __asm__ volatile ("reset"); } //while(flags.ctfail==1) //{ // flags.msgrtn=0; //printmes(str28,100); // TRIP:C-T FAULT //if(flags.swon==0) //__asm__ volatile ("reset"); //} while(flags.zincfail==1) { flags.msgrtn=0; printmes(str35,100); // TRIP:SYNC FAULT! if(flags.swon==0) __asm__ volatile ("reset"); flags.fault=1; } while(flags.lbcut==1) { flags.msgrtn=0; printmes(str29,100); //" TRIP:LOW-BATTERY "; if((flags.swon==0)||(resumedelay>175)) __asm__ volatile ("reset"); } while(flags.olcut==1) { flags.msgrtn=0; printmes(str30,100); //" TRIP:OVER-LOAD "; if((flags.swon==0)||(resumedelay>175)) __asm__ volatile ("reset"); } while(flags.olwarn) { flags.msgrtn=0; printmes(str33,100); //" WARN:OVER-LOAD "; if(flags.swon==0) __asm__ volatile ("reset"); } while(flags.lbwarn==1) { flags.msgrtn=0; printmes(str32,100); //"WARN:LOW-BATTERY"; if(flags.swon==0) __asm__ volatile ("reset"); } printmes(str20,1); // 0/0/"\fBATTERY V:"; if(flags.chon==1) { if(champs==0) goto outmes; printmes(str36,3); //"AC CHARGR:"; } outmes: if((key==upsmode)||(key==invmode)) { if(flags.onflag==1) { printmes(str27,4); //"\fTOTAL LOAD:"; } modedisp(); swdisp(); printmes(str25,2); //"\fMAINS VOLT:"; if(flags.onflag==1) { printmes(str26,0); //"\fINVERTER V:"; } } else { modedisp(); swdisp(); printmes(str25,2); //"\fMAINS VOLT:"; } //printmes(str38,100); //"\fTITLE NAME if(menudelay>=125) { flags.setup=1; menudelay=0; lcd_putc('\f'); printmes(str0,100); //"\fCALIBRATION MENU"; while(key==modekey); while(1) { if(key==modekey) { setchramp=setting[5]/10; loadclb=setting[3]; functions(); memwrite(); flags.setup=0; __asm__ volatile ("reset"); } } } } }//main
Last edited by a moderator: