Flash Memory msp430f5529 ENERGIA

Discussion in 'Homework Help' started by mihaita212, Jun 20, 2017.

  1. mihaita212

    Thread Starter New Member

    Mar 26, 2017
    10
    0
    Hello guys i have a project at my school were i need to make an energy metter with a msp430f5529 and a hardware part i did all the code myself and the hardware part (current metters,voltage divider etc), (i know is rudimental and ineffective) , the code and the montage works well and does everything i need it to do.Now my professor asked me to save "energie1" and "energie2" so when my microcontroler runs out of battery this 2 variables are saved , i read a lot of threds but i can't figure it out.
    Here is the code if it helps ( i can provide you with hardware montage if needed).



    Code (Text):
    1. #include <Wire.h>
    2. #include "LiquidCrystal_I2C.h"
    3.  
    4. byte address = 0x27;      // LCD I2C address
    5. int columns = 20;         // number of columns on LCD
    6. int rows = 2;             // number of rows on LCD
    7. LiquidCrystal_I2C lcd(address, columns, rows);
    8.  
    9. long previousMillis = 0;      
    10. long previousMillis1 = 0;
    11. int timp;
    12.  
    13. int sensorPin = 23;
    14. int sensorValue = 0;
    15. float volt;
    16.  
    17.  
    18. byte newChar1[] = {
    19.   B11111,
    20.   B10001,
    21.   B10001,
    22.   B10001,
    23.   B10001,
    24.   B10001,
    25.   B10001,
    26.   B11111
    27. };
    28.  
    29. byte newChar2[] = {
    30.   B00000,
    31.   B00000,
    32.   B11100,
    33.   B11100,
    34.   B11100,
    35.   B11100,
    36.   B00000,
    37.   B00000
    38. };
    39.  
    40. byte newChar3[] = {
    41.   B11111,
    42.   B11111,
    43.   B11111,
    44.   B11111,
    45.   B11111,
    46.   B11111,
    47.   B11111,
    48.   B11111
    49. };
    50.  
    51. int sensorPin1 = 24;  
    52. int sensorValue1 = 0;
    53. float amp1;
    54.  
    55. int sensorPin2 = 25;  
    56. int sensorValue2 = 0;
    57. float amp2;
    58.  
    59. float putere1;
    60. float total_putere1;
    61. float energie1;
    62. float media_puteri1;
    63.  
    64. float putere2;
    65. float total_putere2;
    66. float energie2;
    67. float media_puteri2;
    68.  
    69. long interval = 1000;
    70. long interval1=270;
    71.  
    72. const int  buttonPin = PUSH2;
    73. int buttonPushCounter = 0;  
    74. int buttonState = 0;      
    75. int lastButtonState = 0;    
    76.  
    77.  
    78. void setup() {
    79.   lcd.init();                    
    80.   pinMode(buttonPin, INPUT_PULLUP);
    81.  
    82. lcd.createChar(0, newChar1);
    83. lcd.createChar(1, newChar2);
    84. lcd.createChar(2, newChar3);
    85.  
    86.  
    87. }
    88.  
    89. void loop() {
    90.   buttonState = digitalRead(buttonPin);
    91.   sensorValue = analogRead(sensorPin);
    92.   sensorValue1 = analogRead(sensorPin1);
    93.   sensorValue2 = analogRead(sensorPin2);  
    94.   unsigned long currentMillis = millis();
    95.   unsigned long currentMillis1 = millis();
    96.   timp=currentMillis/1000;
    97.  
    98.   if(currentMillis - previousMillis > interval) {
    99.     previousMillis = currentMillis;  
    100.      volt=sensorValue;
    101.      volt=(volt*3.3)/4096;
    102.      volt=volt*8.51;
    103.      amp1=sensorValue1;
    104.      amp1=(amp1*3.3)/4096;
    105.      if(amp1<0.5)
    106.      amp1=0;
    107.      amp1=amp1/0.5;
    108.      amp2=sensorValue2;
    109.      amp2=(amp2*3.3)/4096;
    110.      amp2=amp2/0.05;
    111.      if(amp2<1.25)
    112.      amp2=0;
    113.      putere1=volt*amp1;
    114.      putere2=volt*amp2;
    115.      total_putere1=putere1+total_putere1;
    116.      total_putere2=putere2+total_putere2;}
    117.  
    118. if (buttonState == LOW) {
    119.   lcd.backlight();
    120. }
    121. else
    122.   lcd.noBacklight();
    123.  
    124. if(currentMillis1 - previousMillis1 > interval1) {
    125.   previousMillis1 = currentMillis1;
    126.  
    127. if(buttonPushCounter==1){
    128.   lcd.clear();
    129.   lcd.setCursor(0,0);
    130.   lcd.print("Battery Voltage");
    131.   lcd.setCursor(0,1);
    132.   lcd.print(volt);
    133.   lcd.print(" V");}
    134.  
    135.  
    136. if(buttonPushCounter==2){
    137.    lcd.clear();
    138.   lcd.setCursor(0,0);
    139.   lcd.print("Solar Current");
    140.   lcd.setCursor(0,1);
    141.   lcd.print(amp1);
    142.   lcd.print(" A");}
    143.  
    144. if(buttonPushCounter==3){
    145.    lcd.clear();
    146.   lcd.setCursor(0,0);
    147.   lcd.print("Pump Current");
    148.   lcd.setCursor(0,1);
    149.   lcd.print(amp2);
    150.   lcd.print(" A");}
    151.  
    152. if(buttonPushCounter==4){
    153.   lcd.clear();
    154.   lcd.setCursor(0,0);
    155.   lcd.print("Solar Energy");
    156.   lcd.setCursor(0,1);
    157.   lcd.print(energie1);
    158.   lcd.print(" Wh");}                          
    159.  
    160. if(buttonPushCounter==5){
    161.   lcd.clear();
    162.   lcd.setCursor(0,0);
    163.   lcd.print("Pump Energy");
    164.   lcd.setCursor(0,1);
    165.   lcd.print(energie2);
    166.   lcd.print(" Wh");}
    167.  
    168. if(buttonPushCounter==6){
    169.   lcd.clear();
    170.   if(volt>12.6){
    171.   lcd.clear();
    172.   lcd.setCursor(0,1);
    173.    lcd.write(2);
    174.    lcd.write(2);
    175.    lcd.write(2);
    176.    lcd.write(2);
    177.    lcd.write(2);
    178.    lcd.write(1);
    179.   lcd.setCursor(0,0);
    180.   lcd.print("State Of Charge");
    181.   lcd.setCursor(6,1);
    182.   lcd.print("100");
    183.   lcd.print("%");}
    184.  
    185. if(volt<12.45 && volt>12.21){
    186.   lcd.clear();
    187.   lcd.setCursor(0,1);
    188.    lcd.write(2);
    189.    lcd.write(2);
    190.    lcd.write(2);
    191.    lcd.write(2);
    192.    lcd.write(0);
    193.    lcd.write(1);
    194.   lcd.setCursor(0,0);
    195.   lcd.print("State Of Charge");
    196.   lcd.setCursor(6,1);
    197.   lcd.print("80");
    198.   lcd.print("%");}
    199.  
    200. if(volt<12.20 && volt>11.91){
    201.   lcd.clear();
    202.   lcd.setCursor(0,1);
    203.    lcd.write(2);
    204.    lcd.write(2);
    205.    lcd.write(2);
    206.    lcd.write(0);
    207.    lcd.write(0);
    208.    lcd.write(1);
    209.   lcd.setCursor(0,0);
    210.   lcd.print("State Of Charge");
    211.   lcd.setCursor(6,1);
    212.   lcd.print("60");
    213.   lcd.print("%");}
    214.  
    215. if(volt<11.90 && volt>11.60){
    216.   lcd.clear();
    217.   lcd.setCursor(0,1);
    218.    lcd.write(2);
    219.    lcd.write(2);
    220.    lcd.write(0);
    221.    lcd.write(0);
    222.    lcd.write(0);
    223.    lcd.write(1);
    224.   lcd.setCursor(0,0);
    225.   lcd.print("State Of Charge");
    226.   lcd.setCursor(6,1);
    227.   lcd.print("40");
    228.   lcd.print("%");}
    229.  
    230. if(volt<11.59){
    231.   lcd.clear();
    232.   lcd.setCursor(0,1);
    233.    lcd.write(2);
    234.    lcd.write(0);
    235.    lcd.write(0);
    236.    lcd.write(0);
    237.    lcd.write(0);
    238.    lcd.write(1);
    239.   lcd.setCursor(0,0);
    240.   lcd.print("State Of Charge");
    241.   lcd.setCursor(6,1);
    242.   lcd.print("20");
    243.   lcd.print("%");}}
    244.  
    245. if(buttonPushCounter>6)
    246. buttonPushCounter=1;}
    247.  
    248. if (buttonState != lastButtonState) {
    249. if (buttonState == HIGH) {
    250.   buttonPushCounter++;}}  
    251.   lastButtonState = buttonState;
    252.  
    253.   media_puteri1=total_putere1/timp;
    254.   energie1=media_puteri1*timp/3600;
    255.   media_puteri2=total_putere2/timp;
    256.   energie2=media_puteri2*timp/3600;
    257. }
    258.  
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    4,667
    745
    Does msp430f5529 have memory that is not lost when power is lost(brown out?)?
    If it does not have this type of memory, then you need to add some kind of storage, popular storage options these days are the sd card and usb sticks. MSP430 is TI product, they should have something on interfacing their product with sd card reader.
     
Loading...