Jump to content
43oh

BDCoDE

Members
  • Content Count

    22
  • Joined

  • Last visited

Posts posted by BDCoDE

  1. I run the test again with new code and got 1.55Ah.

    Here is the new output. 

    Voltage= 0.00V Current= 0.00A Capacity= 0.00Ah Discharging time= 1.00s // battery isn't connected yet 
    Voltage= 0.00V Current= 0.00A Capacity= 0.00Ah Discharging time= 2.00s // battery isn't connected yet 
    Voltage= 3.60V Current= 0.28A Capacity= 0.00Ah Discharging time= 3.00s 
    Voltage= 3.64V Current= 0.28A Capacity= 0.00Ah Discharging time= 4.00s 
    Voltage= 3.64V Current= 0.28A Capacity= 0.00Ah Discharging time= 5.00s
    ......................................................................
    ......................................................................
    ......................................................................
    Voltage= 2.22V Current= 0.17A Capacity= 1.55Ah Discharging time= 21694.00s 
    Voltage= 2.22V Current= 0.17A Capacity= 1.55Ah Discharging time= 21695.00s 
    Voltage= 2.21V Current= 0.17A Capacity= 1.55Ah Discharging time= 21696.00s 
    Voltage= 0.00V Current= 0.00A Capacity= 1.55Ah Discharging time= 21697.00s 
    Voltage= 0.00V Current= 0.00A Capacity= 1.55Ah Discharging time= 21698.00s 
    
  2. Like this? The schematic with voltage divider will then look like this.

    Are everything ??????? correctly now?

    // Very simple Arduino Lithium-ion battery capacity tester
    // from electronicsblog.net
     
    #define LED GREEN_LED
    #define resistor 13
     
    float capacity=0, value,voltage,current, time=0;
     
    void measure (void) {
      analogReference(INTERNAL2V5);
      delay(1)
      value= analogRead(A5);
     
      voltage=value/1023*5;
     
      current = voltage/resistor;
     
      capacity=capacity+current/3600;
     
      time++;
     
      Serial.print("Voltage= ");
      Serial.print(voltage);
     
      Serial.print("V Current= ");
      Serial.print(current);
     
      Serial.print("A Capacity= ");
      Serial.print(capacity);
      Serial.print("Ah ");
     
      Serial.print("Discharging time= ");
      Serial.print(time);
      Serial.print("s ");
     
      Serial.print("\n");
    }
     
    boolean x=false;
    unsigned long ms;
     
    void setup() {
     
      pinMode(LED, OUTPUT);
     
      Serial.begin(9600);
      ms = millis()+1000;
    };
     
    void loop () {
      digitalWrite(LED, x);
      x=!x;
      measure();
      while (millis() < ms);
      ms=millis()+1000;
    };
    
    
  3. Thanks for advice, I will try it tomorrow.

     

    The test is finished. Here is the last lines of output file. As you can see the voltage is about 3.5V at the lowest,  I don't know why but the voltage was constant 5.00V til 16653.00s  :!!!:

    The test showed that battery is 1.87Ah. I think it's true, because the battery sticker says it's 2000mAh, but  it's produced in China  :grin:. Will run some more tests tomorrow, with voltage divider  ;-)

     

    Voltage= 3.60V Current= 0.28A Capacity= 1.87Ah Discharging time= 17590.00s 
    Voltage= 3.59V Current= 0.28A Capacity= 1.87Ah Discharging time= 17591.00s 
    Voltage= 3.58V Current= 0.28A Capacity= 1.87Ah Discharging time= 17592.00s 
    Voltage= 3.57V Current= 0.27A Capacity= 1.87Ah Discharging time= 17593.00s 
    Voltage= 3.56V Current= 0.27A Capacity= 1.87Ah Discharging time= 17594.00s 
    Voltage= 3.56V Current= 0.27A Capacity= 1.87Ah Discharging time= 17595.00s 
    Voltage= 3.54V Current= 0.27A Capacity= 1.87Ah Discharging time= 17596.00s 
    Voltage= 3.54V Current= 0.27A Capacity= 1.87Ah Discharging time= 17597.00s 
    Voltage= 3.54V Current= 0.27A Capacity= 1.87Ah Discharging time= 17598.00s 
    Voltage= 3.52V Current= 0.27A Capacity= 1.87Ah Discharging time= 17599.00s 
    Voltage= 3.51V Current= 0.27A Capacity= 1.87Ah Discharging time= 17600.00s 
    Voltage= 0.00V Current= 0.00A Capacity= 1.87Ah Discharging time= 17601.00s 
    Voltage= 0.00V Current= 0.00A Capacity= 1.87Ah Discharging time= 17602.00s 
    Voltage= 0.00V Current= 0.00A Capacity= 1.87Ah Discharging time= 17603.00s 
    
  4. No voltage divider, here is the actual schematic.

     

    Besides, I was getting 1.4V when I was using "voltage=value/1024*3.7;" , instead of  "voltage=value/1024*5.0" as in your example.

    Now with "voltage=value/1024*5.0" I get constant 5.00V and 0.38A, but I'm not sure if it's correct.

     

    P.S Here is  the new output. I used "voltage=value/1024*5.0"

     

    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3220.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3221.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3222.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3223.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3224.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3225.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3226.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3227.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3228.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3229.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3230.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3231.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.34Ah Discharging time= 3232.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3233.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3234.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3235.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3236.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3237.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3238.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3239.00s 
    Voltage= 5.00V Current= 0.38A Capacity= 0.35Ah Discharging time= 3240.00s 
    
  5. Your code is working well so far. The only thing I edited was resistance , from 6.9 to 13

    Here is the output example:
    Voltage= 1.42V Current= 0.11A Capacity= 0.01Ah Discharging time= 430.00s 
    Voltage= 1.35V Current= 0.10A Capacity= 0.01Ah Discharging time= 431.00s 
    Voltage= 1.42V Current= 0.11A Capacity= 0.01Ah Discharging time= 432.00s 
    Voltage= 1.37V Current= 0.11A Capacity= 0.01Ah Discharging time= 433.00s 
    Voltage= 1.43V Current= 0.11A Capacity= 0.01Ah Discharging time= 434.00s 
    Voltage= 1.37V Current= 0.11A Capacity= 0.01Ah Discharging time= 435.00s 
    Voltage= 1.41V Current= 0.11A Capacity= 0.01Ah Discharging time= 436.00s 
    Voltage= 1.37V Current= 0.11A Capacity= 0.01Ah Discharging time= 437.00s 
    Voltage= 1.42V Current= 0.11A Capacity= 0.01Ah Discharging time= 438.00s 
    Voltage= 1.35V Current= 0.10A Capacity= 0.01Ah Discharging time= 439.00s 
    Voltage= 1.59V Current= 0.12A Capacity= 0.01Ah Discharging time= 440.00s 
    Voltage= 1.42V Current= 0.11A Capacity= 0.01Ah Discharging time= 441.00s 
    Voltage= 1.36V Current= 0.10A Capacity= 0.01Ah Discharging time= 442.00s 
    Voltage= 1.45V Current= 0.11A Capacity= 0.01Ah Discharging time= 443.00s 
    Voltage= 1.36V Current= 0.10A Capacity= 0.01Ah Discharging time= 444.00s 
    Voltage= 1.45V Current= 0.11A Capacity= 0.01Ah Discharging time= 445.00s 
    Voltage= 1.39V Current= 0.11A Capacity= 0.01Ah Discharging time= 446.00s 
    Voltage= 1.76V Current= 0.14A Capacity= 0.01Ah Discharging time= 447.00s 
    Voltage= 1.44V Current= 0.11A Capacity= 0.01Ah Discharging time= 448.00s 
    Voltage= 1.41V Current= 0.11A Capacity= 0.01Ah Discharging time= 449.00s 
    Voltage= 1.33V Current= 0.10A Capacity= 0.01Ah Discharging time= 450.00s

    I can smell the resistors burning :). I think it's strange that Voltage is so unstable. but we will see what will happen the next hour.

     

    P.S The real voltage is 3.7 Li-ion battery  :grin:
  6. Edited: I was lucky and received my usb2uart converter now. It's based on CP2102 chip, if it makes any difference. I installed drivers and Windows shows it on COM11 post. I checked the code below, it's working just fine. But not the "Battery Test" code. I have no idea what to do...

     

    static uint8_t sensorPin = A5;
    int sensorValue = 0;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      sensorValue = analogRead(sensorPin);
      Serial.println(sensorValue);
      delay(100);
    }
    

     

    Checked as well on my another code. This one works fine too.

     

    #define cmdL 'L'      //UART command
    #define cmdR 'R'      //UART command
     
    char incomingByte;    // income data
    
    
    char command;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      if (Serial.available() > 0) {
        incomingByte = Serial.read();
        if(incomingByte == cmdL) { 
          Serial.println("You typed L");
        }
        else if(incomingByte == cmdR) {
          Serial.println("You typed R");
        }
        else if(incomingByte > '0'){
          Serial.println("Wrong command. Please try again");
        }// ????? ??????
    }
    delay(100);
    }
    
  7. Ok, didn't noticed that part of you message.

    The code looks like this now:

    // Very simple Arduino Lithium-ion battery capacity tester
    // from electronicsblog.net
    
    static uint8_t sensorPin = A5;
    #define LED GREEN_LED
    #define resistor 13
     
    float capacity=0, value,voltage,current, time=0;
     
    void measure (void) {
     
      value= analogRead(sensorPin);
     
      voltage=value/1024*5.0;
     
      current = voltage/resistor;
     
      capacity=capacity+current/3600;
     
      time++;
     
    Serial.print("Voltage= ");
    Serial.print(voltage);
    
    Serial.print("V Current= ");
    Serial.print(current);
    
    Serial.print("A Capacity= ");
    Serial.print(capacity);
    Serial.print("Ah ");
    
    Serial.print("Discharging time= ");
    Serial.print(time);
    Serial.print("s ");
    
    Serial.print("\n");
    }
     
    boolean x=false;
      
     #pragma vector=TIMER0_A0_VECTOR
    __interrupt void TIMER1_OVF_vect(void) {
        x=!x;
        digitalWrite(LED, x);
        if(x)
        {
            measure();
        }
        }
    
        void setup() {
        pinMode(LED, OUTPUT);
        TACTL = ID_3 + MC_1 + TASSEL_2 + TACLR; // Set timer to up mode on SMCLK/8 (125kiHz)
        TACCTL0 = CCIE; // Enable timer interrupt
        TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register)
        _BIS_SR(GIE); // enabled global interrupt;
        Serial.begin(9600); 
        };
     
    void loop () {
       LPM3;
    };

     

    The GREEN_LED is now always ON, but still nothing in Terminal output.

    Here is the new picture of schematic. There you can see how all jumpers are connected.

  8. Sorry, my fault. I was actually trying with both of them.

    The problem was in Serial.print().

    I used Serial.println() instead.

     

    Here is the working source.

    static uint8_t sensorPin = A5;
    int sensorValue = 0;
    
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      sensorValue = analogRead(sensorPin);
      Serial.println(sensorValue);
      delay(1000);
    }
    

     

    But I still can't get this battery test working.

    Here is the code you gave me, is there anything wrong with it?

    // Very simple Arduino Lithium-ion battery capacity tester
    // from electronicsblog.net
    
    static uint8_t sensorPin = A5;
    #define LED GREEN_LED
    #define resistor 13
     
    float capacity=0, value,voltage,current, time=0;
     
    void measure (void) {
     
      value= analogRead(sensorPin);
     
      voltage=value/1024*5.0;
     
      current = voltage/resistor;
     
      capacity=capacity+current/3600;
     
      time++;
     
    Serial.print("Voltage= ");
    Serial.print(voltage);
    
    Serial.print("V Current= ");
    Serial.print(current);
    
    Serial.print("A Capacity= ");
    Serial.print(capacity);
    Serial.print("Ah ");
    
    Serial.print("Discharging time= ");
    Serial.print(time);
    Serial.print("s ");
    
    Serial.print("\n");
    }
     
    boolean x=false;
      
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void TIMER1_OVF_vect(void) {
        x=!x;
        digitalWrite(LED, x);
        if(x)
        {
            measure();
        }
        }
    
        void setup() {
        pinMode(LED, OUTPUT);
        // I don't know the ATmega timers, but I will be assuming your timer clock is running at 1MHz and interrupts every 0x10000-0x0BDC = 62500 microseconds (every 62.5 milliseconds)
        _BIS_SR(GIE); // enabled global interrupt;
        TACTL  = TAIE; // enabled timer overflow interrupt;
        TACTL  |= MC_1; // normal operation page 366 (mode up);
        TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register)
        TACTL  |= TASSEL_2 + TACLR; // start timer/ reset clock
        Serial.begin(96000);
         
        };
     
    void loop () {
      LPM3;
    };
    
  9. I do use Serial.begin(9600)  :smile:

     

    P.S I read this thread and decided to check if it's working on mine board. I connected P1.5 pin to GND and used this code. Still can't receive anything in Serial Monitor. I tried both M430G2553 & M430G2452. What's the problem  :x

    static uint8_t sensorPin = A5;
    int sensorValue = 0;
    
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      sensorValue = analogRead(sensorPin);
      Serial.print(sensorValue);
      delay(10);
    }
    
  10. Like this?

      
    #pragma vector=TIMER0_A0_VECTOR
        __interrupt void TIMER1_OVF_vect(void) {
        x=!x;
        digitalWrite(GREEN_LED, x);
        measure();
        }
    
        void setup() {
        pinMode(GREEN_LED, OUTPUT);
        // I don't know the ATmega timers, but I will be assuming your timer clock is running at 1MHz and interrupts every 0x10000-0x0BDC = 62500 microseconds (every 62.5 milliseconds)
        _BIS_SR(GIE); // enabled global interrupt;
        TACTL  = TAIE; // enabled timer overflow interrupt;
        TACTL  |= MC_1; // normal operation page 366 (mode up);
        TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register)
        TACTL  |= TASSEL_2 + TACLR; // start timer/ reset clock
        Serial.begin(256000);
         
        };
     
    void loop () {
      LPM3;
    };
    

     

    I'm using Terminal v1.9b on COM3 (9600,8,Parity =none,Stop bits =1,Handshaking =none)

    I cant get anything displayed and the resistors get hot.

    Am I doing it wrong?

  11. Successfully compiled now. Thanks :smile:

     

     

     

    P.S  Get some problems under testing.

            Here is the schematic I used. R1 = 5 x 68ohm 1/4W conecteted in parallel.
            And here is the full source code:
    // Very simple Arduino Lithium-ion battery capacity tester
    // from electronicsblog.net
    
    #define resistor 13
     
    float capacity=0, value,voltage,current, time=0;
     
    void measure (void) {
     
      value= analogRead(7);
     
      voltage=value/1024*5.0;
     
      current = voltage/resistor;
     
      capacity=capacity+current/3600;
     
      time++;
     
      Serial.print("Voltage= ");
      Serial.print(voltage);
     
      Serial.print("V Current= ");
      Serial.print(current);
     
      Serial.print("A Capacity= ");
      Serial.print(capacity);
      Serial.print("Ah ");
     
      Serial.print("Discharging time= ");
      Serial.print(time);
      Serial.print("s ");
     
      Serial.print("\n");
    }
     
    boolean x=false;
      
    #pragma vector=TIMER0_A0_VECTOR
        __interrupt void TIMER1_OVF_vect(void) {
        x=!x;
        measure();
        }
    
        void setup() {
        pinMode(GREEN_LED, OUTPUT);
        // I don't know the ATmega timers, but I will be assuming your timer clock is running at 1MHz and interrupts every 0x10000-0x0BDC = 62500 microseconds (every 62.5 milliseconds)
        _BIS_SR(GIE); // enabled global interrupt;
        TACTL  = TAIE; // enabled timer overflow interrupt;
        TACTL  |= MC_1; // normal operation page 366 (mode up);
        TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register)
        TACTL  |= TASSEL_2 + TACLR; // start timer/ reset clock
        Serial.begin(256000);
         
        };
     
    void loop () {
      digitalWrite(GREEN_LED, x);
    };
    

     

     

     

  12. Hi, roadrunner84.

     

    When I use your code i get this error.

    batt_tester.cpp: In function 'void setup()':
    batt_tester.cpp:50:5: error: 'TACTL0' was not declared in this scope
    

     


    Preferably, abstraction layers hide this platform specific code from you, in this case it didn't happen.

     

    Is it something like inline assembler? 

     

     


     

     
  13. Hi, I'm trying to build a simple Li ion battery capacity tester using this article. The code compiles fine until line 40, where it comes to interrupt handler. What should I use instead?

     

    Here is the code where I get errors:

    ISR(TIMER1_OVF_vect) {
      TCNT1=0x0BDC;
      x=!x;
     
      measure();
     
    }
     
    void setup() {
     
      pinMode(LED, OUTPUT);
     
      TIMSK1=0x01; // enabled global and timer overflow interrupt;
      TCCR1A = 0x00; // normal operation page 148 (mode0);
      TCNT1=0x0BDC; // set initial value to remove time error (16bit counter register)
      TCCR1B = 0x04; // start timer/ set clock
     
      Serial.begin(256000);
    
    };
    

     

     

    I saw this topic, but I never used assembler before and I don't understand anything there. 

×
×
  • Create New...