Hi Jan,
Below are the files and code snippet. I have cc'ed this email to Tiong Hoo
Lim who asked for the files.
Best regards,
Zhiyi
===================================
In Oscilloscope, use the following two sensors for X- and Y-axis readings.
new ADCSensorsXC() as SensorX,
new ADCSensorsYC() as SensorY,
OscilloscopeC.Read[unique(MS)] -> SensorX.Read;
OscilloscopeC.Read[unique(MS)] -> SensorY.Read;
In tos/platforms/telosb, create four files:
ADCSensorsXC.nc:
generic configuration ADCSensorsXC() {
provides interface Read<uint16_t>;
}
implementation {
components new Msp430ADCSensorsXC();
Read = Msp430ADCSensorsXC.Read;
}
ADCSensorsYC.nc:
generic configuration ADCSensorsYC() {
provides interface Read<uint16_t>;
}
implementation {
components new Msp430ADCSensorsYC();
Read = Msp430ADCSensorsYC.Read;
}
ADCSensorsStreamXC.nc:
generic configuration ADCSensorsStreamXC() {
provides interface ReadStream<uint16_t>;
}
implementation {
components new Msp430ADCSensorsXC();
ReadStream = Msp430ADCSensorsXC.ReadStream;
}
ADCSensorsStreamYC.nc:
generic configuration ADCSensorsStreamYC() {
provides interface ReadStream<uint16_t>;
}
implementation {
components new Msp430ADCSensorsYC();
ReadStream = Msp430ADCSensorsYC.ReadStream;
}
Under tos/chips/msp430/sensors, create the following four files:
Msp430ADCSensorsXC.nc:
generic configuration Msp430ADCSensorsXC() {
provides interface Read<uint16_t>;
provides interface ReadStream<uint16_t>;
provides interface Resource;
provides interface ReadNow<uint16_t>;
}
implementation {
components new AdcReadClientC();
Read = AdcReadClientC;
components new AdcReadStreamClientC();
ReadStream = AdcReadStreamClientC;
components Msp430ADCSensorsXP;
AdcReadClientC.AdcConfigure -> Msp430ADCSensorsXP;
AdcReadStreamClientC.AdcConfigure -> Msp430ADCSensorsXP;
components new AdcReadNowClientC();
Resource = AdcReadNowClientC;
ReadNow = AdcReadNowClientC;
AdcReadNowClientC.AdcConfigure -> Msp430ADCSensorsXP;
}
Msp430ADCSensorsYC.nc:
generic configuration Msp430ADCSensorsYC() {
provides interface Read<uint16_t>;
provides interface ReadStream<uint16_t>;
provides interface Resource;
provides interface ReadNow<uint16_t>;
}
implementation {
components new AdcReadClientC();
Read = AdcReadClientC;
components new AdcReadStreamClientC();
ReadStream = AdcReadStreamClientC;
components Msp430ADCSensorsYP;
AdcReadClientC.AdcConfigure -> Msp430ADCSensorsYP;
AdcReadStreamClientC.AdcConfigure -> Msp430ADCSensorsYP;
components new AdcReadNowClientC();
Resource = AdcReadNowClientC;
ReadNow = AdcReadNowClientC;
AdcReadNowClientC.AdcConfigure -> Msp430ADCSensorsYP;
}
Msp430ADCSensorsXP.nc:
#include "Msp430Adc12.h"
module Msp430ADCSensorsXP {
provides interface AdcConfigure<const msp430adc12_channel_config_t*>;
}
implementation {
const msp430adc12_channel_config_t config = {
// for accelerometer;
inch: INPUT_CHANNEL_A2,
sref: REFERENCE_VREFplus_AVss,
ref2_5v: REFVOLT_LEVEL_2_5,
adc12ssel: SHT_SOURCE_ACLK,
adc12div: SHT_CLOCK_DIV_1,
sht: SAMPLE_HOLD_4_CYCLES,
sampcon_ssel: SAMPCON_SOURCE_SMCLK,
sampcon_id: SAMPCON_CLOCK_DIV_1
};
async command const msp430adc12_channel_config_t*
AdcConfigure.getConfiguration()
{
return &config;
}
}
Msp430ADCSensorsYP.nc:
#include "Msp430Adc12.h"
module Msp430ADCSensorsYP {
provides interface AdcConfigure<const msp430adc12_channel_config_t*>;
}
implementation {
const msp430adc12_channel_config_t config = {
// for accelerometer;
inch: INPUT_CHANNEL_A3,
sref: REFERENCE_VREFplus_AVss,
ref2_5v: REFVOLT_LEVEL_2_5,
adc12ssel: SHT_SOURCE_ACLK,
adc12div: SHT_CLOCK_DIV_1,
sht: SAMPLE_HOLD_4_CYCLES,
sampcon_ssel: SAMPCON_SOURCE_SMCLK,
sampcon_id: SAMPCON_CLOCK_DIV_1
};
async command const msp430adc12_channel_config_t*
AdcConfigure.getConfiguration()
{
return &config;
}
}
That's all. Hope it helped.
Zhiyi
================================
> Hi Zhiyi,
>
> the original telosb doesn't have an accelerometer, but in general you
> can contribute by putting your code in "tinyos-2.x-contrib" [1]. If it
> is only about the msp430adc12_channel_config_t you might as well just
> send that code snippet to tinyos-help mailing list.
>
> Jan
>
> [1] http://docs.tinyos.net/tinywiki/index.php/Contributing_Code_to_TinyOS
>
> On Tue, Nov 29, 2011 at 1:57 AM, zhiyi <[email protected]> wrote:
>> Jan,
>> Thanks for help. My program works now. Actually it is a bit embarrassed
>> to
>> say the reason was that the sensor board was not plugged tightly enough
>> on
>> the mote.
>>
>> Also I noticed there was no adc12 modules for accelerometers on telosb.
>> Could I make such a module and contribute to the code tree of telosb? I
>> tested my module works fine for ADXL321.
>> Cheers,
>> Zhiyi
>>
>>
>>
>> On 28/11/2011, at 11:15 PM, Jan Hauer wrote:
>>
>>> Your configuration seems identical to the telosa/b configuration
>>> (S1087-01 light sensor on port A5). There is already a component (have
>>> you tried it?) ->
>>> tinyos-main/tos/platforms/telosa/chips/s10871/HamamatsuS10871TsrC.nc
>>>
>>> Jan
>>>
>>> On Sun, Nov 27, 2011 at 11:52 PM, zhiyi <[email protected]> wrote:
>>>>
>>>> Sorry for kicking the old dirts. I followed this thread but have not
>>>> found
>>>> what I needed.
>>>>
>>>> I have the similar problem with ADC: I can't read proper data from
>>>> light
>>>> sensors or any sensor on the sensor board EM1000.
>>>>
>>>> I have tried Oscilloscope and it works for the InternalTemperature and
>>>> InternalVoltage. What I did was I create a new sensor configuration
>>>> similar
>>>> to these two templates. My configuration is:
>>>>
>>>> �const msp430adc12_channel_config_t config = {
>>>>     inch: INPUT_CHANNEL_A5,
>>>>     sref: REFERENCE_VREFplus_AVss,
>>>>     ref2_5v: REFVOLT_LEVEL_1_5,
>>>>     adc12ssel: SHT_SOURCE_ACLK,
>>>>     adc12div: SHT_CLOCK_DIV_1,
>>>>     sht: SAMPLE_HOLD_4_CYCLES,
>>>>     sampcon_ssel: SAMPCON_SOURCE_SMCLK,
>>>>     sampcon_id: SAMPCON_CLOCK_DIV_1
>>>> }
>>>>
>>>> A5 is supposed to be the channel for S1087-01 light sensor on EM1000.
>>>> What I
>>>> read are the values gradually decreased and then within a few seconds
>>>> stayed
>>>> at a almost constant value (no change even if I changed the light). I
>>>> tried
>>>> HOLD_64, but there was no difference. I even took off the sensor
>>>> board,
>>>> there was no difference.
>>>>
>>>> My mote was CM4000, by the way. I placed my sensor configuration under
>>>> tos/chips/msp430/sensors, which I worked fine in terms of compilation.
>>>>
>>>> Could you please shed some light what I could try next?
>>>>
>>>> Many thanks for your help.
>>>>
>>>> Zhiyi
>>>>
>>>>
>>>>> Are there any of the "standard" telosb external sensors
>>>>> (Humidity/Temperature/Light) available on your telosb ? Can you test
>>>>> whether they give you good readings (or test your code with the
>>>>> internal sensors of the msp430).
>>>>>
>>>>>>> 2) open tinyos-2.x/tos/chips/msp430/adc12/Msp430Adc12.h and comment
>>>>>>> out "ADC12_P6PIN_AUTO_CONFIGURE". Now the Ax PINs are not
>>>>>>> automatically configured, so you should (e.g. in Boot.booted()), do
>>>>>>> this:
>>>>>>>
>>>>>>> call Port61.selectModuleFunc();
>>>>>>> call Port61.makeInput();
>>>>>>>
>>>>>>> (in your configuration:
>>>>>>> �components HplMsp430GeneralIOC;
>>>>>>> �MyDriverC.Port61 -> HplMsp430GeneralIOC.Port61;)
>>>>>>
>>>>>>
>>>>>> I'm not sure I understand - should I create a new driver myself?
>>>>>> Based
>>>>>> on an existing module?
>>>>>>
>>>>>
>>>>> The pin(s) on the msp430 to which your sensor is attached must be
>>>>> configured to be in input and module (ADC) function mode. This is
>>>>> done
>>>>> automatically if ADC12_P6PIN_AUTO_CONFIGURE is defined (which is the
>>>>> default). But the pins are switched to module function mode just
>>>>> before the conversion and back to IO function mode afterwards. Maybe
>>>>> there is a timing issue, so you could try to disable the default
>>>>> behaviour and try to take care of the pin configuration yourself.
>>>>>
>>>>>
>>>>> Jan
>>>>
>>>>
>>>>
>>
>> =======================
>> Zhiyi Huang
>> Dept of Computer Science
>> University of Otago
>> Email: [email protected]
>> Phone: 0064-3-4795680
>> Fax: 0064-3-4798529
>>
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help