News:

;) This forum is the property of Proton software developers

Main Menu

Dspic33CK and FFT routines

Started by Wimax, Feb 08, 2026, 10:06 PM

Previous topic - Next topic

Wimax

Hello,

I am trying to use the DSP routines for dspic33, but I cannot get the one for complex FFT to work on dspic33ck256mp508. In my case, I need to perform a 1024 points FFT. To isolate it from the main programme, I created a simpler one (using 256 point FFT) based on the available example, but Q15.inc creates a linker error "section address must be even" and I can't go on.
Has anyone tried the DSP routines on Dspic33ck ? Any examples of working code ?

trastikata

#1
https://jontio.zapto.org/hda1/dsp.html

This was a great example of using MAC in conjunction with overheadless loops which accelerated the FFT an order of magnitude.

The author also had a neural voice recognition from microphone on dsPIC, based on MAC instructions ... overall the site was priceless source of information.

The site was ahead of its time, I see now it is closed, I regret is I did not saved the site. If you find a mirror or a copy, please share.

Wimax

Hi Trastikata,

Thank you very much for the info, but I didn't find a mirror yet.
Did you try the FFT inside DSP folder of PDS ?
The linker error I get is very strange as I did very small changes on one example code, I don't use the ADC, but I load the input buffer with known data just to see if it runs.


John Lawton

#3
There is a 2025 snapshot on Wayback if that helps:

https://web.archive.org/web/20250418103741/https://jontio.zapto.org/hda1/dsp.html

Maybe ask him where/why the site is gone?

John
-----------------------------------------------------------------------------------------
Amicus 8 and 16A/16B dev boards
Especially created for Positron development
https://www.easy-driver.co.uk/Amicus

trastikata

Quote from: John Lawton on Feb 09, 2026, 11:48 AMThere is a 2025 snapshot on Wayback if that helps:

https://web.archive.org/web/20250418103741/https://jontio.zapto.org/hda1/dsp.html


Wow, thank you John! This is exactly the same site, information there is very useful, now I have a site copy for future reference.

@Wimax I have not tested the DSP routines. If you have some time, take a look at the posted site snapshot, might be useful to you in future.

top204

#5
I have only just noticed that a directive is missing from some of the later dsPIC33 device PPI files. Namely, the end address of YRAM.

This is why the dsPIC33CK devices are giving a linker error for Y RAM boundaries.

I have now adjusted the compiler's ppi reading parser to counter-act this, so it will use the end address in the device if not present, and I will go through the ppi files and alter them for the next update.

However, open the file: 'P33CK256MP508.ppi', in the folder: "C:\Program Files (x86)\ProtonIDE\PDS\Includes\PPI\". But only open it in notepad.

And add a YRAMEND directive to it, as shown below:

RAMAMOUNT=24576    ; Total amount of RAM (in bytes)
CODEAMOUNT=0x2BD00  ; Total amount of Flash Memory (in bytes) read from the linker's .gld file
DMAAMOUNT=24576    ; Amount of DMA RAM (in bytes)
XRAMSTART=0x1000    ; Starting address of X RAM
YRAMSTART=0x5000    ; Starting address of Y RAM
YRAMEND=0x5FFF      ; End address of Y RAM
DMARAMSTART=0x1000  ; Starting address of DMA RAM (if any)


Notice that the text: "YRAMEND=0x5FFF      ; End address of Y RAM" has been added?

This will tell the compiler its limits when arranging Y RAM, and it will assemble and link correctly.

Note that the ADC operates differently on the dsPIC33CK devices, to the original dsPIC33 devices, so the code will not compile with the SFRs present in the sample code listings.

Regards
Les

Wimax

Hi Les,

I added the line in the ppi file, but looking at the datasheet seems that Y RAM for dspic33ck256mp508 should end at 0x6FFF (YRAMEND=0x6FFF      ; End address of Y RAM).
Now the code compiles correctly, but the simple code below resets the MCU.
I added this Nop cycle for the dspic33ck (after the def for dspic33E) inside FFT.inc

$ifdef _dsPIC33E
    Nop
$endif
$ifdef _dsPIC33CK
    Nop
$endif

but I didn't solve the problem. The MCU reset itself continously.


-------------





'****************************************************************
'*  Name    : TEST_FFT.BAS                                      *
'*  Author  : [Max]                                             *
'*  Notice  : Copyright (c) 2026 [2022 by MAX]                  *
'*          : All Rights Reserved                               *
'*  Date    : 08/02/2026                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************

Device = 33CK256MP508
Declare Xtal = 200


Declare Hserial_Baud = 38400 ' USART1 Baud rate @ 38.4 Kbps



Config FSEC        = BWRP_OFF, BSS_DISABLED, BSEN_OFF, GWRP_OFF, GSS_DISABLED, CWRP_OFF, CSS_DISABLED, AIVTDIS_OFF
Config FOSCSEL     = FNOSC_FRC, IESO_OFF
Config FOSC        = POSCMD_EC, OSCIOFNC_ON, FCKSM_CSECMD, PLLKEN_OFF, XTCFG_G0, XTBST_ENABLE
Config FWDT        = SWDTPS_PS2147483648, RCLKSEL_LPRC
Config FPOR        = BISTDIS_DISABLED
Config FICD        = ICS_PGD3, JTAGEN_OFF, NOBTSWP_DISABLED
Config FDMT        = DMTDIS_OFF
Config FDEVOPT     = ALTI2C1_OFF,ALTI2C2_OFF,ALTI2C3_ON, SMBEN_SMBUS, SPI2PIN_PPS
Config FALTREG     = CTXT1_OFF, CTXT2_OFF, CTXT3_OFF, CTXT4_OFF
Config FBOOT       = BTMODE_SINGLE       
       
PPS_Output(cOut_Pin_RP68, cOut_Fn_U1TX) ' Map UART1 TX pin to RD4
PPS_Input(cIn_Pin_RP67, cIn_Fn_U1RX)    ' Map UART1 RX pin to RD3

$define CS_DAC PORTB.9   ' SPI CS to DAC
$define CS_RAM PORTE.0   ' SPI CS to RAM
$define CS_SD  PORTD.2   ' SPI CS to SD


Include "Q15.inc"                           ' Load the Q1:15 fixed point procedures into the program
Include "FFT.inc"                           ' Load the DSP FFT procedures into the program

Symbol cNUM_OF_SAMPLES = 256                ' 256 pairs of complex (Re, Im) values, resulting in 128 FFT bins

Dim InputSamples[cNUM_OF_SAMPLES*2] As Word YRAM  ' Y RAM space is required by FFT routine
Dim Main_wIndex As Word                     ' Used for the main demo


PinInput PORTA.0
PinInput PORTB.2


Main:

IntOsc_200MHz()

High CS_DAC
High CS_RAM
High CS_SD



' Fill the InputSamples array with real and imaginary data

For Main_wIndex = 0 To (cNUM_OF_SAMPLES*2)-1 Step 2
   
    InputSamples[Main_wIndex] = 0             ' Place the result into the Real element of the complex array
    InputSamples[Main_wIndex+1] = 0
Next
HRSOutLn "Start"

FFT_ComplexIP(InputSamples, TwiddleCoeff_256, 8)    ' Perform an FFT of the captured data
FFT_BitReverseComplex(InputSamples, 8)              ' Bit reverse the complex FFT data

For Main_wIndex = 0 To (cNUM_OF_SAMPLES * 2) - 1 Step 2
HRSOutLn Dec InputSamples[Main_wIndex],"  ",Dec InputSamples[Main_wIndex+1]
Next

Do

Loop




Proc IntOsc_200MHz()


CLKDIV = $3001          ' FRCDIV FRC/1, PLLPRE 1, DOZE 1:8
PLLFBD = 100
OSCTUN = $00
PLLDIV = $21            ' POST1DIV 1:2, VCODIV FVCO/4, POST2DIV 1:1
ACLKCON1 = $0101        ' FRCSEL FRC, APLLPRE 1:1
APLLFBD1 = $C8
APLLDIV1 = $42          ' APOST1DIV 1:4, APOST2DIV 1:2, AVCODIV FVCO/4*)

Write_OSCCON($0301)
While OSCCONbits_OSWEN <> 0 : Wend      ' Wait for the clock switch to occur
While OSCCONbits_LOCK <> 1 : Wend       ' Wait for the oscillator to lock


EndProc
       
       

top204

#7
In the hurry to reply, I had forgotten to add the start address of XRAM to the end address of YRAM in the post.

I have just made some changes to the "FFT_Magnitude.bas" demo code listing, for a dsPIC33CK128MP202 device, so I could see if it was resetting, and it is not resetting, and it is going through the DSP process OK. I included the "Traps.inc" file, to see if it was causing an exception and it is not.

As soon as I get some time, I will re-arrange the DSP demo codes for dsPIC33Cx and dsPIC33Ex devices, because the newer dsPIC33 device peripherals are different to the original ones that the demos were created for, all of those years ago.

To see if the program is causing an exception, include the "Traps.inc" file into your code listing, and see the reason why on a serial terminal. Also, look in the device's datasheet and see what other exception traps it has, in case it is a DSP exception happening with your device.

Regards
Les

Wimax

#8
Thank you very much Les for your answer.
I tried to understand the cause of the reset. If I call "FFT_BitReverseComplex", there are no problems.
The cause was in "FFT_ComplexIP".
In particular, after analyzing the assembler, I noticed that
$ifdef _dsPIC33CK
    Nop
$endif
does not generate the corresponding Nop. By inserting the Nops directly after the "mDo" macro, the code now runs without resetting. I am trying to understand if the results are correct.

I look forward to hearing from you soon  ;D