How can I get adc results and use in loop()

How can I get adc results and use in loop()

Postby sjp1111 » Tue Aug 20, 2013 10:33 pm

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.

Code: Select all
#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.
sjp1111
 
Posts: 3
Joined: Tue Aug 20, 2013 8:22 pm

Re: How can I get adc results and use in loop()

Postby guest » Tue Aug 20, 2013 11:48 pm

if you are using the codec as your ADC, you do not need the onboard ADC. so things are easier. also, if you are using maple, be sure to download and use the maple library. it is different. also, the usb confilcts with the codecshield, so you will have to hit "reset" when you upload your code after the first time.

Code: Select all

// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 44 // 44.1Khz
#define ADCS 0 // no ADCs are being used

// include necessary libraries
#include <AudioCodec_Maple.h>

// create data variables for audio transfer
// note the use of "int16" rather than int -> on the maple,
// an int is 32bits
int16 left_in = 0x0000;
int16 left_out = 0x0000;
int16 right_in = 0x0000;
int16 right_out = 0x0000;
                   
                     
void setup() {
  SerialUSB.end(); // usb conflicts with the codec in this mode
  AudioCodec_init(); // setup codec registers
  // call this last if setting up other parts
}

void loop() {
  // put code here, use variables right_in and left_in
}


void AudioCodec_interrupt() {

  // &'s are necessary on data_in variables
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
 
}

guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: How can I get adc results and use in loop()

Postby sjp1111 » Wed Aug 21, 2013 12:05 am

I sincerely appreciate your comments.

Now i'm wating for arriving my maple board.

So i'll try if I get maple.

Thanky you again.
sjp1111
 
Posts: 3
Joined: Tue Aug 20, 2013 8:22 pm


Return to Audio Codec Shield

Who is online

Users browsing this forum: Bing [Bot] and 2 guests


cron