Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Testing battery sensor #6

@aicastell

Description

@aicastell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions