Testing task on xCORE.ai Audio evaluation board: audio glitches

New to XMOS and XCore? Get started here.
sonaben
Junior Member
Posts: 7
Joined: Fri Nov 10, 2023 11:21 am

Testing task on xCORE.ai Audio evaluation board: audio glitches

Post by sonaben »

Hello,

I'm a total beginner with xmos, so pardon my ignorance.
I've purchased the xCORE.ai Audio evaluation board, and I'm trying to run a task along with a 8in/8out audio application.

For now I'm simply trying to run a task to switch some leds on or off every x seconds (using hwtimer_t).

I've updated user_main.h from app_usb_aud_xk_316_mc to add the call to "myTask":

Code: Select all

#define USER_MAIN_CORES on tile[0]: {\
                                        ctrlPort();\
                                        i2c_master(i2c, 1, p_scl, p_sda, 100);\
                                    }\
                        on tile[1]: {\
                                        unsafe\
                                        {\
                                            i_i2c_client = i2c[0];\
                                        }\
                                        myTask();\
                                    }
And added a user_main.c:

Code: Select all

void myTask() {

    unsigned long currTime = 0, prevTime = 0;
    int on = 1;

    hwtimer_t timer = hwtimer_alloc();

    while(1) {
      currTime = hwtimer_get_time(timer);
      if (currTime - prevTime > 100000000) {
        prevTime = currTime;
        if (on) {
          ledsOn();
        }
        else {
          ledsOff();
        }
        on = (on == 1) ? 0 : 1;
      }
    }

    hwtimer_free(timer);
}
However when I run the code and play some music I can hear some audio glitches.
Is it because the task is running on the audio tile?
I've looked at the main.xc in lib_xua and I thought the task would run in parallel on a different core, but this doesn't seem to be the case.

Thanks for your help!


lmariotti
Member++
Posts: 27
Joined: Mon Nov 21, 2022 5:38 pm

Post by lmariotti »

Hi sonaben,

I'm not sure why your solution doesn't work (not an expert here), but I've achieved to have a blinking led in usb-audio with no glitches as follow:

Code: Select all

#define BLINK_LED_TILE (0)
#defien BLINK_LED_PORT (XS1_PORT_4B)

on tile[BLINK_LED_TILE] : out port led_port = BLINK_LED_PORT;

void Blink_led(unsigned period) // [ms]
{
  timer t;
  unsigned time = 0;
  unsigned tmp = 0;

  while(1)
  {
    select
    {
      case t when timerafter(time) :> void:
        time += period * 100000;

        led_port <: tmp;
        tmp ^= 1;
      break;
    }
  }
}

int main()
{
  ...

  on tile[BLINK_LED_TILE]: Blink_led(500);
  ...
}
This is XMOS example code for blinking led described in XMOS Programming Guide XM004440A.

Hope this help.
User avatar
Ross
XCore Expert
Posts: 966
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

I cannot see an issue with your example Sonaben, however, looks that lmariotti has done the work for you :)