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.

Not able to do analog sensor data transmission using ZSTack(ZStack-Exp5438-2.5.1) (Generic App Sample Example)

Other Parts Discussed in Thread: MSP430F5438, CC2520, Z-STACK, MSP430F5438A

Hello ,

I am working on msp430f5438 experimenter board with cc2520 for WSN .i am using Z-Stack (Zstack-exp5438-2.5.1). for configuring the nodes.i am using GENERIC APP sample example for data transmission.

 i am sending sine wave using function generator from the transmission node but at the receiver node(coordinator) i am not able to produce perfect sine wave when checked in python based gui.i want to achieve a frequency band of 1hz to 250 hz  for my application data.

now the adc setting i have used are shown below.i have used ADC of 8bit.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{

//ADC12CTL0 &= ~ADC12ENC; // Disable ADC12 conversions
//REFCTL0 &= ~REFON; // Disable reference


theMessageData[index1] = (ADC12MEM0);

index1++;
if (index1 == 1)
{
index1 = 0;
ADC12CTL0 &= ~ADC12ENC;
__bic_SR_register_on_exit(LPM0_bits);
}

// __delay_cycles(12000);------------>should i use delay here???



}

void adc(void)
{

P6SEL |= BIT7; // Pin 7.6 and 7.7 are inputs from the accelerometer to the ADC => they are configured as inputs to the ADC
P6DIR &= ~BIT7;


P7DIR=BIT5;
P7OUT=BIT5;
REFCTL0 |= REFMSTR+REFVSEL_2+REFON+REFTCOFF;



ADC12CTL0 = ADC12ON + ADC12SHT0_6+ ADC12MSC; 
ADC12CTL1 = ADC12SHP + ADC12CONSEQ_2 + ADC12SSEL_3 +ADC12DIV_3 + ADC12PDIV ;  //7075hz hz sampling freq
ADC12CTL2 = ADC12RES_0; // +ADC12TCOFF; // Resolution=08 bits, 9 clock cycle conversion time on time

ADC12MCTL0 = ADC12INCH_7+ ADC12SREF_1;
ADC12IE = BIT0;
__delay_cycles(200000); // Allowing reference voltage to stabilize




}
void adctrigger(void)
{
ADC12CTL0 |= ADC12ENC | ADC12SC;
// ADC12CTL0 |= ADC12SC;
__bis_SR_register(LPM0_bits+GIE);
__no_operation();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

and for the Send Message Timeout in GenericApp.h

#define GENERICAPP_SEND_MSG_TIMEOUT   250   -------------------->HOW TO CONFIGURE THIS VALUE???

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  • 1. It is not good to put a delay in ISR.
    2. Why do you use this "send message timeout"? It looks weird to me.
  • Sir,
    The "send message timeout" comes with the ZStack.
    I have not included it.
    I think it is the time delay or interval between transmission of two consecutive packets from a node.
  • Sir,
    Also when we varying the "send message timeout" values the signal gets distorted.not able to understand what is the transmission mechanism flow.also we are using single byte of data field in the transmission of frame.
  • Sorry, I think I misunderstand your question. GENERICAPP_SEND_MSG_TIMEOUT is used for send message every 250 miliseconds since it is set to 250.
  • Sir,
    What should we do now to rectify our problem.
  • What is your problem now?
  • Sir,
    We are not able to do correct data transmission. Whatever values we adjust for the timeout delay, adc sampling frequency we are not able to get smooth wave at receiver side for every frequency.

    Current settings are :

    Packet data size : 80 bytes
    ADC Sampling frequency: 725.33 Hz
    Timeout delay: 250ms

    I am getting smooth sine wave for frequencies that are multiple of 9Hz i.e. 9 , 18, 27, 90, 180, 270, etc...

    According to me this is because

    (1/725.33)*80 = 110ms

    1/9 = 111ms

    So, the values are correct but for any frequency other than 9Hz the samples are taken at wrong place so their reconstruction is not proper but for 9Hz and its multiples the samples are taken at proper place and so the reconstruction.

    I think above inference is wrong because for some different settings when I applied the same logic I did not get the expected result

    What should I do now to get smooth sine wave for frequencies between 0.1Hz to 250Hz?

    Also as discussed in different thread we are not able to set the timeout value less than 150 ms so is there a solution for that.

  • If you don't do ADC reading and just try to send 80 bytes data every 150ms, can you see the message sent smoothly?
  • yes sir when we are sending integer data by using 80bytes at 150ms we are able to see smooth and expected data.
    the loop which we have used for this is:

    ////////////////////////////////////////////////////////////////////////////////////
    byte theMessageData[80];


    for (uint8 i=0; i<TransmitApp_MaxDataLength; i++)
    {
    theMessageData[i] = i;
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////
  • So, the problem should be your ADC reading. How do you do this continuous ADC reading?
  • Sir,

    I am calling the ADC in  GenericApp_Init function and adc triggering is being done in process event before sending the data.

    ADC being used is of 8 bit resolution.

    I have used following code as posted:

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    #pragma vector=ADC12_VECTOR

    __interrupt void ADC12_ISR(void)

    {

    //ADC12CTL0 &= ~ADC12ENC; // Disable ADC12 conversions

    //REFCTL0 &= ~REFON; // Disable reference

    theMessageData[index1] = (ADC12MEM0);

    index1++;

    if (index1 == 80)

    {

    index1 = 0;

    ADC12CTL0 &= ~ADC12ENC;

    __bic_SR_register_on_exit(LPM0_bits);

    }

    }

    void adc(void)

    {

    P6SEL |= BIT7; // Pin 7.6 and 7.7 are inputs from the accelerometer to the ADC => they are configured as inputs to the ADC

    P6DIR &= ~BIT7;

    P7DIR=BIT5;

    P7OUT=BIT5;

    REFCTL0 |= REFMSTR+REFVSEL_2+REFON+REFTCOFF;

    ADC12CTL0 = ADC12ON + ADC12SHT0_6+ ADC12MSC;

    ADC12CTL1 = ADC12SHP + ADC12CONSEQ_2 + ADC12SSEL_3 +ADC12DIV_3 + ADC12PDIV ;  //7075hz hz sampling freq

    ADC12CTL2 = ADC12RES_0; // +ADC12TCOFF; // Resolution=08 bits, 9 clock cycle conversion time on time

    ADC12MCTL0 = ADC12INCH_7+ ADC12SREF_1;

    ADC12IE = BIT0;

    __delay_cycles(200000); // Allowing reference voltage to stabilize

    }

    void adctrigger(void)

    {

    ADC12CTL0 |= ADC12ENC | ADC12SC;

    // ADC12CTL0 |= ADC12SC;

    __bis_SR_register(LPM0_bits+GIE);

    __no_operation();

    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////

  • When and how do you call your adc() function?
  • Sir, 

    As I explained earlier, adc()  is being called in GenericApp_Init function and adctrigger()  is being called in process event GenericApp_ProcessEvent function before transmission of data using GenericApp_SendTheMessage() function

  • Can you show me how you use adctrigger() in GenericApp_ProcessEvent()?
  • Sir,

    I am using the following code for transmitting the data :

    ////////////////////////////////////////////////////////////////////////////////////////////////

    if ( events & GENERICAPP_SEND_MSG_EVT )

     {

            adctrigger();

       // Send "the" message

       GenericApp_SendTheMessage();

       // Setup to send message again

       osal_start_timerEx( GenericApp_TaskID,

                           GENERICAPP_SEND_MSG_EVT,

                           GENERICAPP_SEND_MSG_TIMEOUT );

       // return unprocessed events

       return (events ^ GENERICAPP_SEND_MSG_EVT);

     }

    /////////////////////////////////////////////////////////////////////////////////////////////////////

  • It seems that you only do one ADC reading in GENERICAPP_SEND_MSG_EVT. Am I right? Can you also show me what is in your GenericApp_SendTheMessage()?
  • Sir,

    I enable the ADC in adctrigger function and then in ADC ISR the values are getting stored in theMessageData array and we exit the interrupt only when 80 bytes of data are stored.

    We have set ADC12CTL1 = ADC12CONSEQ_2 , so this implies repeat single channel

    So according to me I am not taking one adc reading. Please rectify if I am wrong.

    Also for GenericApp_SendTheMessage(), I am posting the code below:

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static void GenericApp_SendTheMessage( void )
    {
    uint16 len= TransmitApp_MaxDataLength;

    if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
    GENERICAPP_CLUSTERID,
    len, //(byte)osal_strlen( theMessageData ) + 1,
    (byte *)&theMessageData,
    &GenericApp_TransID,
    AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
    {
    // Successfully requested to be sent.
    }
    else
    {
    // Error occurred in request to send.
    }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////

    For uint16 len= TransmitApp_MaxDataLength;

    I am using following code:

    //////////////////////////////////////////////////////////////////

    uint16 TransmitApp_MaxDataLength;

    void GenericApp_Init( uint8 task_id )

    {

    afDataReqMTU_t mtu;
    mtu.kvp = FALSE;
    mtu.aps.secure = FALSE;
    TransmitApp_MaxDataLength = afDataReqMTU( &mtu );


    TransmitApp_MaxDataLength = (TransmitApp_MaxDataLength/99)*80;
    ...
    ...
    ...
    ...
    }
  • I am not an expert of MSP430 but I think your codes in ADC12_ISR are weird. I suggest you to check if the codes in ADC12_ISR cause your unsmooth problem.
  • Sir,
    I will be checking my ADC_ISR code for MSP430,meanwhile can u please suggest some ADC_ISR codes.
    it will be of very much help.
    thank you

  • sir,
    we have gone through the ADC code in the link provided by you,also we have checked with the sample codes for ADC provided by msp430f5438a codes from TI.
    also the DC values of the analog signal from function generator is coming correct at receiver.
    so can you plz say what is not correct in the ADC code according to you
  • I said I am not MSP430 expert. I just think your ADC code is weird not incorrect. I see that you would stop ADC only when index1 is equal to 80. This means ADC interrupt would keep rising in your application and I think this would make Z-Stack doesn't have spare time to send message.
  • Sir,

    You said: ADC interrupt would keep rising in your application and I think this would make Z-Stack doesn't have spare time to send message.

    Please can you elaborate on this. I thought we are supposed to collect the data and then send it on the air and that was our approach for constructing ADC_ISR logic.

     

  • You set ADC12CTL0 &= ~ADC12ENC only when index1 is equal to 80 in ADC ISR function. It seems this ADC ISR would keep rising when index1 counts from 1 to 80 and this continuous ISR rising would block Z-stack to transmitting message. I don't know if MSP430 can do continuous ADC reading to an memory using DMA. If it has this capability, I would suggest you using this ADC DMA reading instead of ISR.