Alessandro Balvis
Centro Ricerche Enel - Pisa
[EMAIL PROTECTED]



----- Original Message ----- 
From: "Alessandro Balvis" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, November 09, 2005 6:33 PM
Subject: Fw: [Tinyos-help] Programming FFT with MDA300


>
>
>
> Alessandro Balvis
> Centro Ricerche Enel - Pisa
> [EMAIL PROTECTED]
>
>
>
> ----- Original Message ----- 
> From: "Alessandro Balvis" <[EMAIL PROTECTED]>
> To: "Michael Schippling" <[EMAIL PROTECTED]>
> Sent: Wednesday, November 09, 2005 6:31 PM
> Subject: Re: [Tinyos-help] Programming FFT with MDA300
>
>
> > I eliminate the state variable, but it still didn't work.
> > Also, I have reduced the number of the samples, beause I suspected that
> > something was wrong
> > with the timing of the task. In fact the MCU couldn't compute the FFT
and
> > send the packet in
> > the same time that the MDA300 finished the acquisition of data. With N=8
> for
> > example everything
> > works without problem. I would increase the interval of the timer, but
the
> > max number is 1024*31 (in fact is 32768).
> > How can I use the timer with a larger interval? It's possible?
> > Thanks.
> >
> >
> > Alessandro Balvis
> > Centro Ricerche Enel - Pisa
> > [EMAIL PROTECTED]
> >
> >
> >
> > ----- Original Message ----- 
> > From: "Michael Schippling" <[EMAIL PROTECTED]>
> > To: "Alessandro Balvis" <[EMAIL PROTECTED]>
> > Cc: <[email protected]>
> > Sent: Tuesday, November 08, 2005 11:35 PM
> > Subject: Re: [Tinyos-help] Programming FFT with MDA300
> >
> >
> > > I would suspect the use of your "sending_packet" state variable.
> > > It may be getting reset by the sendDone() in the midst of doing
> > > your data acquisition, which will prevent the next message start.
> > > MS
> > >
> > >
> > > Alessandro Balvis wrote:
> > > > Hy, I'm working with the MDA300 and Micaz for data analysis of a
> signal.
> > > > I have some problem with the code about the sending data. Everything
> > > > works good until the event "Send.done", that block the acquisition
of
> > > > data from MDA300, while the Timer is still working. I try to send
some
> > > > results from the implemented FFT, just to try the send task with the
> > > > radio. It works just once, the first time, then it stops. Why the
> event
> > > > blocks the execution of FFT? There is some problem with the timing
of
> > > > the command and event?
> > > > I list the code for explication, any suggest or comment is
> appreciated,
> > > > thanks.
> > > >
> > > >
> > > > Alessandro Balvis
> > > > Centro Ricerche Enel - Pisa
> > > > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> > > >
> > > >
> > > >
> > > > includes sensorboard;
> > > >
> > > > includes sinewave;
> > > >
> > > > module MDA300M
> > > >
> > > > {
> > > >
> > > >     provides interface StdControl;
> > > >
> > > >     uses {
> > > >
> > > >         interface Leds;
> > > >
> > > >         //Sampler Communication
> > > >
> > > >         interface StdControl as SamplerControl;
> > > >
> > > >         //interface StdControl as SubControl;
> > > >
> > > >         interface Sample;
> > > >
> > > >         //interface LoggerWrite;
> > > >
> > > >         //interface LoggerRead;
> > > >
> > > >         //RF communication
> > > >
> > > >         interface StdControl as CommControl;
> > > >
> > > >         interface Send;
> > > >
> > > >         interface RouteControl;
> > > >
> > > >         interface CC2420Control as Radio;
> > > >
> > > >         //Timer
> > > >
> > > >         interface Timer;
> > > >
> > > >     }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > > implementation
> > > >
> > > >     {
> > > >
> > > >         #define RATE_TIMER 50 // in decimi di secondo
> > > >
> > > >         #define ANALOG_SAMPLING_TIME 1
> > > >
> > > >         #define MDA300_PACKET1 1
> > > >
> > > >         #define INTERVAL_TIMER 1024 * 14
> > > >
> > > >         #define NSIGNAL 128
> > > >
> > > >         uint16_t fr[NSIGNAL];
> > > >
> > > >         uint16_t fi[NSIGNAL];
> > > >
> > > >         uint16_t index;
> > > >
> > > >         #define LOG2NSIGNAL 7                    //ATTENZIONE!!
> > > > Impostare bene il parametro
> > > >
> > > >         uint16_t mr, nn, i, j, l, k, istep, n, shift;
> > > >
> > > >         uint16_t qr, qi, tr, ti, wr, wi;
> > > >
> > > >         uint16_t m;
> > > > //dimensione dei dati 2^m
> > > >
> > > >         //#define PACKET1_FULL 1              // contatore per
> riempire
> > > > pacchetto
> > > >
> > > >         #define MSG_LEN 40                          // excludes TOS
> > > > header, but includes xbow header
> > > >
> > > >         enum {
> > > >
> > > >         SENSOR_ID = 7,
> > > >
> > > >         POWER = 9,
> > > >
> > > >         FREQ = 10,
> > > >
> > > >         DATA_START = 12,
> > > >
> > > >         } PacketDataEnum;
> > > >
> > > >         /* Messages Buffers */
> > > >
> > > >         //TOS_Msg packet;
> > > >
> > > >         TOS_Msg radio_send_buffer;
> > > >
> > > >         TOS_MsgPtr radio_msg_ptr;
> > > >
> > > >         char *ptr_store;
> > > >
> > > >         uint8_t msg_status;
> > > >
> > > >         uint16_t Len;
> > > >
> > > >         uint8_t power;
> > > >
> > > >         uint16_t freq;
> > > >
> > > >         uint8_t nsam, z;
> > > >
> > > >         bool working;
> > > >
> > > >         bool sending_packet;
> > > >
> > > >         int8_t record[4];
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Inizializzo i componenti.
> > > >
> > > > *
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > > command result_t StdControl.init() {
> > > >
> > > >     call Leds.init();
> > > >
> > > >     atomic {
> > > >
> > > >         radio_msg_ptr = call
Send.getBuffer(&radio_send_buffer,&Len);
> > > >
> > > >     }
> > > >
> > > >     msg_status = 0;
> > > >
> > > >     nsam = NSIGNAL-1;
> > > >
> > > >     z = 0;
> > > >
> > > >     working = FALSE;
> > > >
> > > >     sending_packet = FALSE;
> > > >
> > > >     call SamplerControl.init();
> > > >
> > > >     call CommControl.init();
> > > >
> > > >     return SUCCESS;
> > > >
> > > > }
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Avvio i componenti. Avvio il clock. Setup del campionamento
> > > >
> > > > *
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > > command result_t StdControl.start() {
> > > >
> > > >     call SamplerControl.start();
> > > >
> > > >     call CommControl.start();
> > > >
> > > >     call Timer.start(TIMER_REPEAT, INTERVAL_TIMER);
> > > >
> > > >     return SUCCESS;
> > > >
> > > > }
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Blocco i componenti.
> > > >
> > > > *
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > > command result_t StdControl.stop() {
> > > >
> > > >     call SamplerControl.stop();
> > > >
> > > >     return SUCCESS;
> > > >
> > > > }
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Trasmissione del paccheto via radio
> > > >
> > > > *
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > >
> > > > task void send_radio_msg()
> > > >
> > > >     {
> > > >
> > > >         power = (uint8_t) call Radio.GetRFPower();
> > > >
> > > >         radio_msg_ptr->data[POWER] = power;
> > > >
> > > >         freq = (uint16_t) call Radio.GetFrequency();
> > > >
> > > >         radio_msg_ptr->data[FREQ] = freq;
> > > >
> > > >         radio_msg_ptr->data[FREQ+1] = (freq >> 8);
> > > >
> > > >         //radio_msg_ptr->data[RSSI] = radio_send_buffer.strength;
> > > >
> > > >         radio_msg_ptr->data[SENSOR_ID] = SENSOR_BOARD_ID;
> > > >
> > > >         radio_msg_ptr->data[SENSOR_ID+1] = (SENSOR_BOARD_ID >> 8);
> > > >
> > > >         call Send.send(radio_msg_ptr,Len);
> > > >
> > > >     }
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Inserimento dati in pacchetto
> > > >
> > > > *
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > > task void insert_result() {
> > > >
> > > >     uint16_t ibuff;
> > > >
> > > >     ibuff = 0;
> > > >
> > > >     for (ibuff = 0; ibuff < 15; ibuff += 1) {
> > > >
> > > >         radio_msg_ptr->data[DATA_START+ibuff] = 79; //fr[ibuff];
> > > >
> > > >     }
> > > >
> > > >     post send_radio_msg();
> > > >
> > > > }
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Elaborazione dati tramite FFT
> > > >
> > > > *
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > >
> > > > task void fix_fft() {
> > > >
> > > >     m = 7;                                         //ATTENZIONE!!
> > > > Impostare bene il parametro
> > > >
> > > >     n = 1 << m;
> > > >
> > > >     mr = 0;
> > > >
> > > >     nn = n - 1;
> > > >
> > > >     tr = 0;
> > > >
> > > >     ti = 0;
> > > >
> > > >     shift = 1;
> > > >
> > > >     istep = 0;
> > > >
> > > >     call Leds.yellowOn();
> > > >
> > > >
> > > >
> > > >     //Decimazione nel tempo e riordino dei dati
> > > >
> > > >     for (m = 1; m<=nn; ++m) {
> > > >
> > > >         l = n;
> > > >
> > > >         do {
> > > >
> > > >             l >>= 1;
> > > >
> > > >             } while (mr+l > nn);
> > > >
> > > >             mr = (mr & (l-1)) + 1;
> > > >
> > > >             if (mr <= m) {
> > > >
> > > >             tr = fr[m];
> > > >
> > > >             fr[m] = fr[mr];
> > > >
> > > >             fr[mr] = tr;
> > > >
> > > >             ti = fi[m];
> > > >
> > > >             fi[m] = fi[mr];
> > > >
> > > >             fi[mr] = ti;}
> > > >
> > > >             }
> > > >
> > > >         l = 1;
> > > >
> > > >         k = LOG2NSIGNAL;
> > > >
> > > >         while (l < n) {
> > > >
> > > >             shift = 1;
> > > >
> > > >             istep = l << 1;
> > > >
> > > >             for (m = 0; m < l; ++m) {
> > > >
> > > >                 j = m << k;
> > > >
> > > >                 if (j >= NSIGNAL/2) {
> > > >
> > > >                 wr = -sinewave[j-NSIGNAL/2+NSIGNAL/4];
> > > >
> > > >                 wi = sinewave[j-NSIGNAL/2];
> > > >
> > > >                 } else {
> > > >
> > > >                 wr = sinewave[j+NSIGNAL/2];
> > > >
> > > >                 wi = -sinewave[j];
> > > >
> > > >                 }
> > > >
> > > >                 if (shift) {
> > > >
> > > >                     wr >>= 1;
> > > >
> > > >                     wi >>= 1;
> > > >
> > > >                 }
> > > >
> > > >                 for (i = m; i < n; i += istep) {
> > > >
> > > >                         j = i + l;
> > > >
> > > >                         tr = ((wr)*(fr[j]))-((wi)*(fi[j]));
> > > >
> > > >                         ti = ((wr)*(fr[j]))+((wi)*(fi[j]));
> > > >
> > > >                         qr = fr[i];
> > > >
> > > >                         qi = fi[i];
> > > >
> > > >                         if (shift) {
> > > >
> > > >                             qr >>= 1;
> > > >
> > > >                             qi >>= 1;
> > > >
> > > >                         }
> > > >
> > > >                         fr[j] = qr - tr;
> > > >
> > > >                         fi[j] = qi - ti;
> > > >
> > > >                         fr[i] = qr + tr;
> > > >
> > > >                         fi[i] = qi + ti;
> > > >
> > > >                }
> > > >
> > > >         }
> > > >
> > > >         --k;
> > > >
> > > >         l = istep;
> > > >
> > > >         }
> > > >
> > > >         for (m = 0; m < NSIGNAL-1; m += 1) {
> > > > //conversione in forma polare
> > > >
> > > >                 fr[m] = fr[m] >> 12;
> > > >
> > > >                 fi[m] = fi[m] >> 12;
> > > >
> > > >                 fr[m] = fr[m]*fr[m];
> > > >
> > > >                 fi[m] = fi[m]*fi[m];
> > > >
> > > >                 fr[m] = sqrt(fr[m]+fi[m]);
> > > >
> > > >                 dbg(DBG_USR1, "Ale: X(k=%d)=%d\n", m, fr[m]);
> > > >
> > > >         }
> > > >
> > > >         call Leds.yellowOff();
> > > >
> > > >         post insert_result();
> > > >
> > > > }
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Messaggio trasmesso via radio.
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > > event result_t Send.sendDone(TOS_MsgPtr pMsg, result_t success) {
> > > >
> > > >         radio_msg_ptr = pMsg;
> > > >
> > > >         call Leds.redToggle();
> > > >
> > > >         atomic {
> > > >
> > > >             sending_packet = FALSE;
> > > >
> > > >         }
> > > >
> > > >         return SUCCESS;
> > > >
> > > > }
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Timer Fired -
> > > >
> > > > *
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > > event result_t Timer.fired() {
> > > >
> > > >     call Leds.greenToggle();
> > > >
> > > >     atomic {
> > > >
> > > >         working = TRUE;
> > > >
> > > >         sending_packet = TRUE;
> > > >
> > > >     }
> > > >
> > > >     record[3] = call
> > > > Sample.getSample(7,ANALOG,ANALOG_SAMPLING_TIME,AVERAGE_FOUR);
> > > >
> > > >     return SUCCESS;}
> > > >
> > > >
> > > >
> > > >
> >
>
/***************************************************************************
> > *
> > > >
> > > > * Gestisco l'evento dataReady singolarmente
> > > >
> > > > * per tutti i tipi di dati generati dal MDA300
> > > >
> > > >
> >
>
****************************************************************************
> > /
> > > >
> > > > event result_t Sample.dataReady(uint8_t channel,uint8_t
> > > > channelType,uint16_t dato) {
> > > >
> > > >     switch (channelType) {
> > > >
> > > >         case ANALOG:
> > > >
> > > >         switch (channel) {
> > > >
> > > >             case 7:
> > > >
> > > >             if (working) {
> > > >
> > > >                     fr[z]=(int16_t) 1000*((dato/2048) - 1);
> > > > //normalizzo il valore del seganel e
> > > >
> > > >             call Leds.yellowToggle();
> > > > //moltiplico per mille per operare con interi
> > > >
> > > >             atomic {z += 1;
> > > >
> > > >                         nsam -= 1;
> > > >
> > > >             }
> > > >
> > > >             break;
> > > >
> > > >         }
> > > >
> > > >     }
> > > >
> > > >     default:
> > > >
> > > >     break;
> > > >
> > > > }
> > > >
> > > > atomic {
> > > >
> > > >             if (nsam == 0 && sending_packet) {
> > > >
> > > >             z = 0;
> > > >
> > > >             nsam = NSIGNAL-1;
> > > >
> > > >             working = FALSE;
> > > >
> > > >             post fix_fft();
> > > >
> > > >             }
> > > >
> > > > }
> > > >
> > > > return SUCCESS;
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > ------------------------------------------------------------------------
> > > >
> > > > _______________________________________________
> > > > Tinyos-help mailing list
> > > > [email protected]
> > > >
> >
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
> > >
> >
>

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to