Takeuchi Kouichi
/
2ak1010_LocalFile_W_solar
エレキジャックweb mbed入門用です。 太陽光発電MPPT電力測定 ファイル記録システム用プログラムです。
main.cpp@0:989432420ed6, 2010-10-10 (annotated)
- Committer:
- takeuchi
- Date:
- Sun Oct 10 11:47:33 2010 +0000
- Revision:
- 0:989432420ed6
aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takeuchi | 0:989432420ed6 | 1 | //2ak1009_Solar_VI |
takeuchi | 0:989432420ed6 | 2 | // for Solar charger Copyright by K.Takeuchi |
takeuchi | 0:989432420ed6 | 3 | |
takeuchi | 0:989432420ed6 | 4 | #include "mbed.h" |
takeuchi | 0:989432420ed6 | 5 | #include "TextLCD2004.h" |
takeuchi | 0:989432420ed6 | 6 | |
takeuchi | 0:989432420ed6 | 7 | #define ON 1 |
takeuchi | 0:989432420ed6 | 8 | #define OFF 0 |
takeuchi | 0:989432420ed6 | 9 | #define max_minutes 210 |
takeuchi | 0:989432420ed6 | 10 | #define I_trim 0.15 |
takeuchi | 0:989432420ed6 | 11 | |
takeuchi | 0:989432420ed6 | 12 | AnalogIn Vbat_adc(p20); |
takeuchi | 0:989432420ed6 | 13 | AnalogIn Vsolar_adc(p19); |
takeuchi | 0:989432420ed6 | 14 | AnalogIn Isolar_adc(p18); |
takeuchi | 0:989432420ed6 | 15 | |
takeuchi | 0:989432420ed6 | 16 | TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3 |
takeuchi | 0:989432420ed6 | 17 | LocalFileSystem local("local"); |
takeuchi | 0:989432420ed6 | 18 | |
takeuchi | 0:989432420ed6 | 19 | int main() { |
takeuchi | 0:989432420ed6 | 20 | float Vbat,Vsolar,Isolar; |
takeuchi | 0:989432420ed6 | 21 | float Isolar_sum,Isolar_avg,Vsolar_sum,Vsolar_avg,Wsolar; |
takeuchi | 0:989432420ed6 | 22 | int k=0,s_count=60,m_count=max_minutes; |
takeuchi | 0:989432420ed6 | 23 | lcd.cls(); |
takeuchi | 0:989432420ed6 | 24 | lcd.locate(0,0); |
takeuchi | 0:989432420ed6 | 25 | lcd.printf("=Solar MPPT Sys.="); |
takeuchi | 0:989432420ed6 | 26 | lcd.locate(0,1); |
takeuchi | 0:989432420ed6 | 27 | lcd.printf("File open..."); |
takeuchi | 0:989432420ed6 | 28 | FILE *fp=fopen("/local/Solar.txt","a"); |
takeuchi | 0:989432420ed6 | 29 | if(!fp){ |
takeuchi | 0:989432420ed6 | 30 | lcd.locate(0,2); |
takeuchi | 0:989432420ed6 | 31 | fprintf(stderr,"File/local/Solar.txt cant't opened"); |
takeuchi | 0:989432420ed6 | 32 | exit(1); |
takeuchi | 0:989432420ed6 | 33 | } |
takeuchi | 0:989432420ed6 | 34 | lcd.locate(0,1); |
takeuchi | 0:989432420ed6 | 35 | lcd.printf("System start!!"); |
takeuchi | 0:989432420ed6 | 36 | fprintf(fp,"\n"); |
takeuchi | 0:989432420ed6 | 37 | wait(2.0); |
takeuchi | 0:989432420ed6 | 38 | |
takeuchi | 0:989432420ed6 | 39 | while(1){ |
takeuchi | 0:989432420ed6 | 40 | Vbat=Vbat_adc.read()*30; |
takeuchi | 0:989432420ed6 | 41 | Vsolar=Vsolar_adc.read()*30; |
takeuchi | 0:989432420ed6 | 42 | Isolar=(Isolar_adc.read()*3.3-2.5)/185*1000; |
takeuchi | 0:989432420ed6 | 43 | Wsolar=Vsolar_avg*Isolar_avg; |
takeuchi | 0:989432420ed6 | 44 | lcd.cls(); |
takeuchi | 0:989432420ed6 | 45 | lcd.locate(0,0); |
takeuchi | 0:989432420ed6 | 46 | lcd.printf("=Solar MPPT Sys.="); |
takeuchi | 0:989432420ed6 | 47 | lcd.locate(0,1); |
takeuchi | 0:989432420ed6 | 48 | lcd.printf("Sp V:%2.1fV,I:%1.2fA",Vsolar_avg,Isolar_avg); |
takeuchi | 0:989432420ed6 | 49 | lcd.locate(0,2); |
takeuchi | 0:989432420ed6 | 50 | lcd.printf("Vbat:%2.1fV",Vbat); |
takeuchi | 0:989432420ed6 | 51 | lcd.locate(0,3); |
takeuchi | 0:989432420ed6 | 52 | lcd.printf("W:%2.1fW %d:%d",Wsolar,m_count,s_count); |
takeuchi | 0:989432420ed6 | 53 | wait(0.5); |
takeuchi | 0:989432420ed6 | 54 | lcd.locate(0,0); |
takeuchi | 0:989432420ed6 | 55 | lcd.printf("=Solar MPPT Sys ="); |
takeuchi | 0:989432420ed6 | 56 | wait(0.5); |
takeuchi | 0:989432420ed6 | 57 | Vsolar_sum=Vsolar_sum+Vsolar; |
takeuchi | 0:989432420ed6 | 58 | Isolar_sum=Isolar_sum+Isolar; |
takeuchi | 0:989432420ed6 | 59 | k++; |
takeuchi | 0:989432420ed6 | 60 | if(k==10){ |
takeuchi | 0:989432420ed6 | 61 | k=0; |
takeuchi | 0:989432420ed6 | 62 | Vsolar_avg=Vsolar_sum/10; |
takeuchi | 0:989432420ed6 | 63 | Isolar_avg=Isolar_sum/10-I_trim; |
takeuchi | 0:989432420ed6 | 64 | Vsolar_sum=0; |
takeuchi | 0:989432420ed6 | 65 | Isolar_sum=0; |
takeuchi | 0:989432420ed6 | 66 | } |
takeuchi | 0:989432420ed6 | 67 | s_count--; |
takeuchi | 0:989432420ed6 | 68 | if(s_count==0){ |
takeuchi | 0:989432420ed6 | 69 | s_count=60; |
takeuchi | 0:989432420ed6 | 70 | m_count--; |
takeuchi | 0:989432420ed6 | 71 | fprintf(fp,"%2d, %2.1f, %2.2f, %2.2f, %2.1f\n",m_count,Vsolar_avg,Isolar_avg,Wsolar,Vbat); |
takeuchi | 0:989432420ed6 | 72 | } |
takeuchi | 0:989432420ed6 | 73 | if(m_count ==0){ |
takeuchi | 0:989432420ed6 | 74 | lcd.cls(); |
takeuchi | 0:989432420ed6 | 75 | lcd.locate(0,0); |
takeuchi | 0:989432420ed6 | 76 | lcd.printf("=Solar MPPT Sys.=");wait(0.2); |
takeuchi | 0:989432420ed6 | 77 | lcd.locate(0,1); |
takeuchi | 0:989432420ed6 | 78 | lcd.printf("File close...");wait(0.2); |
takeuchi | 0:989432420ed6 | 79 | fprintf(fp,"\n"); |
takeuchi | 0:989432420ed6 | 80 | fclose(fp); |
takeuchi | 0:989432420ed6 | 81 | lcd.locate(0,2); |
takeuchi | 0:989432420ed6 | 82 | lcd.printf("Recording Finish!"); |
takeuchi | 0:989432420ed6 | 83 | wait(5.0); |
takeuchi | 0:989432420ed6 | 84 | exit(1); |
takeuchi | 0:989432420ed6 | 85 | } |
takeuchi | 0:989432420ed6 | 86 | }//while |
takeuchi | 0:989432420ed6 | 87 | }//main |
takeuchi | 0:989432420ed6 | 88 | |
takeuchi | 0:989432420ed6 | 89 |