Jump to content
43oh

BDCoDE

Members
  • Content Count

    22
  • Joined

  • Last visited

Reputation Activity

  1. Like
    BDCoDE reacted to semicolo in Problem using Arduino code in Energia   
    Probably noise, the recommended way to get a sample is to put the cpu in sleep mode and wake up by the conversion interrupt, I don't know if energia is doing that.
    Also the noise can come from the supply.
    Did you add a voltage divider for the battery voltage? A fully charged battery is around 4.2V this could damage the MCU.
  2. Like
    BDCoDE reacted to semicolo in Problem using Arduino code in Energia   
    What about my my code? It just works I don't think you really need the sampling intervals to be spot on accuracy that you need a timer.
    If you really want it to be better just do
     
    // Very simple Arduino Lithium-ion battery capacity tester // from electronicsblog.net   #define LED GREEN_LED #define resistor 6.9   float capacity=0, value,voltage,current, time=0;   void measure (void) {     value= analogRead(0);     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; 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. Like
    BDCoDE reacted to semicolo in Problem using Arduino code in Energia   
    Yes and remove all the timer stuff from setup
    So something like this
     
    // Very simple Arduino Lithium-ion battery capacity tester // from electronicsblog.net   #define LED 13 #define resistor 6.9   float capacity=0, value,voltage,current, time=0;   void measure (void) {     value= analogRead(0);     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;   void setup() {     pinMode(LED, OUTPUT);     Serial.begin(9600);   };   void loop () {   digitalWrite(LED, x); x=!x; measure(); delay(1000); };
  4. Like
    BDCoDE reacted to roadrunner84 in Problem using Arduino code in Energia   
    Your code is ATmega specific (you're directly addressing the timer peripheral of the Arduino), and hence cannot be run at the MSP430/launchpad. You could translate this code to work for the Launchpad. Preferably, abstraction layers hide this platform specific code from you, in this case it didn't happen.
    #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER1_OVF_vect(void) { x=!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; TACTL0 = TAIE; // enabled timer overflow interrupt; TACTL0 |= MC_1; // normal operation page 366 (mode up); TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register) TACTL0 |= TASSEL_2 + TACLR; // start timer/ reset clock Serial.begin(256000); }; Oh. I see the timer is supposed to interrupt every second, let's rewrite the code a tiny bit:
    #pragma vector=TIMER0_A0_VECTOR __interrupt void TIMER1_OVF_vect(void) { x=!x; if(x) // the interrupt is kicked twice per second, but measure() will be called only half of those times; so once per second { measure(); } } void setup() { pinMode(LED, OUTPUT); TACTL0 = TAIE + MC_3 + TASSEL_2 + TACLR; // Set timer to up mode on SMCLK/8 (125kiHz) TACCR0 = 62500 - 1; // set overflow value to remove time error (16bit counter register) _BIS_SR(GIE); // enabled global interrupt; Serial.begin(256000); };
  5. Like
    BDCoDE reacted to roadrunner84 in Problem using Arduino code in Energia   
    Oh, my bad! it sgould be TACTL instead of TACTL0. The TACCR0 should stay as is.
    No this is not inline assembler, it's just writing to fixed memory locations.
×
×
  • Create New...