Go Down

Topic: MKR 1300 - Audio acquisition (Read 188 times) previous topic - next topic

Enrico93

Jun 05, 2018, 10:41 am Last Edit: Jun 05, 2018, 11:04 am by Enrico93
Hello everyone,

I have a problem with audio acquisition. I'm using MKR 1300. How can I increase the sampling frequency using ADC registers? And how can I use the digital to analog converter to visualize the acquired data?

Following this is the code I have used

Code: [Select]
void AdcBooster()
{
  SYSCTRL->OSC8M.bit.PRESC = 0;    // Set OSC8M prescaler to 1
  ADC->INPUTCTRL.bit.MUXPOS=0x01;  //A1 as input
  ADC->INPUTCTRL.bit.MUXPOS=0x1C;   //DAC as output
  ADC->CTRLA.bit.ENABLE = 0;                     // Disable ADC
  while ( ADC->STATUS.bit.SYNCBUSY == 1 );       // Wait for synchronization
  ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV64 |   // Divide Clock by 64.
                   ADC_CTRLB_RESSEL_12BIT;       // Result on 12 bits
  ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_1 |   // 1 sample
                     ADC_AVGCTRL_ADJRES(0x00ul); // Adjusting result by 0
  ADC->SAMPCTRL.reg = 0x00;                      // Sampling Time Length = 0
  ADC->CTRLA.bit.ENABLE = 1;                     // Enable ADC
  while ( ADC->STATUS.bit.SYNCBUSY == 1 );       // Wait for synchronization
}

uint32_t anaRead()
{
  ADC->INTFLAG.bit.RESRDY = 1;              // Data ready flag cleared
 
  ADC->SWTRIG.bit.START = 1;                // Start ADC conversion
  while ( ADC->INTFLAG.bit.RESRDY == 0 );   // Wait till conversion done
 
  uint32_t valueRead = ADC->RESULT.reg;     // read the result
 
  ADC->SWTRIG.reg = 0x01;                    //  and flush for good measure
 
  return valueRead;
}


void setup() {
  Serial.begin(250000);
 // pinMode(A1, INPUT);
  AdcBooster();
 
 
}
void loop() {
  uint32_t audio = anaRead();
  analogWrite(A0, audio);
}


Thanks!

Go Up