How can I get adc results and use in loop()
I'm korean newbie of maple and this audio codec shield.
First of all, I wanna upload my algorithm to the maple board. My project needs two mic inputs so I'm using audio codec shield.
I'm gonna put my algorithm in loop(). Actually I don't need analog outputs, just need Adc results and I need to use adc results(as 44.1kHz sampling rate) in my code.
Let's see my code.
I'm thinking that mod0_value, mod1_value are adc results and these values gonna be inputs of my algorithm.
But I'm wondering i'm right and If I use mod0_value, mod1_vlaue in the loop, these values are updated or not.
Please give me any comments or suggestions. It would be really helpful for me.
Actually what I want is getting adc results and using these results as the input of my algoritm in loop()
All the best.
First of all, I wanna upload my algorithm to the maple board. My project needs two mic inputs so I'm using audio codec shield.
I'm gonna put my algorithm in loop(). Actually I don't need analog outputs, just need Adc results and I need to use adc results(as 44.1kHz sampling rate) in my code.
Let's see my code.
#define SAMPLE_RATE 44 // 44.1kHz sample rate
#define ADCS 2 // use both ADCs
// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodec.h>
// create data variables for audio transfer
// even though the function is mono, the codec requires stereo data
int left_in = 0; // in from codec (LINE_IN)
int right_in = 0;
int left_out = 0; // out to codec (HP_OUT)
int right_out = 0;
// create variables for ADC results
// it only has positive values -> unsigned
unsigned int mod0_value = 0;
unsigned int mod1_value = 0;
void setup() {
// call this last if you are setting up other things
AudioCodec_init(); // setup codec and microcontroller registers
}
void loop() {
while (1); // reduces clock jitter
// I'm gonna put my algorithm in here
}
// timer1 interrupt routine - all data processed here
void AudioCodec_interrupt() {
// &'s are necessary on data_in variables
AudioCodec_data(&left_in, &right_in, left_out, right_out);
// &'s are necessary on data_in variables
AudioCodec_data(&left_in, &right_in, left_out, right_out);
// get ADC values
// & is required before adc variables
AudioCodec_ADC(&mod0_value, &mod1_value);
// you dont need to reti() with Maple
}I'm thinking that mod0_value, mod1_value are adc results and these values gonna be inputs of my algorithm.
But I'm wondering i'm right and If I use mod0_value, mod1_vlaue in the loop, these values are updated or not.
Please give me any comments or suggestions. It would be really helpful for me.
Actually what I want is getting adc results and using these results as the input of my algoritm in loop()
All the best.