Hello,
i am new to tinyos programming. i am using a telosb plattform called Kmote.
I have problems with the ADC. unfortunatley i cant post my entire code in
zip format so i posted the entire code. i have a temperature sensor in
combination with a operational amplifier and the ouptut is connected to the
ADC2 chanel.
I have posted my entire code. Both, the configuration file and the module
file. i dont understand why i am getting values around 932 even if i unplug
the cable from the ADC's input.
the small project i am trying to implement is that i send a sensor value
from one board to another one, which displays me that on the terminal. what
i am doing wrong?
i am thankful to any advice you can give me...
regards,
Kmote
#include<stdio.h>
#include<UserButton.h>
#include"MoteToMote.h"
#include "Msp430Adc12.h"
module MoteToMoteSensorC
{
provides
{
interface AdcConfigure<const msp430adc12_channel_config_t*> as
AdcChanelConfig;
}
uses //General Interfaces
{
interface Boot;
interface Leds;
interface Timer<TMilli> as MilliTimer;
}
uses //UserButton
{
interface Get<button_state_t>;//state of the button
interface Notify<button_state_t>;//if user presses userbutton
}
uses//UART Interfaces
{
interface SplitControl as UartControl;
interface AMSend as UartAMSend;
interface Receive as UartReceive;
interface Packet as UartPacket;
}
uses//Radio Interfaces
{
interface SplitControl as RadioAMControl;
interface AMPacket as RadioAMPacket;
interface AMSend as RadioAMSend;
interface Receive as RadioReceive;
interface Packet as RadioPacket;
}
uses interface Read<uint16_t> as AdcChanelRead;
}
implementation
{
//global variables!!!
bool _radioBusy = FALSE;//current status of radio
message_t _packet;//toplayer of message or packet
//========================================
uint16_t luminance, start_transmission=0;
/* ======================== ADC CONFIGURATION ========================*/
const msp430adc12_channel_config_t config =
{
//inch: SUPPLY_VOLTAGE_HALF_CHANNEL,
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
};
/* ===================================================================*/
event void Boot.booted()
{
call UartControl.start();
call Notify.enable();//Notify interface enabled
call RadioAMControl.start();//enabel radio chip and start
call AdcChanelRead.read();
}
event void MilliTimer.fired()
{
MoteToMoteMsg_t *msg = call RadioPacket.getPayload(&_packet,
sizeof(MoteToMoteMsg_t));
if(start_transmission==1)
{
if(call AdcChanelRead.read()==SUCCESS)
{
}
else
{
//call Leds.led2On();
}
if(_radioBusy == FALSE)//is radio busy....?
{
msg->MoteID = TOS_NODE_ID;//when compiler
compiling the code, comment
through shell during the application. set internal ID of the sensor board!!
msg->Data = luminance;
//Sending the packet
if(call RadioAMSend.send(AM_BROADCAST_ADDR, &
_packet,
sizeof(MoteToMoteMsg_t))==SUCCESS)//send packet through radio
{
_radioBusy=TRUE;
}
}
}
}
event void Notify.notify(button_state_t val)//argument entweder 0 oder
1,
if user presses userbutton
{
start_transmission=1;
}
event void RadioAMSend.sendDone(message_t *msg, error_t error)
{
if(msg == & _packet)
{
_radioBusy=FALSE;
}
}
event void RadioAMControl.startDone(error_t error)
{
if(error == SUCCESS)//'SUCCESS' constant in TinyOS and its
constant value
is 0
{
//call Leds.led0On();//if it starts without problems
==> led 0 on!
}
else
{
call RadioAMControl.start();//--> Loop until AMControl
starts!
}
}
event void RadioAMControl.stopDone(error_t error)
{
// TODO Auto-generated method stub
}
event message_t * RadioReceive.receive(message_t *msg, void *payload,
uint8_t len)
{
if(len == sizeof(MoteToMoteMsg_t))
{
//empfangen der nachricht und schreiben in das
incomingPacket
MoteToMoteMsg_t *incomingPacket =
(MoteToMoteMsg_t*)payload;
//incomingPacket->MoteID == 2;
uint16_t data = incomingPacket->Data;//Data wird in die
variable "date"
gespeichert
printf("ID = %d, Data Received: %d\n",TOS_NODE_ID,
data);
if(data > 25)//user of the other mode pressed the button
{
call Leds.led0Toggle();
call Leds.led1Off();
}
if(data < 25)//user of the other mode released the
button
{
call Leds.led1Toggle();
call Leds.led0Off();
}
}
return msg;
}
event message_t * UartReceive.receive(message_t * bufPtr, void *
payload,
uint8_t len)
{
return bufPtr;
}
event void UartAMSend.sendDone(message_t * bufPtr, error_t error)
{
}
event void UartControl.startDone(error_t err)
{
if(err == SUCCESS)
{
call MilliTimer.startPeriodic(1000);
}
}
event void UartControl.stopDone(error_t err)
{
}
event void AdcChanelRead.readDone( error_t result, uint16_t val )
{
if (result == SUCCESS)
{
call Leds.led0Toggle();
call Leds.led1Toggle();
}
//luminance=2.5 * (val/4096.0) * 6250.0 / 500.0;
luminance=(uint16_t)val;
printf("\n\nWert = %d\n\n", val);
}
async command const msp430adc12_channel_config_t*
AdcChanelConfig.getConfiguration()
{
return &config; // must not be changed
}
}
#include"MoteToMote.h"
configuration MoteToMoteSensorAppC
{
//Not interrested now!
}
implementation
{
//general
components MoteToMoteSensorC as App;
components SerialActiveMessageC as AM;
components MainC; //for Boot interface
components LedsC;
components new TimerMilliC();
App.Boot -> MainC;
App.Leds -> LedsC;
App.MilliTimer->TimerMilliC;
//Userbutton
components UserButtonC;
App.Get -> UserButtonC;
App.Notify -> UserButtonC;
//Uart
App.UartControl->AM;
App.UartReceive->AM.Receive[AM_TEST_SERIAL_MSG];
App.UartAMSend->AM.AMSend[AM_TEST_SERIAL_MSG];
App.UartPacket->AM;
//Radio
components ActiveMessageC;
components new AMSenderC(AM_RADIO);//requires initilaiation!!
components new AMReceiverC(AM_RADIO);
App.RadioReceive->AMReceiverC;
App.RadioAMSend->AMSenderC;
App.RadioPacket->AMSenderC;
App.RadioAMPacket -> AMSenderC;
App.RadioAMControl -> ActiveMessageC;
//for writing into serial port
components SerialPrintfC;
//ADC
components new AdcReadClientC();
App.AdcChanelRead -> AdcReadClientC;
AdcReadClientC.AdcConfigure -> App.AdcChanelConfig;
}
--
View this message in context:
http://tinyos-help.10906.n7.nabble.com/Problems-getting-true-Values-from-ADC-telosb-tp24512.html
Sent from the TinyOS - Help mailing list archive at Nabble.com.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help