# Is my lookup table with 50,000 entries too big for MCU memory (dsPIC33EP256MC506)?

I want to implement a 2-input 1-output fuzzy logic controller using lookup table on the dsPIC33EP256MC506 microcontroller. I am comparing the lookup table and actual fuzzy logic controller side by side in Simulink. In order to minimize the error between the lookup table and actual controller, I am having to generate a huge table, having around 50,000 entries. The input 1 range is -5000 to 5000, input 2 range is -1000 to 1000 and output range is -9999 to 9999. I am using Simulink code generation.

I went over the datasheet's memory section, but still need some expert guidance in relating the lookup table size to the program memory size. My questions are: how can I find out if this lookup table will fit into the program memory? How can I estimate the approximate size of the lookup table? What are key things to look for in datasheet or the lookup table from practical implementation viewpoint?

• Although lookup table would do it, implementing fuzzy controller in code would be much better and much more flash/ram friendly. Believe me, it's not that hard, and it would allow to change parameters without need to reflash whole lookup table each time you make changes. – avra Apr 30 '15 at 11:46
• I'm actually Simulink C-code generation feature, so not coding at all. However, the lookup table is generated through a combination of MATLAB code/fuzzy toolbox commands. – Adeel Apr 30 '15 at 12:28
• You might wish to investigate the use of higher-order interpolation, and/or wavelet interpolation to lower the size of the table. – Kuba hasn't forgotten Monica Apr 30 '15 at 15:19

You say your lookup table will contain 50000 elements and each element will have the range of -9999 to 9999. That means each element will need 16 bits (= 2 bytes) of memory. So the whole LUT will need 50000 x 2 bytes = 100000 bytes = aprox. 97.6 Kbytes.
Your microcontroller has 256 Kbytes of Flash memory and 32 Kbytes of RAM. So your program/Flash memory would be enough for the LUT. To place the table in program memory you need to declare it as const: const int16_t LUT[] = { ... };