|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Tue Jul 25, 2023 8:17 am |
|
|
It's the POP tw instruction in build_twiddle that is crashing.
It should be triggering an address error interrupt though. |
|
|
Marco27293
Joined: 09 May 2020 Posts: 115
|
|
Posted: Tue Jul 25, 2023 8:18 am |
|
|
How could I fix this problem ?
Code: |
void build_twiddle(Complex* tw, unsigned int16 fft_size)
{
unsigned int16 i = 0;
float32 theta = 0;
float32 d_theta = 0;
d_theta = 2 * PI / (fft_size);
for(i = 0;i < fft_size / 2;i++)
{
//e^(-j * theta) = cos(theta) - j * sin (theta)
tw[i].re = (signed int16) (32767.0 * cos(theta));//scale to full range (-32768 to 32767)
tw[i].im = (signed int16) (-32767.0 * sin(theta));
theta += d_theta;//increment to the next theta value
}
}
|
where is POP issue ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Tue Jul 25, 2023 9:41 am |
|
|
Look at the symbol listing. The actual error is:
Trap due to unimplemented RAM memory access, occurred from instruction at 0x000AFE
Just tried increasing the stack size, and that error disappears. Presumably
the larger table needs more stack. See if that fixes the problem for you.
The listing file only shows a small amount used, but it may not correctly
reflect stack space used in the assembler... |
|
|
Marco27293
Joined: 09 May 2020 Posts: 115
|
|
Posted: Tue Jul 25, 2023 9:45 am |
|
|
Forgive me but I' m not understanding clearly...
How can I enlarge the stack ?
Could you provide me an example snippet code ?
Thank you very much |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Tue Jul 25, 2023 9:52 am |
|
|
That is standard programming for the DSPIC's. 99% of programs need
the stack enlarged:
Code: |
#include <33EP512GP502.h>
#build (STACK=512)
|
Should be the line after the processor include. |
|
|
Marco27293
Joined: 09 May 2020 Posts: 115
|
|
Posted: Tue Jul 25, 2023 9:59 am |
|
|
I tried,
using stack=512 and stack=2048, but the issue persists...
Any other suggestions ?
I really apprecciate your support, thank you very much!!
Moreover I used:
#build (STACK=0x8000:0x8800)
I got from trap error:
INT_SOFTWARE FAULT PC:29B8 W0:0 W1:0 W2:400 W3:1 W4:7F45 W5:2 W6:0 W7:1 W8:1002 W9:8 W10:9000 W11:0 W12:3FF W13:4 W14:2000 W15:8004 DSRPAG:1 DSWPAG:1 TBLPAG:0 INTCON2:8000 INTCON3:10 INTCON4:0 CORCON:42A
STACK (2) 0 2C76
and instruction located at PC: 29b8 is from lst file:
Code: |
.................... /* Clear the accumulators, prefetch lower-leg */
.................... clr B, [W8]+=2, W4 //B = 0, W4 = a.re W8 = &a[i].im
029B8: CLR , [W8]+=2,W4
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Tue Jul 25, 2023 11:18 am |
|
|
With the stack expanded, it now crashes at this line:
Code: |
mov [W0+W5], [W1+W5] //br[k].im = seq[i].im
|
in memcpy_brev
W0 is FFFC W5 is 0002, W1 is 0000.
Now W0 is loaded with the source address for this. This is called at the
start of the _fft function, which is the core of the actual fft function.
It's very odd. The actual function is called with dest=A2D0, but
this loads into W1, and is then zero!....
It then crashes because this is an invalid address.
Now looking at the assembler, the line where it loads is:
Code: |
251: mov dest, W1 //W1 = cplx_output; (bit-reversed pointer)
00BD8 811681 mov.w 0x22d0,0x0002
|
But dest is at A2DO
A2D0-A2D1 memcpy_brev.dest
The assembler is losing the top bit of the memory address.
It looks like this is an assembler fault in the compiler.
You need to report this to CCS.
I'll do so as well. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Tue Jul 25, 2023 11:57 am |
|
|
OK. Following tweaks to the assembler:
fft.h
Code: |
//at line 314:
//mov fft_len_div2, W2 //W2 = TWI = FFT_LENGTH / 2;
push fft_len_div2
pop W2
//mov fft_size, W14 //W14 = FFT_LENGTH
push fft_size
pop W14
SL W14, #2, W14 //W14 = fft_length * sizeof(complex)
mov #1, W3 //W3 = k_max = 1
mov #8, W9 //W9 = offset = 2 * sizeof(complex);
STAGE_LOOP:
clr W11 //for(k = 0;k < k_max;k++)
K_LOOP:
/* Get the twiddle factor for this k-group. */
//mov cplx_tw, W10 //W10 = cplx_tw (pointer)
push cplx_tw
pop W10
//Then at line 251
//mov dest, W1 //W1 = cplx_output; (bit-reversed pointer)
push dest
pop W1
mov source, W0 //W0 = cplx_input; (pointer)
mov #2, W5 //W5 = sizeof(signed int16*)
//mov fft_size, W4 //W4 = FFT_LENGTH;
push fft_size
pop W4
|
It then runs correctly.
I've replaced a number of mov instructions with push/pop's.
It appears these particular mov's are failing with addresses above 0x8000.
Best Wishes |
|
|
Marco27293
Joined: 09 May 2020 Posts: 115
|
|
Posted: Wed Jul 26, 2023 1:23 am |
|
|
Thank you very much!!
I implemented your solutions but I still got:
Code: |
INT_SOFTWARE FAULT PC:29C2 W0:0 W1:0 W2:400 W3:1 W4:2B0 W5:2 W6:0 W7:1 W8:1002 W9:8 W10:9000 W11:0 W12:3FF W13:4 W14:2000 W15:7F84 DSRPAG:1 DSWPAG:1 TBLPAG:0 INTCON2:8000 INTCON3:10 INTCON4:0 CORCON:42A
STACK (2) 0 2C80
/////
/* Clear the accumulators, prefetch lower-leg */
.................... clr B, [W8]+=2, W4 //B = 0, W4 = a.re W8 = &a[i].im
029C2: CLR , [W8]+=2,W4
|
Could you help to further investigate ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Wed Jul 26, 2023 1:37 am |
|
|
Missed one I had done...
Code: |
void memcpy_brev(Complex* dest, Complex* source, unsigned int16 fft_size)
{
unsigned int16 xb;
xb = 0x8000 | (fft_size);
#asm
push MODCON //save the MODCON register
push XBREV //save the XBREV register
mov #0x01FF, W4
mov W4, MODCON
mov xb, W4
mov W4, XBREV
//mov dest, W1 //W1 = cplx_output; (bit-reversed pointer)
push dest
pop W1
mov source, W0 //W0 = cplx_input; (pointer)
mov #2, W5 //W5 = sizeof(signed int16*)
//mov fft_size, W4 //W4 = FFT_LENGTH;
push fft_size
pop W4
dec W4, W4 //W4 = FFT_LENGTH - 1;
do W4, END
mov [W0], [W1] //br[k].re = seq[i].re
mov [W0+W5], [W1+W5] //br[k].im = seq[i].im
add #4, W0 //i++
END:mov [W1], [W1++] //k = k_next
pop XBREV //restore XBREV
pop MODCON //restore MODCON
#endasm
}
//Then in _fft
#asm
/* Initialize. */
//mov fft_len_div2, W2 //W2 = TWI = FFT_LENGTH / 2;
push fft_len_div2
pop W2
//mov fft_size, W14 //W14 = FFT_LENGTH
push fft_size
pop W14
SL W14, #2, W14 //W14 = fft_length * sizeof(complex)
mov #1, W3 //W3 = k_max = 1
mov #8, W9 //W9 = offset = 2 * sizeof(complex);
STAGE_LOOP:
clr W11 //for(k = 0;k < k_max;k++)
K_LOOP:
/* Get the twiddle factor for this k-group. */
//mov cplx_tw, W10 //W10 = cplx_tw (pointer)
push cplx_tw
pop W10
sl W2, #2, W0 //W0 = sizeof(Complex) * offset
mul.uu W0, W11, W0 //W0 = k * (sizeof(Complex) * offset)
add W10, W0, W10 //tw = (tw + 1) (pointer)
|
Also has to be done in _ifft if you use this.
It's a problem, it is inherent in any chip where the Y Data RAM is above
0x8000. I've suggested to CCS, that they might do a fix that tests for
chips where this applies, and bodge as I have done.
The problem is that mov instruction is limited to 15bits of data space,
so fails on chips where this applies. The code requires the factors are
in the Y Data space, so is going to fail on all chips where this is above
0x8000.
The push/pop adds one instruction time to this move, but otherwise
solves the issue. |
|
|
Marco27293
Joined: 09 May 2020 Posts: 115
|
|
Posted: Wed Jul 26, 2023 1:47 am |
|
|
I do not use ifft.
I implemented all the solutions but I still have error at this PC instruction:
Code: |
INT_SOFTWARE FAULT PC:29C2 W0:0 W1:0 W2:400 W3:1 W4:13 W5:2 W6:0 W7:1 W8:1002 W9:8 W10:9000 W11:0 W12:3FF W13:4 W14:2000 W15:7F84 DSRPAG:1 DSWPAG:1 TBLPAG:0 INTCON2:8000 INTCON3:10 INTCON4:0 CORCON:42A
STACK (2) 0 2C80
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Wed Jul 26, 2023 3:09 am |
|
|
I'm running the CCS supplied example program, just modified to use your
chip and expand the table size to 2048. I'm building a simulated sin table
with a frequency of 500, and amplitude of 1. It merrily runs, and displays
the fft values on the terminal.
I'll message you directly and send my modified fft.h.
See if this works for you. |
|
|
Marco27293
Joined: 09 May 2020 Posts: 115
|
|
Posted: Wed Jul 26, 2023 3:46 am |
|
|
Thank you !!
Your support is essential!
I still have this issue:
INT_SOFTWARE FAULT PC:29C0 W0:0 W1:0 W2:400 W3:1 W4:30A W5:2 W6:FFFF W7:1 W8:1002 W9:8 W10:9000 W11:0 W12:3FF W13:4 W14:2000 W15:7F84 DSRPAG:1 DSWPAG:1 TBLPAG:0 INTCON2:8000 INTCON3:10 INTCON4:0 CORCON:42A
STACK (2) 0 2C7E
I should send you my main.cand main.h files in private mode...
Could you take a look to these files please ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19260
|
|
Posted: Wed Jul 26, 2023 4:39 am |
|
|
My example is the supplied CCS one, except have changed to your chip,
expanded the stack to 256, and added the #define Yabove8000, which
turns on the fix in my code (I did note this when I sent it to you).
You definitely need the stack expanded in your code. You have quite a
lot going on. |
|
|
Marco27293
Joined: 09 May 2020 Posts: 115
|
|
Posted: Wed Jul 26, 2023 4:46 am |
|
|
I still have the error.
I sent you my code, for clarification I've already tried to uncomment and use:
#build (STACK=256)
but nothing changes... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|