nkokkos / sky-boards-collect

Automatically exported from code.google.com/p/sky-boards-collect
0 stars 0 forks source link

Problem reactivating sensors in collect_view_arch_read_sensors #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

In this test program 

http://code.google.com/p/sky-boards-collect/source/browse/trunk/contiki/examples
/sky/test/test-DS1000.c 

there is no problem with running SENSORS_ACTIVATE _after_ a previous 
SENSORS_DEACTIVATE, it works without problems. However, in collect-view, this 
will cause the node to sends repeatly the same CO value, so I guess that once 
SENSOR_DEACTIVATE is executed first time, SENSORS_ACTIVATE won't work in 
succesive calls.

// This code will send always the same CO value to sink
void collect_view_arch_read_sensors(struct collect_view_data_msg *msg)
{
    SENSORS_ACTIVATE(ds1000); // sky adc12 config (sky-sensors.c)
    msg->sensors[CO_SENSOR] = ds1000.value(SENSOR_CO);
    SENSORS_DEACTIVATE(ds1000);
}

I solved this issue doing this:

char sensors_activate=0;
void collect_view_arch_read_sensors(struct collect_view_data_msg *msg)
{
    if (!sensors_activate){
        SENSORS_ACTIVATE(ds1000);   
        sensors_activate=1;
    }
    msg->sensors[CO_SENSOR] = ds1000.value(SENSOR_CO);
}

But I don't like this, because it doesn't really solve the problem. And it is 
very inefficient.

collect-view-z21.c apparently have the same problem, because it is only 
initilized.
collect-view-sky.c works ok.

Any ideas?

Original issue reported on code.google.com by eldial@gmail.com on 8 Aug 2012 at 11:58

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This solves the problem:

void collect_view_arch_read_sensors(struct collect_view_data_msg *msg)
{
    SENSORS_ACTIVATE(ds1000);
        printf("");
    msg->sensors[CO_SENSOR] = ds1000.value(SENSOR_CO);
    SENSORS_DEACTIVATE(ds1000);
}

But this doesn't (same result for clock_delay or clock_wait)

void collect_view_arch_read_sensors(struct collect_view_data_msg *msg)
{
    SENSORS_ACTIVATE(ds1000);
        static int i=1000;
        while(i>0)i--;
    msg->sensors[CO_SENSOR] = ds1000.value(SENSOR_CO);
    SENSORS_DEACTIVATE(ds1000);
}

Original comment by eldial@gmail.com on 8 Aug 2012 at 4:22

GoogleCodeExporter commented 9 years ago
Clarification about collect-view-z21.c:

It doesn't have the same problem. 

~/contiki/platform/z21/dev/tmp102.c

doesn't implement a function to stop tmp102

Original comment by eldial@gmail.com on 10 Aug 2012 at 1:20

GoogleCodeExporter commented 9 years ago
This solves the the problem, and it is the right way:

void collect_view_arch_read_sensors(struct collect_view_data_msg *msg)
{
    SENSORS_ACTIVATE(ds1000);
        while (!ds1000.status(SENSORS_READY));
    msg->sensors[CO_SENSOR] = ds1000.value(SENSOR_CO);
    SENSORS_DEACTIVATE(ds1000);
}

Details:

1. From sky-sensors.c:

int
sky_sensors_status(uint16_t input, int type)
{
  if(type == SENSORS_ACTIVE) {
    return (adc_on & input) == input;
  }
  if(type == SENSORS_READY) {
    ready |= ADC12IFG & adc_on & input;
    return (ready & adc_on & input) == input;
  }
  return 0;
}

2. From MSP430 user's guide (ADC12 Chapter)

"When conversion results are written to a selected ADC12MEMx, the corresponding 
flag
in the ADC12IFGx register is set."

Conclusion: 

One must wait for the ADC12 to place first conversions on selected ADC12MEM 
registers. Also, contiki file "collect-view-sky.c" could be patched (for 
safety) even though problem won't happen there (SENSORS_ACTIVATE(ds1000) 
enables 3 conversions at one call, not the case in collect-view-sky.c).

Original comment by eldial@gmail.com on 13 Aug 2012 at 1:04