Versão estável sem DMA e FFT. 128 amostras.

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed

Committer:
rebonatto
Date:
Tue Jan 05 11:47:35 2016 +0000
Revision:
0:fac116e94d44
Vers?o est?vel sem DMA e FFT. 128 amostras.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rebonatto 0:fac116e94d44 1 /*
rebonatto 0:fac116e94d44 2 * Capture.h
rebonatto 0:fac116e94d44 3 *
rebonatto 0:fac116e94d44 4 * Created on:
rebonatto 0:fac116e94d44 5 * Author:
rebonatto 0:fac116e94d44 6 */
rebonatto 0:fac116e94d44 7 #include "Capture.h"
rebonatto 0:fac116e94d44 8
rebonatto 0:fac116e94d44 9 //Semaphore Capture::m_CaptureSemaphore(1); //used to alert the capture thread about a ready capture
rebonatto 0:fac116e94d44 10 //int Capture::m_BufferIndex;
rebonatto 0:fac116e94d44 11
rebonatto 0:fac116e94d44 12 //__attribute((section("AHBSRAM1"),aligned)) dmaLinkedListNode Capture::m_Nodes[2];// __attribute__((section("AHBSRAM0"))); //this list holds the buffer configuration for the DMA peripheral
rebonatto 0:fac116e94d44 13 __attribute((section("AHBSRAM1"),aligned)) short int Capture::m_AdcBuffers[NUMBER_OF_CHANNELS][NUMBER_OF_SAMPLES];// __attribute__((section("AHBSRAM0")));
rebonatto 0:fac116e94d44 14 Serial rfid_serial(p28,p27);
rebonatto 0:fac116e94d44 15
rebonatto 0:fac116e94d44 16 AnalogIn AdcChannel0(CHANNEL0);
rebonatto 0:fac116e94d44 17 AnalogIn AdcChannel1(CHANNEL1);
rebonatto 0:fac116e94d44 18 AnalogIn AdcChannel2(CHANNEL2);
rebonatto 0:fac116e94d44 19 AnalogIn AdcChannel3(CHANNEL3);
rebonatto 0:fac116e94d44 20 AnalogIn AdcChannel4(CHANNEL4);
rebonatto 0:fac116e94d44 21 AnalogIn AdcChannel5(CHANNEL5);
rebonatto 0:fac116e94d44 22
rebonatto 0:fac116e94d44 23 //ADC_CONVERT(m_AdcBuffers[m_BufferIndex][nsamples][nchannel]);
rebonatto 0:fac116e94d44 24
rebonatto 0:fac116e94d44 25 short int Capture::GetValue(int nsamples, int nchannel)
rebonatto 0:fac116e94d44 26 {
rebonatto 0:fac116e94d44 27 return m_AdcBuffers[nchannel][nsamples];
rebonatto 0:fac116e94d44 28 }
rebonatto 0:fac116e94d44 29
rebonatto 0:fac116e94d44 30 void Capture::PutValue(int nsamples, int nchannel, short int value)
rebonatto 0:fac116e94d44 31 {
rebonatto 0:fac116e94d44 32 m_AdcBuffers[nchannel][nsamples] = value;
rebonatto 0:fac116e94d44 33 }
rebonatto 0:fac116e94d44 34
rebonatto 0:fac116e94d44 35 void Capture::CopyBuffer(int channel, short int *dest)
rebonatto 0:fac116e94d44 36 {
rebonatto 0:fac116e94d44 37 memcpy(dest, &m_AdcBuffers[channel][0], sizeof(short int) * NUMBER_OF_SAMPLES);
rebonatto 0:fac116e94d44 38 /*
rebonatto 0:fac116e94d44 39 for(int i=0;i<NUMBER_OF_SAMPLES;i++)
rebonatto 0:fac116e94d44 40 {
rebonatto 0:fac116e94d44 41 dest[i] = GetValue(i,channel);
rebonatto 0:fac116e94d44 42 }
rebonatto 0:fac116e94d44 43 */
rebonatto 0:fac116e94d44 44 }
rebonatto 0:fac116e94d44 45
rebonatto 0:fac116e94d44 46
rebonatto 0:fac116e94d44 47 void Capture::AcquireValues(){
rebonatto 0:fac116e94d44 48 int i;
rebonatto 0:fac116e94d44 49
rebonatto 0:fac116e94d44 50 for(i=0; i < NUMBER_OF_SAMPLES; i++){
rebonatto 0:fac116e94d44 51 m_AdcBuffers[0][i] = ADC_CONVERT(AdcChannel0.read_u16());
rebonatto 0:fac116e94d44 52 //wait_us(10);
rebonatto 0:fac116e94d44 53 m_AdcBuffers[1][i] = ADC_CONVERT(AdcChannel1.read_u16());
rebonatto 0:fac116e94d44 54 //wait_us(10);
rebonatto 0:fac116e94d44 55 m_AdcBuffers[2][i] = ADC_CONVERT(AdcChannel2.read_u16());
rebonatto 0:fac116e94d44 56 //wait_us(10);
rebonatto 0:fac116e94d44 57 m_AdcBuffers[3][i] = ADC_CONVERT(AdcChannel3.read_u16());
rebonatto 0:fac116e94d44 58 //wait_us(10);
rebonatto 0:fac116e94d44 59 m_AdcBuffers[4][i] = ADC_CONVERT(AdcChannel4.read_u16());
rebonatto 0:fac116e94d44 60 //wait_us(10);
rebonatto 0:fac116e94d44 61 m_AdcBuffers[5][i] = ADC_CONVERT(AdcChannel5.read_u16());
rebonatto 0:fac116e94d44 62 wait_us(13);
rebonatto 0:fac116e94d44 63 }
rebonatto 0:fac116e94d44 64 }
rebonatto 0:fac116e94d44 65
rebonatto 0:fac116e94d44 66 //void Capture::Initialize(){ //AnalogIn adcChannel0; }
rebonatto 0:fac116e94d44 67
rebonatto 0:fac116e94d44 68
rebonatto 0:fac116e94d44 69 void Capture::ReadRFID(int channel,char *rfid)
rebonatto 0:fac116e94d44 70 {
rebonatto 0:fac116e94d44 71
rebonatto 0:fac116e94d44 72 char cmd[4];
rebonatto 0:fac116e94d44 73 cmd[0] = 'S';
rebonatto 0:fac116e94d44 74 cmd[1] = '0'+channel;
rebonatto 0:fac116e94d44 75 cmd[2] = '\n';
rebonatto 0:fac116e94d44 76 cmd[3] = '\0';
rebonatto 0:fac116e94d44 77
rebonatto 0:fac116e94d44 78 //send
rebonatto 0:fac116e94d44 79 rfid_serial.puts(cmd);
rebonatto 0:fac116e94d44 80
rebonatto 0:fac116e94d44 81 //receive
rebonatto 0:fac116e94d44 82 char ch=0;
rebonatto 0:fac116e94d44 83 char ans[10];
rebonatto 0:fac116e94d44 84 int cnt=0;
rebonatto 0:fac116e94d44 85 int tmout=1000;
rebonatto 0:fac116e94d44 86 while(ch != '\n' && tmout-- && cnt<9)
rebonatto 0:fac116e94d44 87 {
rebonatto 0:fac116e94d44 88 if(rfid_serial.readable())
rebonatto 0:fac116e94d44 89 {
rebonatto 0:fac116e94d44 90 ch = rfid_serial.getc();
rebonatto 0:fac116e94d44 91 if(!((ch>='0' && ch<='9') || (ch >= 'A' && ch <= 'F')))ch='0';
rebonatto 0:fac116e94d44 92 ans[cnt++] = ch;
rebonatto 0:fac116e94d44 93 }
rebonatto 0:fac116e94d44 94 else
rebonatto 0:fac116e94d44 95 wait_ms(1);
rebonatto 0:fac116e94d44 96
rebonatto 0:fac116e94d44 97 }
rebonatto 0:fac116e94d44 98 ans[cnt-1] = '\0';
rebonatto 0:fac116e94d44 99 for(int i=0;i<9;i++)
rebonatto 0:fac116e94d44 100 rfid[i] = ans[i];
rebonatto 0:fac116e94d44 101
rebonatto 0:fac116e94d44 102 }