Audio codec shield with Intel Edison

Audio codec shield with Intel Edison

Postby youthreewire » Thu Aug 06, 2015 10:24 am

Hello,

Greetings!

After developing a library successfully for the Arduino Due I am planning to extend the same to Intel Edison. So what functionality do we need? Edison does I2C, it can mimic timers and interrupts though actually it does not have them. I think I might have to see how to use an external clock signal to generate interrupts on the edison.

Apart from the external clock interrupt I dont see what problem there could be.Please pour in your suggestions.I will also start a thread in the edison forums.

Thanks
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Intel Edison

Postby youthreewire » Fri Aug 07, 2015 10:35 pm

So what is the relation between the CLKOUT signal at 11 mhz from the the codec and the ISR at 44 khz. I mean how should the CLKOUT signal and SS pin wave together look like in the oscilloscope?
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Intel Edison

Postby guest » Sat Aug 08, 2015 11:32 am

i dont know anything about the edison, but i have a friend i can ask.

as for the clk_out, that should really be at 5.5MHz. its ok if its 11MHz, but the CK/2 bit should be set in the setup registers. the SS output and the clock signal should be synchronized with each other. ie, if you look at them on the scope, they should not move with respect to each other.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Intel Edison

Postby youthreewire » Mon Aug 10, 2015 5:33 am

So when I am using SCL and SDA in I2C what among them is output or input. I think SCL might be output and SDA an input pin. Because in doing I2C communication I need to set the output and input pins. I will first try I2C with BYPASS enable and see if first I2C is working. Then I will code for ISR and timers and then SPI.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Intel Edison

Postby youthreewire » Mon Aug 10, 2015 5:45 am

Just tested I2C, it is working and configuring the codec as needed.I will move onto interrupts,SS and SPI.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Intel Edison

Postby youthreewire » Mon Aug 10, 2015 11:20 pm

The question you might want to ask your friend is how do you track at external interrupt signal at 11Mhz/256 (for 44 Khz) and this timing should drive the ISR.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Intel Edison

Postby youthreewire » Tue Aug 11, 2015 4:10 am

You told me in the past that the first pulse of SS should be aligned with the falling edge of SPI Clock. I understood that but now I want to know how should the SS pin wave be aligned to the 11Mhz or 5.5Mhz CLKOUT signal from the codec? Since I am not able to track the CLKOUT in edison I will try to read the moment when it is high and start the timer with respect to the rising edge of the CLKOUT signal. If align them this way at the beginning will it remain aligned for the rest of the time or should we see the RISING edge every time?Please let me know.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Intel Edison

Postby youthreewire » Tue Aug 11, 2015 7:03 am

My code for Edison. I2C works and configures the codec right but SPI is still work in progress. Will debug this tomorrow using the scope
Code: Select all
#include <TimerOne.h>
#include "SPI.h"
#include <Wire.h>
#define LINVOL 23
#define RINVOL 23
#define LHPVOL 100
#define RHPVOL 100
#define ADCHPD 0
#define SIDEATT 0
#define SIDETONE 0
#define DACSEL 1
#define BYPASS 0
#define INSEL 0
#define MUTEMIC 1
#define MICBOOST 0
#define SAMPLE_RATE 8
int myi=0;
bool ledon;
int temp_spi[4];
volatile unsigned int temp =0;

void AudioCodec_init() {
 

  // setup i2c pins and configure codec
  // the new Wire library has trouble with 0x00, so (uint8_t) is added
  // To change the Wire interface speed, go to:
  // <path_from_arduino>\hardware\arduino\sam\libraries\Wire\Wire.h
  // and change the parameters TWI_CLOCK, RECV_TIMEOUT and XMIT_TIMEOUT
  // to the desire frequency.
  int temp_wire1;
  int temp_wire2;

  Wire.begin();
  Wire.beginTransmission(0x1a);
  Wire.write(0x0c); // power reduction register
  Wire.write((uint8_t)0x00); // turn everything on
  temp_wire1 = Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x0e); // digital data format
  Wire.write(0x03); // 16b SPI mode
  temp_wire2 = Wire.endTransmission();

  Serial.println(temp_wire1);
  Serial.println(temp_wire2);

  Wire.beginTransmission(0x1a);
  Wire.write((uint8_t)0x00); // left in setup register
  Wire.write((uint8_t)LINVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x02); // right in setup register
  Wire.write((uint8_t)RINVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x04); // left headphone out register
  Wire.write((uint8_t)LHPVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x06); // right headphone out register
  Wire.write((uint8_t)RHPVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x0a); // digital audio path configuration
  Wire.write((uint8_t)ADCHPD);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x08); // analog audio pathway configuration
  Wire.write((uint8_t)((SIDEATT << 6) | (SIDETONE << 5) | (DACSEL << 4) | (BYPASS << 3) | (INSEL << 2) | (MUTEMIC << 1) | (MICBOOST << 0)));
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x10); // clock configuration
#if SAMPLE_RATE == 88
  Wire.write(0xbc);
#elif SAMPLE_RATE == 44
  Wire.write(0xa0);
#elif SAMPLE_RATE == 22
  Wire.write(0xe0);
#elif SAMPLE_RATE == 8
  Wire.write(0xac);
#elif SAMPLE_RATE == 2
  Wire.write(0xce);
#endif
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x12); // codec enable
  Wire.write(0x01);
  Wire.endTransmission();

}

void setup()
{
  // Initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards
  //system("echo 40 > /sys/class/gpio/export");
   system("echo 128 > /sys/class/gpio/export"); //pin 2
  system("echo 42 > /sys/class/gpio/export");//pin  13
  system("echo in > sys/class/gpio/gpio128/direction");

   SPI.begin();  // Begin SPI hardware
   SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  SPI.setDataMode(SPI_MODE0);
 
  pinMode(2,INPUT);
  pinMode(12,OUTPUT);
  Serial.begin(9600);   
  //Serial.begin(9600);
  Timer1.initialize(125); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
  Timer1.attachInterrupt(timerIsr,CHANGE ); // attach the service routine here
  //attachInterrupt(2, pinChange, CHANGE);
}
 
void loop()
{
  if(fastGpioPciDigitalRead(2)==HIGH)
  {
 
   Timer1.attachInterrupt(timerIsr,CHANGE );

  }
  /*else
  //(fastGpioPciDigitalRead(2)==HIGH)
  {
  fastGpioPciDigitalWrite(13,LOW);
__asm__("nop");
  }*/
   
   Serial.print(temp_spi[0]);
   Serial.print(" ");
   Serial.print(temp_spi[1]);
   Serial.print(" ");
   Serial.print(temp_spi[2]);
   Serial.print(" ");
   Serial.print(temp_spi[3]);
   Serial.println(myi);}

void timerIsr()
{
    // Toggle LED
    fastGpioPciDigitalWrite(12,HIGH);
   __asm__("nop");
   myi++;

   temp = random(65535);
        temp_spi[0] = SPI.transfer(highByte(temp));
        fastGpioPciDigitalWrite(12,LOW);
        temp_spi[1] = SPI.transfer(lowByte(temp));
        temp_spi[2] = SPI.transfer(highByte(temp));
        temp_spi[3] = SPI.transfer(lowByte(temp));
       
   
}
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Intel Edison

Postby guest » Tue Aug 11, 2015 12:09 pm

i asked my friend about the edison, and he said it doesnt have any hardware timers that are usable. im not sure how interrupts even work on it. you could put an external counter chip on, but it ultimately may not work. the codecshield is set to work in slave mode, which is not very conducive to most larger platforms. with the edison you can just put a usb sound card on it.

with the master clock and SS signals, i dont think it matters whether its aligned to rising or falling edge, just as long as its consistent.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Intel Edison

Postby youthreewire » Tue Aug 11, 2015 9:31 pm

Software emulation of timers and interrupts is there on edison.I am able to get an 8khz interrupt on the edison.Here is the scope shot:
IMG_20150811_144937.jpg
IMG_20150811_144937.jpg (115.75 KiB) Viewed 17311 times
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Next

Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron