Buongiorno a tutti!
Ho dei problemi con l'acquisizione audio, utilizzo la scheda MKR WAN 1300. Come posso aumentare la frequenza di campionamento utilizzando i registri ADC? E come posso utilizzare il convertitore analogico digitale per visualizzare i dati acquisiti?
Questo è il codice utilizzato
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);
}
Grazie anticipatamente