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?

  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – avra Apr 30 '15 at 11:46
  • \$\begingroup\$ 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. \$\endgroup\$ – Adeel Apr 30 '15 at 12:28
  • 1
    \$\begingroup\$ You might wish to investigate the use of higher-order interpolation, and/or wavelet interpolation to lower the size of the table. \$\endgroup\$ – 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[] = { ... };

  • \$\begingroup\$ With perfect coding, a table element occupies 14.288 bits (there's 9999*2+1 values). That's 89298 bytes of storage needed. More practically, you can store 103 values in 184 bytes, losing only 5% of one bit. That's 89321 bytes with a 184 byte codeword. \$\endgroup\$ – Kuba hasn't forgotten Monica Apr 30 '15 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.