Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: src/lut.cpp
- Revision:
- 6:39442d493098
- Parent:
- 5:09be5bbb5020
- Child:
- 7:860b3a8275cb
--- a/src/lut.cpp Sat Dec 01 00:08:53 2018 +0000 +++ b/src/lut.cpp Mon Dec 03 01:03:14 2018 +0000 @@ -28,51 +28,65 @@ #include "mbed.h" #include "stdint.h" +#include "globals.h" #include "lut.h" //unsigned int binCode[6]; #define MAX_LUT_ENTRIES 1024 -uint8_t binC[MAX_LUT_ENTRIES]{ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19}; -uint8_t thermC[MAX_LUT_ENTRIES]{ 0, 0, 1, 1, 2, 2, 3, 3, 4, 5}; +uint8_t binC[MAX_LUT_ENTRIES] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19}; +uint8_t thermC[MAX_LUT_ENTRIES]{ 0, 0, 1, 1, 2, 2, 3, 3, 4, 5}; -void dec2bin(int dec){ - +/******************************************************************************* +dec2bin_fix - Converts decimal to binary with fixed width as specified. +*******************************************************************************/ +void dec2bin_fix(unsigned int dec, unsigned int n){ int k; - int n=5; - for (int c = 5; c >= 0; c--) - { + for (int c = 5; c >= 0; c--){ k = dec >> c; - if (k & 1) binCode[n] = 1; else binCode[n] = 0; - n--; } } - -void dec2therm(int dec){ - - for (int i = 0; i <= 16; i++) - { +/******************************************************************************* +dec2therm_fix - Converts decimal to thermometer code with fixed width as specified. +*******************************************************************************/ +void dec2therm_fix(unsigned int dec, unsigned int n){ + for (int i = 0; i <= n; i++){ thermCode[i] = 0; } - for (int i = 0; i <= dec; i++) - { + for (int i = 0; i <= dec; i++){ thermCode[i] = 1; } +} + +/******************************************************************************* +getLUTcode - gets output codes from LUT using row reference. +*******************************************************************************/ +void getLUTcode(unsigned short row){ + + dec2bin_fix(binC[row], (unsigned int)WEIGHT_BIN_WIDTH); + dec2therm_fix(thermC[row], (unsigned int)BOARDS_THERMCODE_WIDTH); } -void getLUTcode(int row){ - - dec2bin(binC[row]); - dec2therm(thermC[row]); +/******************************************************************************* +getLUT_binCode - gets output codes from LUT using row reference. +*******************************************************************************/ +unsigned int getLUT_binCode(unsigned short row){ + return binC[row]; +} +/******************************************************************************* +getLUT_binCode - gets output codes from LUT using row reference. +*******************************************************************************/ +unsigned int getLUT_thermCode(unsigned short row){ + return thermC[row]; } \ No newline at end of file