[SOLVED]Audio codec shield with Arduino Due

Re: Audio codec shield with Arduino Due

Postby youthreewire » Mon Jun 22, 2015 7:56 am

Here is the output from another code:

other prograam with interrupts.jpg
other prograam with interrupts.jpg (205.79 KiB) Viewed 9565 times


Code: Select all
#define TC2_CHANNEL_FOR_TCLK8 2  /* presumed to correspond to XC2 */

enum Phase
   {
      TC2_INTERNAL,
      PIOD_EXTERNAL,
      TC2_EXTERNAL,
      DONE
   };
   
  /* enum Phase
   {
      TC2_EXTERNAL,
      TC2_EXTERNAL,
      TC2_EXTERNAL,
      DONE
   };*/

Phase phase;
int pioIRQsServiced;
int tc2IRQsServiced[3];
unsigned int status;
int upflag = 0;
bool ledon=0;
int oldmillis=0;

/****************************************************************/

void PIOD_Handler(void)
{
   /* clear interrupt */
   status = REG_PIOD_ISR;
   pioIRQsServiced++;
}


/****************************************************************/

void TC8_Handler()
{
   /* clear interrupt */
   status = TC_GetStatus(TC2, TC2_CHANNEL_FOR_TCLK8);
   if (status & TC_SR_CPCS)
   {
      if (phase == TC2_INTERNAL)
      {
         tc2IRQsServiced[0]++;
      }
      else
      {
         tc2IRQsServiced[1]++;
      }
   }
   if (status & TC_SR_ETRGS)
   {
      tc2IRQsServiced[2]++;
   }
}


/****************************************************************/

void SetupPIOD(void)
{
   int result;

   /* power on PIO ("Parallel Input/Output Controller") controller D */
   pmc_enable_periph_clk(ID_PIOD);
   /* enable interrupts for PIOD */
   NVIC_EnableIRQ(PIOD_IRQn);
   /* configure PD9 as general-purpose IO pin as opposed to the TCLK8 peripheral */
   result = PIO_Configure(PIOD, PIO_INPUT, PIO_PD9, PIO_IT_RISE_EDGE);
   printf("%d <- PIO_Configure\n", result);
   /* ensure we're interrupting on the rising edge of the external clock */
   REG_PIOD_AIMER = PIO_PD9;
   REG_PIOD_ESR = PIO_PD9;
   REG_PIOD_REHLSR = PIO_PD9;
   /* enable interrupts */
   REG_PIOD_IER = PIO_PD9;
}


/****************************************************************/

void TakeDownPIOD(void)
{
   TC_Stop(TC2, TC2_CHANNEL_FOR_TCLK8);
   TC_SetRC(TC2, TC2_CHANNEL_FOR_TCLK8, 0);
   REG_PIOD_IDR = PIO_PD9;
   NVIC_DisableIRQ(TC8_IRQn);
   pmc_disable_periph_clk(ID_PIOD);
}


/****************************************************************/

void SetupTC2(bool useInternalClock)
{
   int result;

   /* "The user must configure the Power Management Controller before any access to the input line information." per 34.4.2 */
   pmc_enable_periph_clk(ID_TC8);
   /* "Using the PIO Controller requires the NVIC to be programmed first." per 34.4.3 */
   NVIC_EnableIRQ(TC8_IRQn);
   result = PIO_Configure(PIOD, PIO_PERIPH_B, PIO_ABSR_P9, PIO_DEFAULT);
   printf("%d <- PIO_Configure\n", result);
   if (useInternalClock)
   {
      TC_Configure(TC2,
                TC2_CHANNEL_FOR_TCLK8,
                TC_CMR_TCCLKS_TIMER_CLOCK4 | TC_CMR_WAVSEL_UP_RC | TC_CMR_WAVE);
   }
   else
   {
      TC_Configure(TC2,
                TC2_CHANNEL_FOR_TCLK8,
                (TC_CMR_TCCLKS_XC2 |
                 TC_CMR_EEVTEDG_RISING |
                 TC_CMR_EEVT_XC2 |
                 TC_CMR_ENETRG |
                 TC_CMR_WAVSEL_UP_RC |
                 TC_CMR_WAVE));
   }
   /* load counter register */
   TC_SetRC(TC2, TC2_CHANNEL_FOR_TCLK8, 13);
   /* start the timer */
   TC_Start(TC2, TC2_CHANNEL_FOR_TCLK8);
   /* enable the timer-specific interrupts */
   REG_TC2_IER2 = TC_IER_CPCS | TC_IER_ETRGS;
}


/****************************************************************/

void TakeDownTC2(void)
{
   TC_Stop(TC2, TC2_CHANNEL_FOR_TCLK8);
   TC_SetRC(TC2, TC2_CHANNEL_FOR_TCLK8, 0);
   REG_TC2_IDR2 = TC_IER_CPCS | TC_IER_ETRGS;
   NVIC_DisableIRQ(TC8_IRQn);
   pmc_disable_periph_clk(ID_TC8);
}


/****************************************************************/

void setup(void)

   pinMode(13,OUTPUT);
   Serial.begin(9600);
   printf("start with TC2 internal\n");
   SetupTC2(true);
}


/****************************************************************/

void loop(void)
{
 
        if(upflag==0)
        {
        oldmillis = millis();
        upflag=1;
        Serial.println("I an upflag 0");
        }
        if((millis()-oldmillis)>=200)
        {
        ledon=!ledon;
        digitalWrite(13,ledon);
        upflag=0;
        Serial.println("I am in LED ON");
        }
       
  //phase=TC2_EXTERNAL;
  //Serial.println(phase);
   switch (phase)
   {
      case TC2_INTERNAL:
         if (tc2IRQsServiced[0] > 250000)
         {
            phase = PIOD_EXTERNAL;
            TakeDownTC2();
            printf("PASSED\nswitch to PIOD\n");
            SetupPIOD();
         }
         break;
      case PIOD_EXTERNAL:
         if (pioIRQsServiced > 20)
         {
            phase = TC2_EXTERNAL;
            TakeDownTC2();
            printf("PASSED\nswitch to TC2 external\n");
            SetupTC2(false);
         }
         break;
      case TC2_EXTERNAL:
         if (tc2IRQsServiced[1] > 20)
         {
            printf("PASSED!!!\n");
            for ( ; ; );
         }
         break;
      default:
         break;
   }
   //delay(1000);
   printf("PIO IRQs: %d, CPCS internal IRQs: %d, CPCS external IRQs: %d, ETRGS external IRQs: %d, status: %08x, CV2: %d\n", pioIRQsServiced, tc2IRQsServiced[0], tc2IRQsServiced[1], tc2IRQsServiced[2], status, REG_TC2_CV2);
   if (Serial.available() > 0)
   {
      char choice = Serial.read();
      if (choice == 'z')
      {
         REG_TC2_BCR = TC_BCR_SYNC;
      }
   }
}


The problem is does not immediately recognize the interrupt.It reads zero for a minute and then it starts.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Mon Jun 22, 2015 8:04 am

Just checked.It starts detection when enum=2 i.e phase 3 when it goes into TC2_External. Good news is that now we have a method to detect the external clocks. I wonder if it would capture such a high freq signal.

Serial.print statements were also not working when the ISR_NAKED was declared and with reti( ). We need to such an equivalent to the code here as well.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Mon Jun 22, 2015 11:01 am

change your Serial.begin(9600) to something much higher. try 115200, and if that doesnt work, try all the higher options (i dont know what bit rates the serial monitor can accept).
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby guest » Mon Jun 22, 2015 11:04 am

another thing you can do for these tests, is not send data every interrupt. the data is overflowing in the transmit buffer. also, set the clock divider to 256, and make sure you are getting a 44.1k pulse at your new ss pin (toggle a pin within the interrupt routine).
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Mon Jun 22, 2015 9:52 pm

So tell me what does ISR_NAKED do in your code and how should I write an equivalent of not including reti() in my code?
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Mon Jun 22, 2015 10:28 pm

you should NOT use ISR_NAKED. that will make anything the main{} loop fail. the UNO needed that to help save processing time, but with the DUE it wont be necessary, and will make things more difficult. as a result, you also do not need to use reti().
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Tue Jun 23, 2015 3:54 am

Right now I am not using ISR_NAKED. But what I observed is that if I give the 11Mhz CLKOUT Signal as the input to pin30 the main loop() does not run at all.What shall I do now?It runs for signals with 200ms time period.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Tue Jun 23, 2015 11:28 am

you are doing too much in the main loop, most likely. get rid of anything in the mian loop, and just toggle an external pin in the interrupt, so you can see that its working. watch this pin on your scope, and make sure its at the frequency you expect. then, you can slowly add things back to your main loop, one at a time, and see what makes it break. but, before doing that, you could also get SPI working. with the MAPLE (another ARM processor), i found that the USB peripheral had an interrupt that took too long, and conflicted with the SPI. hopefully that is not the case here.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Fri Jun 26, 2015 9:59 pm

The main loop is just a switch statement with print statement.I will do what you said i.e to toggle a pin and that will give us an idea. I will check it with a scope and get back.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Fri Jul 03, 2015 9:45 pm

I am turning a GPIO pin on and off with the interrupt coming from CLKOUT pin.I am getting a frequency of 142 Khz i.e 0.14Mhz on the GPIO pin where as the clock signal is at a frequency of 11.363 Mhz signal. What shall I do now?
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

PreviousNext

Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron