FFT on DSPIC

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
yannr
Posts: 22
Joined: Thu Oct 06, 2011 9:43 am
Has thanked: 9 times
Been thanked: 1 time
Contact:

FFT on DSPIC

Post by yannr »

Hello Everybody,

I make a new post on FFT used on DSPIC.

I am user of matrix multimedia product and teacher in an engineer School in France : INSA LYON.
I work with my students on fantastic projects:
https://www.youtube.com/user/yricotti
My students and I have so discovered electronic...

In a New project, We try to make a car that can be controled by brain for disability problem.
We need to make FFT, on DSpic 30F3014. We work on this project
with St Etienne Hospital and a research laboratory (INL).

I Have tried the new DSP component on a DSPIC 30F3014, with flowcode V5.5.2.1 for Pic 24 and DsPIC,
all the exemple on DSP componants works well but not the 10th exemple called : 10. Frequency Analysis using FFT.fcf_pic16
The only one that I want to use.

I have tried to find the problem with my file in attachment (test13e.fcf_pic16) by adding more and more
components of 10. Frequency Analysis using FFT.fcf_pic16
and in fact it's the ReadSingleBank_FFT that produce the following problem:

G:\yann\OT\datasheet_matrix_et_autre\DS_pic\test DSP>pic30-gcc -c -mcpu=30F3014 -funsigned-char -fno-short-double -Os -I"C:\PROGRA~2\FLOWCO~1\v5\Tools\MX_bats\..\C_tools\support\h" -I"C:\PROGRA~2\FLOWCO~1\v5\Tools\MX_bats\..\MX_support" -Wall -std=gnu99 "test13e".c -o "test13e".o
test13e.c: In function 'FCD_ADC0_ReadAsString':
test13e.c:2070: warning: pointer targets in passing argument 3 of 'FCI_FLOAT_TO_STRING' differ in signedness
test13e.c: In function 'FCD_DSP_Abs0_ReadPeak':
test13e.c:2294: error: 'DSP_Abs_13_LEVEL_PEAK_RECORD' undeclared (first use in this function)
test13e.c:2294: error: (Each undeclared identifier is reported only once
test13e.c:2294: error: for each function it appears in.)
test13e.c:2294: error: 'Peak_Idx' undeclared (first use in this function)
test13e.c:2301: error: 'DSP_Abs_13_LEVEL_RECORD' undeclared (first use in this function)
test13e.c: In function 'FCD_DSP_Abs0_ReadTrough':
test13e.c:2341: error: 'DSP_Abs_13_LEVEL_TRGH_RECORD' undeclared (first use in this function)
test13e.c:2341: error: 'Trgh_Idx' undeclared (first use in this function)
test13e.c: In function 'FCD_DSP_Abs0_ReadAverage':
test13e.c:2375: error: 'DSP_Abs_13_SAMPLE_SIZE' undeclared (first use in this function)
test13e.c:2389: error: 'DSP_Abs_13_LEVEL_AVRG_RECORD' undeclared (first use in this function)
test13e.c:2389: error: 'Avrg_Idx' undeclared (first use in this function)
test13e.c: In function 'FCD_DSP_Abs0_ReadPeak_Tick':
test13e.c:2433: error: 'DSP_Abs_13_LEVEL_PEAK_RECORD' undeclared (first use in this function)
test13e.c:2433: error: 'Peak_Idx' undeclared (first use in this function)
test13e.c: In function 'FCD_DSP_Abs0_ReadTrough_Tick':
test13e.c:2473: error: 'DSP_Abs_13_LEVEL_TRGH_RECORD' undeclared (first use in this function)
test13e.c:2473: error: 'Trgh_Idx' undeclared (first use in this function)
test13e.c: In function 'FCD_DSP_Abs0_ReadAverage_Tick':
test13e.c:2512: error: 'DSP_Abs_13_LEVEL_AVRG_RECORD' undeclared (first use in this function)
test13e.c:2512: error: 'Avrg_Idx' undeclared (first use in this function)
test13e.c: In function 'FCD_DSP_Abs0_ReadSingleBank_FFT':
test13e.c:2569: warning: comparison is always true due to limited range of data type
test13e.c: In function 'FCM_timer_tick':
test13e.c:2742: warning: pointer targets in passing argument 1 of 'FCD_DSP_Input0_Add_To_Buffer' differ in signedness
test13e.c: In function 'main':
test13e.c:2776: warning: pointer targets in passing argument 1 of 'FCD_LCDDisplay0_PrintString' differ in signedness
test13e.c:2869:3: warning: #warning "This interrupt has previously been enabled, so the macro <timer_tick> may never get called."

Error returned from [pic30-gcc.exe].

Can somebody explain me how I can Handle the problem?

YannR
Attachments
test13e.fcf_pic16
(19.19 KiB) Downloaded 354 times
Regards
INSA 1er cycle GCP projects with or without eblocks:
https://www.youtube.com/user/yricotti

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC=can't be used

Post by benp »

Why don't we have an answer from matrix staff?
There is no working example for FFT.
The other DSP examples compile properly but not this one.
The yannr example can compile if you remove "ReadSingleBank_FFT" but not if you disable icon. That's very strange...

Thank you Yannr. I think that's a good idea to do a specific topic on FFT.
No answer were given here:
http://www.matrixmultimedia.com/mmforum ... =25#p45619
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FFT on DSPIC

Post by Benj »

Hello,

I will have a look and see if I can resolve the error for you, it certainly was compiling on my system before the examples were released.

I have been able to replicate the issue so please bear with me and I should have something working for you this afternoon.

yannr
Posts: 22
Joined: Thu Oct 06, 2011 9:43 am
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: FFT on DSPIC

Post by yannr »

We trust in you Benj !

:wink:

thanks,

Yann
Regards
INSA 1er cycle GCP projects with or without eblocks:
https://www.youtube.com/user/yricotti

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FFT on DSPIC

Post by Benj »

Hello,

This updated component C file should resolve the issue.
FC5_PIC16BIT_DSP_Abs.c
(14.15 KiB) Downloaded 371 times
FC5_PIC_DSP_Abs.c
(14.15 KiB) Downloaded 347 times
FC5_AVR_DSP_Abs.c
(14.15 KiB) Downloaded 365 times
FC5_ARM_DSP_Abs.c
(14.15 KiB) Downloaded 350 times

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC

Post by benp »

Thank you benj
The example now compile on Flowcode for DSPIC(except the "Add_To_Buffer(data)" which need to be changed to string).
Yannr, did you test this on the dsPIC board?
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

yannr
Posts: 22
Joined: Thu Oct 06, 2011 9:43 am
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: FFT on DSPIC

Post by yannr »

thanks Benj for your work, now I can compile my FFT program.
but the result is not good.

I make a sinus signal of 25 Hz from 0v to 5v.
I do a sample of 183 Hz on 32 sample taken.

and after the FFT in the result in frequencie
in level data I read always in frequencies domain
5hz, 1
11Hz, 2
17Hz, 2
22Hz, 3
28Hz, 3
34Hz, 4
39Hz, 4
45Hz, 4
51Hz, 4
57Hz, 4
62Hz, 3
68Hz, 3
74 Hz, 2
79 Hz, 2
85Hz, 1

More interesting if i disconnect the wire of the sinus signal I have exactly the same result...It's not depending of the input Data!!!

If you have an idea that I can test I put my file with my post.

thanks,

Yann
Attachments
test15e.fcf_pic16
(21.41 KiB) Downloaded 330 times
Regards
INSA 1er cycle GCP projects with or without eblocks:
https://www.youtube.com/user/yricotti

yannr
Posts: 22
Joined: Thu Oct 06, 2011 9:43 am
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: FFT on DSPIC

Post by yannr »

OK there was an other problem in the example,
It seems better to use ADD_Raw_Tick as Add_To_Buffer,
because we use a _Tick method

Now if I put 5V at the input, after the FFT, for all the frequencies I have always 0.
It's better.

but with an 5.2 HZ sinus signal input, when I sample at 45Hz, the results are still not good. It appears harmonic that doesn't exist

I put my file under.
Attachments
test15g.fcf_pic16
(21.63 KiB) Downloaded 319 times
Regards
INSA 1er cycle GCP projects with or without eblocks:
https://www.youtube.com/user/yricotti

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FFT on DSPIC

Post by Benj »

Hello,

For FFT to work nicely you really need to be using at least 16-bit readings with 16-bit FFT look up values.

The 16-bit readings must use a signed variable type so the signal can go positive and negative, the mid point for the signal has to be 0V.

You should be able to play around with the settings in the DSP System component to get this working a bit nicer.

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC

Post by benp »

This one with virtual analog signal work properly:
test15gbenv03.fcf_pic16
virtual analog signal
(21.99 KiB) Downloaded 315 times
This is a calculated signal from the sin(teta).
You can change the period with div in constants.

YannR performed tests with true analog signal. He will post his results as soon as available.
The 32 bit size buffer is really too small for FFT. Benj, is it possible to increase the buffer size?
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

yannr
Posts: 22
Joined: Thu Oct 06, 2011 9:43 am
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: FFT on DSPIC

Post by yannr »

With the test made by benp, my old program test15g.fcf_pic16 is working now.
The problem was that my sinus signal was sometimes minus that O and the analogic acquisition was truncated. It's good from 5 Hz to 13Hz. It's better when the signal is >0 and <5V.

The problem now is that 32 values for the buffer, it's too short to scan a large value of frequencies. It would be great to have 64 or 128 values (256 if the buffer is enough big).

can Matrix do the job?
We can make the beta test.

thanks,

YannR
Regards
INSA 1er cycle GCP projects with or without eblocks:
https://www.youtube.com/user/yricotti

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC

Post by benp »

Is it possible to do a 256 buffer-16bits=512 bytes?
For a 30F3014, SRAM=2048.
This mean 3 buffers and 512 bytes for extra datas.
30F6014 have SRAM=8192 so a 512 byte should be possible(it is 80 tqfp I know).

Can the matrix staff do that because a 32bytes buffer is really too short to be used in most applications
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: FFT on DSPIC

Post by kersing »

It is very simple to change the buffer size. Open the ext(ended) properties of the component, select one of the buffers and type the required length in the length box. The drop down does not show sizes above 32, but typing allows entering a larger value. Just make sure it is a power of 2.

Next place the attached file in the Component directory of your Flowcode installation, replacing the original file. (Somehow 256 [=2^8] has been skipped which results in errors for buffers over 128 bytes)

For everyone not using the 16 bit PICS, to fix the issue, edit the corresponding file (file name end in_DSP_FFT.c). Find:

Code: Select all

#if(%a_INPUT_BUFFER_LEN == 128)
    #define %a_FFT_SAMPLE_POWER     7
#endif
#if(%a_INPUT_BUFFER_LEN == 512)
    #define %a_FFT_SAMPLE_POWER     8
#endif
#if(%a_INPUT_BUFFER_LEN == 1024)
    #define %a_FFT_SAMPLE_POWER    9
#endif
#if(%a_INPUT_BUFFER_LEN == 2048)
    #define %a_FFT_SAMPLE_POWER    10
#endif
#if(%a_INPUT_BUFFER_LEN == 4096)
    #define %a_FFT_SAMPLE_POWER    11
#endif
Replace with:

Code: Select all

#if(%a_INPUT_BUFFER_LEN == 128)
    #define %a_FFT_SAMPLE_POWER     7
#endif
#if(%a_INPUT_BUFFER_LEN == 256)
    #define %a_FFT_SAMPLE_POWER     8
#endif
#if(%a_INPUT_BUFFER_LEN == 512)
    #define %a_FFT_SAMPLE_POWER     9
#endif
#if(%a_INPUT_BUFFER_LEN == 1024)
    #define %a_FFT_SAMPLE_POWER    10
#endif
#if(%a_INPUT_BUFFER_LEN == 2048)
    #define %a_FFT_SAMPLE_POWER    11
#endif
#if(%a_INPUT_BUFFER_LEN == 4096)
    #define %a_FFT_SAMPLE_POWER    12
#endif
Attachments
FC5_PIC16BIT_DSP_FFT.c
(6.04 KiB) Downloaded 225 times
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: FFT on DSPIC

Post by kersing »

The file posted earlier in this thread with buffer size of 256. Requires the update to the FC5_PIC16BIT_DSP_FFT.c file!
Attachments
test15gbenv03.fcf_pic16
(22 KiB) Downloaded 223 times
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

yannr
Posts: 22
Joined: Thu Oct 06, 2011 9:43 am
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: FFT on DSPIC

Post by yannr »

thank you for your answer on how to increase the buffer value to 256.
Now it works better.
My input signal is a sinus from 1000 to 3000 because of my 12-bit Analog-to-Digital Converter (A/D) (0 to 4096)
What I don't understand, it's that the output value of my FFT is really weak: for the main frequencie it's maximum 15, the other are around O or 1.
My output Level value is now an integer and could be from (-32768 to 32767) !!

How is made the number that we have after a REadSingleBankFFT?
Why the frequency bank signal level is so Weak?
Regards
INSA 1er cycle GCP projects with or without eblocks:
https://www.youtube.com/user/yricotti

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FFT on DSPIC

Post by Benj »

Hello,

The FFT should be producing these kinds of signal levels.

8-bit signal - the peak output is 127 so the peak FFT response is SQRT(127) or 11.
16-bit signal - the peak output is 32767 so the peak FFT response is SQRT(32767) or 181.

Therefore you should really be getting bigger signals out of the FFT.

I wonder is the signal equal on both the positive and negative ranges or you may get more cancelling out then you are expecting.

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC

Post by benp »

We can't have more than 15 level.

Here is a test program with a virtual signal input:
test15gbenglcdv06.fcf_pic16
(22.38 KiB) Downloaded 232 times
The input signal is made with:
entre1 = 32000 * sin (teta)

The max level from the FFT sould be:
sqr(32000)=179

The max level is 15.
Bank Leval
0 15
1 0
2 0
3 0
4 0
5 1
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0

I think there is an integer to byte somewhere because sqr(256)=16.

I don't know if this come from my flowcode program or from matrix fft.

Can you give a working example with virtual signal and max fft output?
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

yannr
Posts: 22
Joined: Thu Oct 06, 2011 9:43 am
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: FFT on DSPIC

Post by yannr »

Hi,

Sorry, but we really need some help.
where can we modify the Matrix program to have a real maxi level of
16-bit signal - SQRT(32767) or 181, in order to have something Workable?
thanks,

Yann
Regards
INSA 1er cycle GCP projects with or without eblocks:
https://www.youtube.com/user/yricotti

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC

Post by benp »

Still no news from the matrix team.
Can you provide a working flowcode example with a virtual signal(see my last post).
I believe in a bug which don't allow a greater than 16 signal.

We will a to switch to a homemade FFT in a very short time(with no DSP component inside).
Our prototypes could be good DSP demonstrators if you help us to implement DSP components.
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FFT on DSPIC

Post by Benj »

Hi Ben,

The DSP components were added to v5 in a bit of a rush so i'm not all that surprised there are issues. I tested the code well but then it was taken out of my hands towards the end of development so I didn't really get a say in what was happening. Lots got changed last minute so it's hard for me to pinpoint exactly what the problems are.

Now the reasons behind adding the components to v5 were.

1) to try and bump up the features of v5
2) to try and get more stable code we could use for v6

I am pretty flat out with v6 development at the moment so lending a hand is tricky however I will try and help to iron out these bugs for you.

I suppose if I start working on the v6 DSP components then that might help me spot some of the problems.

So we are both on the same page here is a list of current issues with the DSP components.

1) FFT returning values which seem to be much lower then they should be.
2) Control - PI and PID have compile issues

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC

Post by benp »

Thank you Benj,

Can you give us which algorithme (the name) you use for the FFT.
Do you have the link you use for this?
We try to debug but it's hard because we don't know what you are doing...
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

benp
Posts: 155
Joined: Sat Mar 28, 2009 5:44 pm
Location: LYON FRANCE
Has thanked: 3 times
Been thanked: 41 times
Contact:

Re: FFT on DSPIC

Post by benp »

What is you Algorithm Benj?
Cooley–Tukey, Prime-factor FFT algorithm, Bruun's FFT algorithm, Rader's FFT algorithm, and Bluestein's FFT algorithm?
Can you give the links of what you use and maybe we can find the problem.
Regards
INSA 1er cycle GCP projects with or without eblocks:
http://www.youtube.com/user/INSAgcp

Post Reply