teco-kit / Jennisense

A modularized open hardware, sensor drivers based on contiki for the JN51xx µController. A detailed description and how-to can be found in the wiki (see link below).
http://github.com/teco-kit/Jennisense/wiki
19 stars 16 forks source link

Testing battery sensor #6

Open aicastell opened 10 years ago

aicastell commented 10 years ago

Hello forum.

I am testing the ADC sensor battery of a Jennic JN5148 platform with Jennisense Contiki port. I am using two 1.5V AAA batteries. To use the battery supply, jumper closes J2 pins 1 and 2.

Based on some of the examples available, I coded this simple test:

PROCESS_THREAD(battery_test, ev, data) { static struct etimer period_timer;

PROCESS_BEGIN();
PROCESS_PAUSE();

SENSORS_ACTIVATE(battery_sensor);
printf("Starting...\n");

etimer_set(&period_timer, (2*CLOCK_SECOND));

while(1)
{
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER);

    // Read battery voltage.
    // I get an average of a hundred values to be more safe
    unsigned long battery = 0;

    int i = 0;
    for(i = 0; i < 100; i++) {
        battery += battery_sensor.value(0);
    }
    battery = battery / i;

    // Based on contiki/examples/z1/test-battery.c
    int volt = (battery * 5) / 4096;
    int mvolt = battery - (volt * 1000);
    printf("Battery: %d (%d.%03dV)\n", battery, volt, mvolt);
    etimer_restart(&period_timer);
}

PROCESS_END();

}

This example worked for an hour, printing "battery" values in the range [3100, 3200].

Battery value should be a decreasing function along time. But along time, values read increase and decrease randomly in that range . This is not the expected behaviour for the voltage of a battery. Is this sensor driver working fine?

Also, the value read on "battery" should be rescaled to get the desired magnitude (Volts). I haven't found any document explaining how to rescale the battery values read, to get the desired magnitude. I have used the example available on:

contiki/examples/z1/test-battery.c

to implement something similar, but probably this is wrong for the Jennic platform. What's the proper rescale I should apply to get desired magnitude?

Thank you in advance. Best regards, -- Ivan