Hot!Problem with DSP core of dsPIC33EP512MU810

Author
kappa_am
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2015/05/06 07:24:30
  • Location: 0
  • Status: offline
2018/06/12 21:12:59 (permalink)
0

Problem with DSP core of dsPIC33EP512MU810

Hi,
I am trying to use of DSP by assembly instructions, But value of Accumulator A, Which I use, stay zero, and SAC instruction make it just 1. I would greatly appreciate if if you comment on this issue.
    asm{
    CLR A
    MOV _MLP, W4
    MOV _MLPCND, W5
    MPY W4*W5, A, [W8]+=2, W6, [W10]-=2, W7
    MOV _SHFT, W4
    MOV _SHFT, W5
    MAC W4*W5, A, [W8]+=2, W6, [W10]-=2, W7
    MOV #1, W4
    MOV _SHFT, W5
    MAC W4*W5, A, [W8]+=2, W6, [W10]-=2, W7
    MOV #lo_addr(_LNUMLNG), W9
    SAC A, #0, [W9]}

 
Thank you
#1

14 Replies Related Threads

    JPortici
    Super Member
    • Total Posts : 232
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/13 01:14:44 (permalink)
    0
    Provided you are using XC16, I may be wrong but i'm not sure how it's compiling, at all.
     
    AFAIK the correct syntax for multiline asm instructions is either
    volatile asm("CLR A \n
     MOV _MLP, W4 \n
     ... "};

    with the new line characters to separate each line
     
    or, which i prefer for debugging
    volatile asm("CLR A");
    volatile asm("MOV _MLP,W4");
    ...

     
    in this case i'm sure that no operation is optimized away and i am sure of the single stepping
     
    have you tried single stepping with the debugger to see what is happening? The dsPIC programmer manual provides very clear examples for each instructions with before/after states and contents of registers
     
    you may want to use the simulator instead of the device at this stage.. much faster than reprogramming the part every time
    #2
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/13 02:44:07 (permalink)
    0
    How do you know it is zero?
     
    ACCAU
    ACCAH
    ACCAL
     
    These low registers can get clobbered.  Use the assembler not the inline assembler.
     
    With inline you have to do this sort of coding and it does not look very good.  It looks more complicated than real assembly.
    //shift sector by sdhd (9 or 0)
        asm volatile("sl %d0,%1,%d0":"+r"(Sector):"r"(FC->SDHD));
        asm volatile("mov #16,%0":"+r"(tmp));
        asm volatile("sub %0,%1,%0":"+r"(tmp):"r"(FC->SDHD));
        asm volatile("lsr %1,%0,%0":"+r"(tmp):"r"(Sector));
        asm volatile("sl %0,%1,%0":"+r"(Sector):"r"(FC->SDHD));
        asm volatile("ior %d0,%1,%d0":"+r"(Sector):"r"(tmp));


    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #3
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/13 02:45:55 (permalink)
    0
    void testcode(int MLP, int MLPCND, int SHIFT, unsigned long *LNUMLNG);
    .globl _testcode
    .section testacc,code
     
    .equ arg_MLP, w0
    .equ arg_MLPCND,w1
    .equ arg_SHFT,w2
    .equ arg_ptr_LNUMLNG,w3
     
    _testcode:
    push.d w8   <--- preserve registers w8 - w13 and w14
    push w10
    CLR A
    MOV arg_MLP, W4
    MOV arg_MLPCND, W5
    MPY W4*W5, A, [W8]+=2, W6, [W10]-=2, W7
    MOV arg_SHFT, W4
    MOV arg_SHFT, W5
    MAC W4*W5, A, [W8]+=2, W6, [W10]-=2, W7
    MOV #1, W4
    MOV arg_SHFT, W5
    MAC W4*W5, A, [W8]+=2, W6, [W10]-=2, W7
    ;;;;MOV #lo_addr(_LNUMLNG), W9 
    mov arg_ptr_LNUMLNG,w9
    SAC A, #0, [W9]
    pop w10
    pop.d w8
    return
    .end

    post edited by Gort2015 - 2018/06/13 03:00:23

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #4
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/13 03:08:25 (permalink)
    0
    int TESTU, TESTH, TESTL;
    Also add this at the end for debugging.
     
    push ACCAU
    pop _TESTU
    push ACCAH
    pop _TESTH
    push ACCAL
    pop _TESTL

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #5
    kappa_am
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2015/05/06 07:24:30
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/13 22:57:31 (permalink)
    0
    Thank you all for your helpful comments.
    I checked both by simulation and implementation ACCAU, ACCAH, ACCAL remain zero, whatever math is. only SAC instruction causes the variable gets value "1". I tried everything, but no hope.
    Actually I am using MikroC, and since my program is large I cannot switch to XC16.  I found several bugs in this software and reported them to developer. My program is over 4000 lines, combination of C and inline asm.  neighter built-in library nor inline asm. can get correct results from DSP. I don't really don't know what to do.
    What's your recommendation?
    Thank you for the help.
     
    #6
    longlongint
    Super Mamba
    • Total Posts : 116
    • Reward points : 0
    • Joined: 2012/02/15 06:18:13
    • Location: jn66wo
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/14 01:10:32 (permalink)
    0
    Dear Kappa_am
    The "CLR A" needs to include the intitial prefetch: 

    ; Clear Accumulator and prefetch 1st pair of numbers
    CLR A, [W8]+=2, W4, [W10]+=2, W7

    This is copied from "16-Bit_Language_Tools_Getting_Started_70094E.pdf"
    (Could be outdated, is from 2009?)
     
    have fun
    longlongint
    post edited by longlongint - 2018/06/14 02:56:52
    #7
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/14 02:33:08 (permalink)
    0
    Try something simple:
    int TESTU,TESTH,TESTL;
    mov #7,w4
    mov #11,w5
    mpy w4*w5,A
    push ACCAU
    pop _TESTU
    push ACCAH
    pop _TESTH
    push ACCAL
    pop _TESTL
    return
    printf("U %04X, H %04X, L %04X\r",TESTU,TESTH,TESTL);
     
    It could be that A and B are used by the compiler before you use A and B.
    post edited by Gort2015 - 2018/06/14 02:34:21

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #8
    NorthGuy
    Super Member
    • Total Posts : 4929
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/14 06:34:00 (permalink)
    0
    What are you trying to accomplish?
     
    Why do you prefetch data into W6/W7 and then never use them?
     
    Does W8 point to X memory? Does W10 point to Y memory?
     
    Are you trying to calculate _MLP*_MLPCNT + _SHIFT*(1 + _SHFT)? It is easier and faster to do this with regular non-DSP instructions, or better yet with C.
    #9
    kappa_am
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2015/05/06 07:24:30
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/14 11:03:01 (permalink)
    0
    thank you again all. I will try the recommendations. However, even when I create a new project and insert some DSP instruction I do not get a correct answer, yet.
     
    Dear NorthGuy, This is part of a large program, and I just try to get DSP engine working, in this stage. the instructions may not make sense. I already tried C and non_DSP instruction. non-DSP instruction takes 25 cycles for a long multiplication and shift, C even way more; since I have many multiplications and shift and DSP accumulator are 40-bit wide, I'd like to use DSP.
    #10
    du00000001
    Just Some Member
    • Total Posts : 1967
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/14 11:56:38 (permalink)
    3 (1)
    IIRC, there is a large DSP support library for the dsPIC33's available. Why not use this one?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #11
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/14 13:21:29 (permalink)
    0
    MOV #lo_addr(_LNUMLNG), W9
    is:
    mov _NUMLNG,w8     ;low
    mov _NUMLNG+2,w9 ;high
    or:
    mov #_NUMLNG,tmp
    mov.d [tmp++],w8
    post edited by Gort2015 - 2018/06/14 13:24:45

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #12
    kappa_am
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2015/05/06 07:24:30
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/15 12:43:35 (permalink)
    0
    It is first one.
    #13
    RISC
    Super Member
    • Total Posts : 5220
    • Reward points : 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/16 12:58:38 (permalink)
    3 (1)
    Hi,
    I found in my archives an old dsPIC33FJ256GP710A example for DSP instructions usage.
    It should work similarly on dsPIC33EPxxxx architecture with a few adapatations (config bits etc...).
    Remove the .txt in attached project (it is a .zip archive which is not allowed as attachment) 
    Regards
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2645
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Problem with DSP core of dsPIC33EP512MU810 2018/06/16 13:22:11 (permalink)
    0
    I meant that is how you write it:
    mov _NUMLNG,w8     ;low

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #15
    Jump to:
    © 2018 APG vNext Trial Version 4.5