Hi Peppe, Double buffering is done for a reason!
But regardless, assuming you do have a good reason to not double buffer, you are mixing up sbuf1 and sbuf0 in you memcpy. For your first sample period you'll have junk data copied into ecgData, and from then on ecgData will be lagging the actual sensed data by one sample period. If you don't want do use the double buffering you'd be much better off using the DMA to copy the adc readings directly into the ecgData array. Additionally, p_packet is just a pointer to a position in tx_packet, which is used later. If you don't understand pointers in C you are going to have trouble following this code. Mike On Wed, Oct 5, 2011 at 11:55 AM, Peppe Scabellone <[email protected]>wrote: > Hi , I was looking Steve Ayer's AccelECGC.nc file. > I need to get datas from ECG and as I can see in that file the real datas > are stored in p_packet array as you can see below: > > /* copy all the data samples into the outgoing packet */ > *p_packet++ = *p_ADCsamples++; //tx_packet[8] > *p_packet++ = *p_ADCsamples++; //tx_packet[10] > *p_packet++ = *p_ADCsamples++; //tx_packet[12] > *p_packet++ = *p_ADCsamples++; //tx_packet[14] > *p_packet = *p_ADCsamples; //tx_packet[16] > > but this p_packet is never used in other part of the code. > > I need the two channels of ECG stored in one array > uint16_t ecgData[2] > > so if I call > > async event void DMA0.transferDone(error_t success) { > if(current_buffer == 0){ > call DMA0.repeatTransfer((void*)ADC12MEM0_, (void*)&sbuf1, > NBR_ADC_CHANS); > memcpy(ecgData, &sbuf1, sizeof(*sbuf1)*NBR_ADC_CHANS); > current_buffer = 1; > } > else { > call DMA0.repeatTransfer((void*)ADC12MEM0_, (void*)&sbuf0, > NBR_ADC_CHANS); > memcpy(ecgData, &sbuf0, sizeof(*sbuf1)*NBR_ADC_CHANS); > current_buffer = 0; > } > > post preparePacket(); > > } > > and the method > > void preparePacket() { > uint16_t *p_packet, *p_ADCsamples, crc; > > p_packet = (uint16_t *)&tx_packet[8]; > > if(current_buffer == 1) { > p_ADCsamples = &sbuf0[0]; > > } > else { > p_ADCsamples = &sbuf1[0]; > } > > /* copy all the data samples into the outgoing packet */ > *p_packet++ = *p_ADCsamples++; //tx_packet[8] > *p_packet++ = *p_ADCsamples++; //tx_packet[10] > *p_packet++ = *p_ADCsamples++; //tx_packet[12] > *p_packet++ = *p_ADCsamples++; //tx_packet[14] > *p_packet = *p_ADCsamples; //tx_packet[16] > > } > > The Question is using these two methods I'll have the datas in ecgData > array? or I have to intercept p_packet? > > Thank you. > > _______________________________________________ > Shimmer-users mailing list > [email protected] > https://lists.eecs.harvard.edu/mailman/listinfo/shimmer-users > >
_______________________________________________ Shimmer-users mailing list [email protected] https://lists.eecs.harvard.edu/mailman/listinfo/shimmer-users
