Tuesday, 22 October 2013

TinyOS Micaz Mote / MDA 300 CA - ADC Read



Read data from the ADC of MDA300CA Board


MDA 300 CA  Data  Acquisition  Board











Introduction
Reading data from the ADC channels of any Aquision Board need some generic configuration file of the board, usually this file consists in the directory of the Data Aquisition Board component. Using this file we can read the data from any channels of the ADC in the device. On each channels have 16 bit of the data so we can get the range of the value coming from the Channels from 0 to 2 to the power of 16 . Here we have 8 channels for getting data from the sensor . By connecting the Sensor directly to the channel we can collect the sernsor data.



NesC Code for Reading data from ADC

Configuration File
/*
Author : Bipin.K

*/
configuration
#include "ADCRead.h"

configuration ADCReadAppC {}

implementation
{



components MainC, ADCReadC, LedsC;
components new TimerMilliC() as MyTimer;
/* Data Aquisition Board Component file */
components new SensorMDA300CA() as Mda300;
components SerialActiveMessageC;
components new SerialAMSenderC(AM_ADC);

ADCReadC.Boot -> MainC.Boot;
ADCReadC.Timer0 -> MyTimer;
ADCReadC.Leds -> LedsC.Leds;

ADCReadC.Packet -> SerialAMSenderC;
ADCReadC.AMPacket -> SerialAMSenderC;
ADCReadC.AMSend -> SerialAMSenderC;
ADCReadC.AMControl -> SerialActiveMessageC;

ADCReadC.Sensor_0_Read -> Mda300.ADC_0;

}

Module file



#include "ADCRead.h"

module ADCReadC {

uses {
interface Read<uint16_t> as Sensor_0_Read;
interface Packet;
interface AMPacket;
interface AMSend;
interface SplitControl as AMControl;
interface Boot;
interface Leds;
interface Timer<TMilli> as Timer0;
}
}
implementation
{

uint16_t val_sensor_0 = 0;
bool adc0Done = FALSE;
bool busy = FALSE;
message_t pkt;

task void readDoneTask();
event void Boot.booted()
{
call AMControl.start();
}




event void AMControl.startDone(error_t err) {

if(err == SUCCESS) {
if(call Leds.get() & LEDS_LED0) {
call Leds.led0Off();
}

call Timer0.startPeriodic(TIMER_PERIOD_MILLI);

} else {

if(call Leds.get() & LEDS_LED0) {
;
} else {
call Leds.led0On();
}

call AMControl.start();
}
}

event void AMControl.stopDone(error_t err) {
if(call Leds.get() & LEDS_LED0) {
call Leds.led0Off();
}
}



event void Timer0.fired() {
if(busy == FALSE) {
call Sensor_0_Read.read();
call Leds.led2Toggle();
}
}

event void Sensor_0_Read.readDone(error_t err, uint16_t val) {
///////////
// DEBUG //
///////////
call Leds.led1Toggle();

if(err == SUCCESS) {
val_sensor_0 = val;
adc0Done = TRUE;
post readDoneTask();
}
}


task void readDoneTask() {
if(adc0Done && adc1Done && adc2Done && adc3Done && adc4Done && adc5Done && adc6Done && adc7Done && !busy) {

ADCMsg* adcpkt = (ADCMsg*)(call Packet.getPayload(&pkt, sizeof(ADCMsg)));
if(adcpkt == NULL) {
return;
}
adcpkt->nodeid = TOS_NODE_ID;
adcpkt->adcvalue0 = val_sensor_0;
if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(ADCMsg)) == SUCCESS) {
busy = TRUE;
}

adc0Done = FALSE;
}
}
}


Makefile

COMPONENTS=ADCReadAppC
SENSORBOARD=mda300
include$(MAKERULES)



make install micaz mib510,/dev/ttyUSB0


Hardware Configuration
********************
This is not enough to get the data from the sensor. Besides that we should have to add 2X1Kohn Resistance to the Data Aqusition Board . This enables the I2C data bus in the board.

VCC – CLK : 1 Kohm
VCC -DATA : 1 Kohm

No comments:

Post a Comment