It is Posible to add 1 Pot in Audio Codec Shield?

It is Posible to add 1 Pot in Audio Codec Shield?

Postby Darwin1234 » Sun Mar 25, 2012 8:41 pm

It is Posible to add 1 Pot in Audio Codec Shield?=)
Darwin1234
 
Posts: 2
Joined: Sun Mar 25, 2012 8:26 pm

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby guest » Mon Mar 26, 2012 6:18 pm

yes
there are actually 2 free adc inputs
but the .h file will need to be modified to make this happen
if you are familiar with c i can walk you thorugh it
otherwise i can put it on my todo list
but that will take a bit longer
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby loss1234 » Sun Apr 01, 2012 8:17 am

This would be very useful!
loss1234
 
Posts: 10
Joined: Sun Apr 01, 2012 1:39 am

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby loss1234 » Thu Apr 05, 2012 6:51 am

can you walk us through editing the .h file to add the other 2 ADC Inputs?

I see the section of the file where the ADCS are called...i just need to know what to add.

thanks!
loss1234
 
Posts: 10
Joined: Sun Apr 01, 2012 1:39 am

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby guest » Thu Apr 05, 2012 2:08 pm

all of these bits need to replace
sections that already exist in the .h file

first we should change the adc definitions
this will allow us to easily turn on more adcs in the sketch

Code: Select all
#ifndef ADCS
  #define ADCS 2
#elif (ADCS >=0)&&(ADCS <= 4)
#else
  #error ADCS value not defined
#endif


this now allows us to say ADCS 4
to get 4 pots

then we need to create variables for those ADCs

Code: Select all
// setup variables for ADC
#if ADCS == 0
  // do nothing
#elif ADCS == 1
  unsigned char _i = 64;
  unsigned int _mod0temp = 0x0000;
#elif ADCS == 2
  unsigned char _i = 130;
  unsigned int _mod0temp = 0x0000;
  unsigned int _mod1temp = 0x0000;
#elif ADCS == 3
  unsigned char _i = 196;
  unsigned int _mod0temp = 0x0000;
  unsigned int _mod1temp = 0x0000;
  unsigned int _mod2temp = 0x0000;
#elif ADCS == 4
  unsigned char _i = 255; // this needs to be fixed - the value needs to be 260, but thats larger than a char
  unsigned int _mod0temp = 0x0000;
  unsigned int _mod1temp = 0x0000;
  unsigned int _mod2temp = 0x0000;
  unsigned int _mod3temp = 0x0000;
#endif


the _i value sets the oversampling
i have some code that changes the oversampling time
and this will eventually reset all that

now setup the adc hardware peripheral

Code: Select all
  // setup ADCs
  #if ADCS == 0
    DIDR0 = (1 << ADC1D)|(1 << ADC0D); // turn off digital inputs for ADC0 and ADC1
  #elif (ADCS == 1) || (ADCS == 2)
    ADMUX = 0x40; // start with ADC0 - internal VCC for Vref
    ADCSRA = 0xe7; // ADC enable, autotrigger, ck/128
    ADCSRB = 0x00; // free running mode
    DIDR0 = (1 << ADC1D)|(1 << ADC0D); // turn off digital inputs for ADC0 and ADC1
  #elif (ADCS == 3)
    ADMUX = 0x40; // start with ADC0 - internal VCC for Vref
    ADCSRA = 0xe7; // ADC enable, autotrigger, ck/128
    ADCSRB = 0x00; // free running mode
    DIDR0 = (1<<ADC2D)|(1 << ADC1D)|(1 << ADC0D); // turn off digital inputs for ADC0:2
  #elif (ADCS == 4)
    ADMUX = 0x40; // start with ADC0 - internal VCC for Vref
    ADCSRA = 0xe7; // ADC enable, autotrigger, ck/128
    ADCSRB = 0x00; // free running mode
    DIDR0 = (1<<ADC3D)|(1<<ADC2D)|(1 << ADC1D)|(1 << ADC0D); // turn off digital inputs for ADC0:3
  #endif


i will put the final bit in another post
just to keep this one from getting too long
Last edited by guest on Thu Apr 05, 2012 2:37 pm, edited 1 time in total.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby guest » Thu Apr 05, 2012 2:35 pm

and this is where it gets a bit hairy
we need to add 2 more #elif in the adc sample routine
one for each new option
they should be something like:

Code: Select all
#elif ADCS == 3
  static inline void AudioCodec_ADC(unsigned int* _mod0value, unsigned int* _mod1value, unsigned int* _mod2value) {
    if (ADCSRA & (1 << ADIF)) { // check if sample ready
      --_i; // check which sample we are on
      if (_i == 194) { // do nothing, first sample after mux change
      }
      else if (_i >= 130) { // sample ADC0
        _mod0temp += ADCL; // fetch ADCL first to freeze sample
        _mod0temp += (ADCH << 8); // add to temp register
        if (_i == 130) { // check if enough samples have been averaged
          // add in hysteresis to remove jitter
          if (((_mod0temp - *_mod0value) < HYST) || ((*_mod0value - _mod0temp) < HYST)) {
          }
          else {
            *_mod0value = _mod0temp; // move temp value
       }
          _mod0temp = 0x0000; // reset temp value
          ADMUX = 0x41; // switch to ADC1
        }
      }
      else if (_i == 129) { // do nothing, first sample after adc change
      }
      else if (_i >= 65) { // sample ADC1
        _mod1temp += ADCL; // fetch ADCL first to freeze sample
        _mod1temp += (ADCH << 8); // add to temp register
        if (_i == 65) { // check if enough samples have been averaged
          // add in hysteresis to remove jitter
          if (((_mod1temp - *_mod1value) < HYST) || ((*_mod1value - _mod1temp) < HYST)) {
          }
          else {
            *_mod1value = _mod1temp; // move temp value
       }
          _mod1temp = 0x0000; // reset temp value
          ADMUX = 0x42; // switch to ADC2
        }
      else if (_i <= 63) { // sample ADC2, 64 ignored to skip first sample after change
        _mod1temp += ADCL; // fetch ADCL first to freeze sample
        _mod1temp += (ADCH << 8); // add to temp register
        if (_i == 0) { // check if enough samples have been averaged
          // add in hysteresis to remove jitter
          if (((_mod2temp - *_mod2value) < HYST) || ((*_mod2value - _mod2temp) < HYST)) {
          }
          else {
            *_mod2value = _mod2temp; // move temp value
       }
          _mod2temp = 0x0000; // reset temp value
          ADMUX = 0x40; // switch to ADC0
          _i = 195; // reset counter
        }
      }
      ADCSRA = 0xf7; // reset the interrupt flag
    }
  }


i havent tested this
but it should get you pretty close

looking at it now
i realize i should just rewrite the whole adc sample code
the variable oversampling rate will get really confused
with these larger number of pots
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby guest » Thu Apr 05, 2012 2:39 pm

its possible to write more compact code than this
but time is of the essence
and this compiles down to the fastest stuff
without resorting to pure inline assembly

just in case you were wondering why its so ugly
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby guest » Thu Apr 19, 2012 9:15 am

i finished off the extra mod pot header file
it is located here
http://wiki.openmusiclabs.com/wiki/AudioCodecShield
its in the library zip file

i only have it for the old version of arduino at the moment
i dont use arduino1.0 because they changed so much stuff
that i have to rewrite all of my old code

if you need arduino1.0 libraries let me know

the new header file also has more sample rates
so the full list is now
88ksps
44ksps
29ksps
14ksps
8ksps
7ksps
4ksps
2ksps
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby guest » Fri Apr 20, 2012 4:54 pm

i have put up the arduino1.0 library as well
same place as the other
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: It is Posible to add 1 Pot in Audio Codec Shield?

Postby mxmx » Sat Jun 23, 2012 4:49 am

hi. am i guessing right that this limit only applies to arduino? ie, considering the maple has 16 analog ins?
thanks.
mxmx
 
Posts: 1
Joined: Sat Jun 23, 2012 4:44 am

Next

Return to Audio Codec Shield

Who is online

Users browsing this forum: Google [Bot] and 1 guest


cron