VS1053b timer interrupt stops triggering on playback?

Writing software that inputs and/or outputs audio and performs DSP algorithms such as filters, new codecs or audio effects.
Post Reply
awong
User
Posts: 6
Joined: Tue 2016-10-18 9:45

VS1053b timer interrupt stops triggering on playback?

Post by awong » Tue 2016-10-18 9:59

Hello!

I'm have an Adafruit Music Maker Breakout board with a VS1053 on it. It's being driven by a Sparkfun Arduino Mini Pro.

I'm attempting to use the VS1053's GPIO pins to drive some LEDs using either TIMER1 or TIMER0 to generate a PWM signal to the LEDs while the DSP is decoding back mp3 audio. To start though, I just tried blinking an LED at a constant rate based on the timer.

I was successfully able to write a plugin and in it, configure the TIMER1 during APPL_RESET. The LED seems to blink correctly until decode starts. Then it looks like the interrupt for the timer just stops firing. Any idea what might be happening?

Here's my ISR's C routine is:

Code: Select all

void PwmInterrupt(void) {
  static u_int16 pwmCount = 1;
  u_int16 val = USEX(GPIO_ODATA);
  if (pwmCount == 1 ) {
    val &= ~(1 << 5);
    pwmCount = 0;
  } else {
    val |= (1 << 5);
    pwmCount = 1;
  }
  USEX(GPIO_ODATA) = val;
}
The ISR's stub routine was taken from http://www.vlsi.fi/fileadmin/manuals_gu ... p4_ump.pdf section 5.4.1 (btw, I think there's an error in the last 3 of ASM lines...I think it should be working in X space to be consistent with the rest of the stub code).

User avatar
Henrik
VLSI Staff
Posts: 1041
Joined: Tue 2010-06-22 14:10

Re: VS1053b timer interrupt stops triggering on playback?

Post by Henrik » Tue 2016-10-18 10:38

Hello!

Welcome to our forums, and congratulations on getting right to the advanced topic of assembler programming!

This may seem like a stupid question, but you don't by any chance happen to set SM_RESET in SCI_MODE register before starting decoding? If you do that, VS1053b will be reset and your timer interrupt will be lost.

You are correct that the example in the VS_DSP4 manual isn't directly usable in VS1053b because the VS1053b hardware registers lie in X memory. (The code isn't incorrect, though.)

To make the example code work for VS1053b, you will need to change all lines where there are comments like "If registers in X space". This means the last lines as you noticed, but also the first line:

Code: Select all

_int_routine0:
  STY i7,(i6); STX mr0,(i6)+1 // Registers in X space
  [... unchanged until three last lines ...]
  LDX (i6),mr0  // Registers in X space
  RETI
  STX i7,(i7); LDY (i6)-1,i7 // Registers in X space
If also the first line isn't changed, a crash will almost certainly happen because the interrupt may destroy the contents of the mode register MR0.

Kind regards,
- Henrik
Good signatures never die. They just fade away.

awong
User
Posts: 6
Joined: Tue 2016-10-18 9:45

Re: VS1053b timer interrupt stops triggering on playback?

Post by awong » Tue 2017-03-28 9:10

Whoa..I missed this response for all of the past few months.

Thanks for the tips. I'll see if I can resurrect my code and figure out what is happening. I don't believe I am setting SM_RESET, but I'll have to reproduce my prior experiment to tell. :)

awong
User
Posts: 6
Joined: Tue 2016-10-18 9:45

Re: VS1053b timer interrupt stops triggering on playback?

Post by awong » Mon 2017-04-03 8:19

Incorrectly storing MR0 during the interrupt stub prologue was indeed the mistake. Thanks for catching that!

Now I have a different problem. During actual playback, I seem to be missing interrupts from the timer.

I configure the timer during APPL_RESET, but during active playback my PWM function doesn't seem active (all leds connected to the GPIOs don't change intensity). After playback finishes, the timer routine handles changing the LED brightness as expected.

My best guess is that the timer interrupt is disabled (or maybe interrupts are globally disabled?) during servicing of the plugin code. Is that true? If so, do you know which interrupts are enabled/disabled? Thanks!

User avatar
pasi
VLSI Staff
Posts: 1416
Joined: Thu 2010-07-15 16:04

Re: VS1053b timer interrupt stops triggering on playback?

Post by pasi » Mon 2017-04-03 12:05

APPL_RESET is only called when the samplerate changes.

Interrupt enable is set during software reset, so that could override the timer interrupt enable.

File playback itself should not touch interrupt enables or the timer. Application hook code is called in the decode context with interrupts enabled.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

awong
User
Posts: 6
Joined: Tue 2016-10-18 9:45

Re: VS1053b timer interrupt stops triggering on playback?

Post by awong » Thu 2017-04-06 9:31

Found the problem. My memory configuration file was incorrect.

I copied one of the user_vs1053.mem files from VSIDE Version 2.36. The file was

Code: Select all

MEMORY {
page 0:
        #Program RAM
        #reset: origin = 0x0, length = 2
        dac_int: origin = 0x20, length = 1
        sci_int: origin = 0x21, length = 1
        sdi_int: origin = 0x22, length = 1
        modu_int: origin = 0x23, length = 1
        tx_int: origin = 0x24, length = 1
        rx_int: origin = 0x25, length = 1
        tim0_int: origin = 0x26, length = 1
        tim1_int: origin = 0x27, length = 1
        src_int: origin = 0x28, length = 1
        sdm_int: origin = 0x29, length = 1
        ram_prog:  origin = 0x0050, length = 0x0fb0
page 1:
        #Data X RAM
        data_x:   origin =  0x0800, length = 0x1000
page 2:
        #Data Y RAM
        data_y:   origin =  0x1000, length = 0x0800
        extra_y:  origin = 0xe000, length = 0x2000
}

CORE {
        frequency = 12.288MHz
        bootaddr = 0x4000
}
When compared with the VS1053b Memory Map (section 10.3) inside the vs1053b data sheet, the data_x, data_y, and extra_y configurations look incorrect.

Since I have a few globals in my C program, the linked binary was overwritting 0x0800-0x0804 which is system ram, thereby causing unknown effects.

Once I fixed the origin and length to match for data_x and data_y (and then removed extra_y), my interrupt now runs while playback is going. Yay!

Would it be interesting if I could produce a dockerized build environment for VSIDE (thinking wine + ubuntu)? I have a 90% hacked up version I'm using to do this development on my mac currently... I could try to clean it up if there's interest...

User avatar
Henrik
VLSI Staff
Posts: 1041
Joined: Tue 2010-06-22 14:10

Re: VS1053b timer interrupt stops triggering on playback?

Post by Henrik » Tue 2017-04-11 9:05

Hello!

Nice to hear you got your system working!

As for Docker, I am not really familiar enough with it to understand the implications of using it.

Kind regards,
- Henrik
Good signatures never die. They just fade away.

Post Reply