• AVR Freaks

Hot!dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS)

Author
JPortici
Super Member
  • Total Posts : 1114
  • Reward points : 0
  • Joined: 2012/11/17 06:27:45
  • Location: Grappaland
  • Status: offline
2020/07/08 04:53:40 (permalink)
0

dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS)

i have a set of noisy signals.Due to hardware constraints i can't filter much on the hardware side so i wanted to add some filtering after the acquisition (also, i'm taking advantage of the noise to provide oversampling)
I'm not really satisfied of the response of a moving average filtering so i was thinking about using an IIR filter instead, easy and fast as well, a bunch of assembly instructions in a separate module.
 
The problem is YMEMORY in the 512kB dsPICs is located in the extended data space, and i wasn't able to find many examples of using indirect access of EDS in assembly.
I wonder if i could have any pointer?
 
In case anyone ask, i am not really interested in using the DSP library, i always found out to have too much overhead for simple operations and i didn't really find working examples for the 512kB dsPICs, probably because the code must be altered as both X and Y data spaces can be on EDS?
 
To make things simple, how should i write a MAC with prefetch in this case?
something like [PROLOGUE] [MAC] [EPILOGUE]
#1

8 Replies Related Threads

    my504
    Junior Member
    • Total Posts : 20
    • Reward points : 0
    • Joined: 2018/01/21 05:29:36
    • Location: Moskow reg., Fryazino
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/08 05:22:40 (permalink)
    4 (1)
    Jack_M
    The problem is YMEMORY in the 512kB dsPICs is located in the extended data space
     

    As I understand it, you are going to place a table of filter coefficients in a flash ...
    It is a bad idea. In the EP family, PSV access to the flash address space is FIVE !!! machine cycles.
    I prefer to copy filter coefficients to the buffer and work only with RAM.
    About the IIR.
    Unlike FIR, the code is very cumbersome.
    I think the problem is not in the quality of the IIR versus FIR filtering, but in the intersection of the signal and noise spectra. In this case, it is worth paying attention to correlation and nonlinear filtering ...
     
    #2
    JPortici
    Super Member
    • Total Posts : 1114
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/08 06:30:32 (permalink)
    0
    Y DATA RAM starts at 0x9000.
    my undestarding is that i have to mess with DSRPAG/DSWPAG if i want to access RAM after 0x7FFE because the compiler will be using it for PSV
    The algorythms for an IIR in first direct mode is rather easy IMHO. about a dozen assembly lines..
    post edited by JPortici - 2020/07/08 06:34:38
    #3
    NorthGuy
    Super Member
    • Total Posts : 6228
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/08 07:43:27 (permalink)
    5 (1)
    Jack_M
    Y DATA RAM starts at 0x9000.
    my undestarding is that i have to mess with DSRPAG/DSWPAG if i want to access RAM after 0x7FFE because the compiler will be using it for PSV
    The algorythms for an IIR in first direct mode is rather easy IMHO. about a dozen assembly lines..



    If I remember correctly, DSRPAG and DSWPAG are for X memory only. 0x9000 is the address where Y memory is mapped into X space. The instructions which access Y memory should access it directly. I'm not sure if the first byte of the Y memory should be accessed as 0x1000 or 0x0000. This is easy to test.
    #4
    JPortici
    Super Member
    • Total Posts : 1114
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/09 01:12:19 (permalink)
    0
    I did some tests by placing arbitrary data at particular addresses
    #include <xc.h>

    int __attribute__((space(xmemory))) testxmem = 0xFF;
    int __attribute__((eds,space(ymemory),address(0x9000))) testymem = 0x1;
    __psv__ int __attribute__((space(psv),address(0x9000))) testconst1 = 0x2;
    __psv__ int __attribute__((space(psv),address(0x1000))) testconst2 = 0x3;
    const int testconst3 = 0x4;   //Having a const

    int main(void) {
      volatile int var;
     
      var = testxmem;       //var = 0xFF
      var = testymem;       //var = 0x03 <-- WRONG! unless i declare with __eds__
      var = testconst1;     //var = 0x02
      var = testconst2;     //var = 0x03
      var = testconst3;     //var = 0x04
      return 0;
    }


     
    Generated assembly for
    var = testymem;

    is
    MOV testymem,W0
     
    MOV W0,[W14]

    where testymem is the address of the variable, 0x9000 (checked by switching off symbolic view, or by decoding the opcode)
     
    From what i understood, if i don't declare the variable with the __eds__ or __psv__ attributes, the compiler assumes that the address is in the currently selected page. But since i have a const (which is placed in auto_psv) the startup code will set DSRPAG to point to the auto_psv page. In fact, if i comment out testconst3 DSRPAG is set to "1" and accessing testymem gives the correct value.
     
    This is also confirmed by the reference manual, since testymem is at 0x9000, bit 15 is "1" so the AGU will take whatever is at address 0x1000 in the currently selected page.
    I tried also some inline assembly
    MOV 0x9000,W10;because W10 is one of the registers that must point at ymem in DSP instructions
    MOV [W10],W0
    MOV W0,[W14]

    but it was again 0x03, unless i changed the page
     
    So i have to save/change/restore DSRPAG, it seems.
    Now i will test with a DSP instruction
    post edited by JPortici - 2020/07/09 01:16:05
    #5
    JPortici
    Super Member
    • Total Posts : 1114
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/09 01:30:02 (permalink)
    4 (1)
    Aaaaand i tested with a DSP instruction. Stupid me, i should have done this from the beginning.
    Even though i wasn't able to find it written clearly, apparently the DSP doesn't care and always fetch from RAM, in the Y bus.
    with the variables declared as above
    MOV #0x1000,W8
     
    MOV #0x9000,W10
     
    CLR A,[W8],W4,[W10],W5

     
    results in
    ACCA = 0
    WREG4 = 0xFF
    WREG5 = 0x01
    whatever the value of DSRPAG
     
    EDIT: I found it after re-reading Section 3 of the reference manual for the nth time (we'd need a facepalm smile if adding a smiley wouldn't break this damn forum)
    The Y AGU can only generate an EA within the base data space address range 0x0000 to
    0xFFFF and cannot extend into EDS

    post edited by JPortici - 2020/07/09 01:34:15
    #6
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3984
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/09 05:31:55 (permalink)
    2 (1)
    There are no overheads for the DSC instructions unless you are using
    C where data has to be put into the correct register set.
     
    :: 32bit DSC Double Double Function ::
     
    Here I combine A + B for an 80bit accumulator.
     
    It takes a 32bit number and converts it into 10 x BCD
    that can fit into a 40bit accumulator.
    .include   "xc.inc"
    .globl      doubledabble
    ; ----------------------------------------------------
    .section    QuickPrint, code
    ; ----------------------------------------------------
    arg_ValueL      = w0
    arg_ValueH      = w1
    ptr             = w2
    x               = w3
    y               = w4
    zero            = w5
    accblow         = w6

    doubledabble:
        ; init: saturation off, align value32 to 39:32
        bclr    CORCON, #SATA
        bclr    CORCON, #SATB
        bset    CORCON, #ACCSAT
        lac.d   arg_ValueL, #-8, A
        clr     B
        clr     zero
        mov     #ACCBL, accblow
        ; - - - - - - - - - - - - - - - -
        ; 3 x 72bit left shift
        do      #3-1, 1f
        btst    ACCAU, #7
        sftac   A, #-1
        sftac   B, #-1
    1:  bsw     [accblow], zero
        nop
        ; - - - - - - - - - - - - - - - -
        ;32bits - 3 already done
        do      #32 - 3 - 1, fin
        ; - - - - - - - - - - - - - - - -
        ; dabble 10 nibbles
        mov     #ACCBL, ptr
        do      #5 - 1, dabble_end
        ; - - - - - - - - - - - - - - - -
        ; low nibble
        mov.b   [ptr], x
        and     x,#0xF, y
        cp      y, #5
        bra     ltu, high
        add     #3, y
        and     #0xF, y
        and     #0xF0, x
        ior     x, y, x
        ; - - - - - - - - - - - - - - - -
    high:
        ; high nibble
        lsr     x, #4, y
        and     #0xF, y
        cp      y, #5
        bra     ltu, $+4
        add     #0x30, x
        ; - - - - - - - - - - - - - - - -
     dabble_end:
        mov.b   x, [ptr++]
        ; - - - - - - - - - - - - - - - -
        ;72bit shift left
        btst    ACCAU, #7
        sftac   A, #-1
        sftac   B, #-1
    fin:bsw     [accblow], zero
        nop
        return
    ; ----------------------------------------------------
    .end


    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.
    #7
    Radiocat
    Andy the Radiocat
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2020/05/05 03:28:50
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/12 23:04:06 (permalink)
    0
    Having seen the recent posts regarding issues with use of Y in Extended memory space, perhaps someone could explain why I am having problems with code in Y space. I have an FIR that has worked fine in DsPic33FJ128GP802 and 804 devices, but when used in a DsPic33EP512MC806 any action performed on registers located  at 0xd400 result in the register taking up a value of 0xffff. In addition to this a Mac instruction just fails to perform at all. Is there something unique about this Extended area that requires some other action to make it available for use, apart from use of the .eds directive when reserving the space.
    Brian
    #8
    rontaylor
    Starting Member
    • Total Posts : 40
    • Reward points : 0
    • Joined: 2009/07/31 08:22:53
    • Location: 0
    • Status: offline
    Re: dsPIC33EP512MU814, how to use the DSP? (because YMEMORY is in EDS) 2020/07/14 01:45:07 (permalink)
    0
    Hi JPortici,
     
    Here's how I declare the filter Kernel space in my HF multimode radio system;
     
    ;*********************************************************************************************
    ; Reserve Kernel Memory
    ;
    ; Storage in Y Memory for filter coefficients
    .section yfir, ymemory, align(4096), eds

    ; De-noiser Coefficients
    .global _den_coeff ; Coefficients start
    _den_coeff: .space 256 ; Storage for coefficients in bytes
    ;
    ; Quad Filters
    ; Left Coefficients
    .global _quad_coeff ; Quad coefficients start
    _quad_coeff: .space 256 ; Storage for coefficients in bytes
    ;
    ; Decimation Filters
    .global _dec_coeff ; Decimation coefficients start
    _dec_coeff: .space 256 ; Storage for coefficients in bytes
     
    The FIR filters are part of the assembler signal processing block called by the ISR at sampling rate (48kHz) and the filter data is loaded into kernel memory from C and can be changed on the fly depending upon operating mode or bandwidth.
     
    I design the kernels using a program called FIR Designer which I wrote using Microsoft's free version of Visual Studio. Design process is Windowed Sinc.
     
    PM me for more details.
     
    Regards
     
    Ron Taylor G4GXO
    Penrith UK
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5