This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

external sensors on eZ430RF2500 target board (ADC10 registers)

Other Parts Discussed in Thread: MSP430F2274, CC2500

greetings !

i am new to the world of micro controllers and programming, and  am using the eZ430R-F2500 development kit. after reading the necessary documents, and the related posts on this forum, lots of things are still not that much clear to me, specially the registers that i wrote in red text. that's why am making a new post.

i want to connect two external sensors to the target board, soil moisture (seeedstudio.com/wiki/Grove_-_Moisture_Sensor) and a humidity+temperature sensor (DTH22, adafruit.com/products/385). each sensor will be connected to an externally 5V battery. the ADC10 code is below. i still have to configure the equations for humidity and moisture at the end of this code.

while (1)

{
volatile long temp;

int degC, volt;

int humidity;

int moisture;

int results[3];


SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, "" );

__bis_SR_register(LPM3_bits+GIE); // LPM3 with interrupts enabled

SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, "" );

BSP_TOGGLE_LED2();

/* integrated temperature sensor*/


ADC10CTL1 = INCH_10 + ADC10DIV_4; // Temp Sensor ADC10CLK/5

ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR;

for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled

results[0] = ADC10MEM;

ADC10CTL0 &= ~ENC;

/*external sensors humidity and moisture*/


P2SEL = 0x03;   // peripheral mode

P2DIR = 0xFC;

P2OUT = 0x00;

ADC10AE0 = 0x03;       //A0/A1 analog input enabled

ADC10DTC0 = ADC10CT; // continuous transfer

ADC10DTC1 = 0x02;

ADC10SA = 0x200;

ADC10CTL1 = CONSEQ_3 + ADC10SSEL_0 + ADC10DIV_4 + SHS_0 + INCH_1;      // soil moisture/humdity sensor, Repeat sequence of channels

ADC10CTL0 = ADC10IE + ADC10ON + REFON + ADC10SR + MSC + ADC10SHT_3 + SREF_1;      //multiple sample and conversion

__delay_cycles(240);

ADC10CTL0 |= ENC + ADC10SC;

__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled

results[1] = ADC10MEM;

ADC10CTL0 &= ~ENC;

/*voltage*/

ADC10CTL1 = INCH_11; // AVcc/2

ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;

for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled

results[2] = ADC10MEM;

ADC10CTL0 &= ~ENC;

ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power


// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
// the temperature is transmitted as an integer where 32.1 = 321
// hence 4230 instead of 423

temp = results[0];

degC = ((temp - 673) * 4230) / 1024;

if( tempOffset != 0xFFFF )

{
degC += tempOffset;
}

/*message format, UB = upper Byte, LB = lower Byte
-------------------------------
|degC LB | degC UB | volt LB |
-------------------------------
0 1 2
*/

temp = results[2];

volt = (temp*25)/512;

msg[0] = degC&0xFF;

msg[1] = (degC>>8)&0xFF;

msg[2] = volt;

msg[3] = humidity;

msg[4] = moisture;

am i right so far with the code. can anyone help to correct me ?

thanks alot

Tahir Khan

  • Hello Tahir Khan,

    P2SEL = 0x03;   // peripheral mode

    P2DIR = 0xFC;

    P2OUT = 0x00;

     

    This code is basically setting P2.0 and P2.1 to peripheral mode (as compared to I/O mode), setting both pins to the input direction, and setting all outputs low.  This is simply initializing the pins to be analog inputs.

    ADC10DTC1 = 0x02;

    ADC10SA = 0x200;

     

    The first line sets the number of DTC (data transfer controller) transfers per block to 2.  The second line sets the start address for the DTC to 200 hex.  So we are basically automatically transferring 2 conversion results from ADC10MEM to 200 hex.  When the DTC is enabled, a data transfer is triggered each time the ADC10 completes a conversion and loads the result to ADC10MEM.  

    All of this can be found in the Family User's Guide.  You may have to practice using the ADC10 in order to better understand how it's operating.  Also remember that the F2274 can only handle a max Vcc of 3.6 V and your external sensors should be powered likewise.

    Hope this helps,

    Ryan

  • Greetings Ryan !

    thanks for the response. am sorry but i will be bothering you with some questions, which might sound stupid to you and others on the form, but at least it will help me understand the things involved with the kit. 

    if one has to set Ax, the bit corresponding Ax has to be set to 1 in PxSEL register, right ? in the code example MSP430F22x4_adc10_10.c, P2.0, 2.1, 2.2 are set to INCH0, 1 and 2, but i dont see the P2SEL=0x07 register, just the ADC10AE0 |= 0x07. for  INCHs, i have to set the pins to peripheral mode, right ? or i got the things wrong ?

    my both sensors comes with 4 pins, Vdd, GND, SIG(nal), and a Null, and they require 5 volts each. thats why i want to have external voltage source.  you said the sensors should be powered 3.6v, how, i dont get this point.

    thanks 

  • Hi there !

    got the answar for the PxSEL and the ADC10AE0 at the following link.

    http://mspsci.blogspot.de/2011/10/tutorial-15b-using-adc10.html

    it says

    ''ADC10AE0 enables the ADC function of the external pins being used. (This is necessary, because P1SEL changes the operation of those pins to a function other than ADC; since it's a binary value, P1SEL can only configure two different operations. This register frees up those pins for uses other than just ADC!) ADC10AE1 performs a similar function, but only for devices with more than 8 analog inputs''


    but still i dont get the 3.6 V part.

    thanks alot

  • I'm glad that you were able to find the answer to your PxSEL question!  Now recall that I didn't say you had to use 3.6V, just that MSP430s have a supply voltage (Vcc) range of up to 3.6 V.  Looking at the provided links for both your moisture and temp/humidity sensors, I see that a supply voltage somewhere between 3.3 to 3.6 V is acceptable for them as well.  A 5 V supply is not recommended because MSP430 input pins are never supposed to be supplied with anything greater than Vcc + 0.3 V (there are internal clamp diodes that will short the input to ground if the input exceeds Vcc + 0.7 V for up to 2 mA of current, but we should not rely on this feature).  

    Furthermore, by supplying both the MSP430 and the external sensors with the same supply voltage and selecting the ADC references at Vr+ = Vcc (or Vref+ for external reference if desired) and Vr- = Vss, the sensors will be sending a voltage of 0 to Vcc that the MSP430 will be able to convert to a value between 0 and 1023.  Now just plug in your algorithms and you've got moisture and temp/humidity readings!

    Hope this helps,

    Ryan

  • Greetings Ryan !

    i was just following the post below, where the person has connected a sensor with the external power (5V).

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/18890/570947.aspx#570947

    one thing, the end point (where i will be connecteing my sensors) have only power of 3V (2 x 1.5 AA battery),  now the minimum voltage requirement for MSP430F2274 and the CC2500 is 1.8 V while for both the sensors is 3.3 V individually.

    if i just rely only on 3V battery for all the four components, wont it effect the functionality of the CC2500 tranceiver, i mean the transmitted and recieved signals ? 

    thanks alot

  • You mean to say that you are powering all four devices with a Vcc of 3 V?  This is fine for the CC2500 and MSP430F2274 since that voltage is inside of the allowable supply range.  I don't know about the external sensors, however, you will need to look into that further.  The range of the CC2500 is not optimized at 3 V since it is not the maximum allowable Vcc but it is most likely still suitable for your needs.

    Regards,

    Ryan

  • Greetings!

    thanks for the help and the comments so far.

    just following the example of demo code of the eZ430-RF2500, i made the following changes in my ED code, for connecting two external sensors on the target board.

    while (1)
    {
    volatile long temp;
    int degC, volt;
    int humidity;
    int moisture;
    int results[3];


    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, "" );
    __bis_SR_register(LPM3_bits+GIE); // LPM3 with interrupts enabled
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, "" );

    BSP_TOGGLE_LED2();

    /*integrated temperature sensor*/

    ADC10CTL1 = INCH_10 + ADC10DIV_4; // Temp Sensor ADC10CLK/5
    ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR;
    for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
    results[0] = ADC10MEM;

    ADC10CTL0 &= ~ENC;

    /*humidity and moisture*/

    P2DIR = 0xFC;

    P2OUT = 0x00;

    ADC10AE0 |= 0x03;                              // A0 and A1 analog input enabled

    // ADC10CTL0 &= ~ENC;                     // disable ADC10 during initialization
     
    ADC10CTL0 = ADC10IE + ADC10ON + MSC + ADC10SHT_3 + SREF_0;                         // Enable multiple sample and conversion

    ADC10CTL1 = CONSEQ_3 + ADC10SSEL_0 + ADC10DIV_4 + SHS_0 + INCH_1;         // soil moisture and humdity sensor, Repeat sequence of channels

    ADC10DTC0 |= ADC10CT;                        // Data transferred continuously after every conversion

    ADC10DTC1 = 2;

    ADC10SA |= 0x200;                                    // (unsigned int)512

    ADC10CTL0 |= ENC + ADC10SC;                  // enable ADC10

    __bis_SR_register(CPUOFF + GIE);               // LPM0 with interrupts enabled

    results[1] = ADC10MEM;                                    // save result

    ADC10CTL0 &= ~ENC; // stop ADC10

    /*voltage*/

    ADC10CTL1 = INCH_11; // AVcc/2
    ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
    for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
    results[2] = ADC10MEM;
    ADC10CTL0 &= ~ENC;
    ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power

    // oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
    // the temperature is transmitted as an integer where 32.1 = 321
    // hence 4230 instead of 423

    temp = results[0];                             // integrated temperature sensor
    degC = ((temp - 673) * 4230) / 1024;
    if( tempOffset != 0xFFFF )
    {
    degC += tempOffset;
    }
    /*message format, UB = upper Byte, LB = lower Byte
    -------------------------------
    |degC LB | degC UB | volt LB |
    -------------------------------
    0 1 2
    */

    temp = results[2]; // voltage
    volt = (temp*25)/512;


    temp = results[1];                               // humidity and moisture
    humidity = (temp*2500)/1023;
    if( tempOffset != 0xFFFF )
    {
    humidity += tempOffset;
    }

    temp = results[1];
    moisture = (temp*2500)/1023;
    if( tempOffset != 0xFFFF )
    {
    moisture += tempOffset;
    }

    msg[0] = degC&0xFF;
    msg[1] = (degC>>8)&0xFF;
    msg[2] = volt;

    msg[3] = humidity&0xFF;
    msg[4] =(humidity>>8)&0xFF;

    msg[5] = moisture&0xFF;
    msg[6]= (moisture>>8)&0xFF;

    if (SMPL_SUCCESS == SMPL_Send(linkID1, msg, sizeof(msg)))
    {
    BSP_TOGGLE_LED2();
    }
    else
    {
    BSP_TOGGLE_LED2();
    BSP_TOGGLE_LED1();
    }
    }
    }

    i have not even connected my external sensors yet to the developmental pins and i get the following reading in the HyperTerminal

    Node:HUB0,Temp: 31.7C,Battery:3.6V,Strength:000%,Humidity:015.2%,Moisture:004.4,RE:no
    Node:0001,Temp: 25.9C,Battery:2.5V,Strength:064%,Humidity:006.3%,Moisture:000.3,RE:no
    Node:HUB0,Temp: 31.7C,Battery:3.6V,Strength:000%,Humidity:015.2%,Moisture:004.4,RE:no
    Node:HUB0,Temp: 32.1C,Battery:3.6V,Strength:000%,Humidity:015.2%,Moisture:004.4,RE:no
    Node:HUB0,Temp: 32.1C,Battery:3.6V,Strength:000%,Humidity:015.2%,Moisture:004.4,RE:no
    Node:0001,Temp: 25.9C,Battery:2.5V,Strength:063%,Humidity:000.1%,Moisture:000.6,RE:no

    my questions are:

    1- i know something, rather too much is wrong with the code, coz i think the HyperTerminal should read humidity and moisture zero, both at the access and end node. can someone point out ? there is not that much fluctuation on end node's moisture reading (000.2 to 000.6) but a lot for humidity (000.1 to 25.1) .

    2-can i read voltage by simply connecting the voltmeter pins/leads to the programmed developmental pins, like red terminal (+ve) going to A0 (P3), or A1(P4) and black terminal (-ve) to GND ?

    3- what is the red colored code doing ? i know i am getting these values coz of wrong settings there.

    thanks a lot.

    Tahir Khan

  • So are your analog inputs connected to the external sensors, grounded, or floating?  If they're floating, you're going to get some minuscule voltage at the analog inputs which explains the small (but not zero) readings at the ADC.  If you want to test for true zero, ground your analog input pins.  Or you could connect the external sensors and see what happens.

    It looks like humidity and moisture are saved in results[1] which stored the ADC10MEM value after sampling.  The red code uses an algorithm (multiply by reference voltage in millivolts and divide by sample bit range) and possible offset (not defined in this section of code) to calculate meaningful values, which it then stores in a message array to send to HyperTerminal.  By inspection the code for producing humidity and moisture look exactly the same, so I'm not sure how HyperTerminal is showing different values.

    Ryan

**Attention** This is a public forum