Scaled gamma 1.3 table to cover whole power range.

Now the example shows the difference between different gamma approaches.
This commit is contained in:
Piotr Esden-Tempski 2010-02-22 13:59:51 +01:00
parent 002ec200ad
commit c713c02e9d

View File

@ -21,6 +21,8 @@
#include <libopenstm32/gpio.h>
#include <libopenstm32/timer.h>
#define GAMMA_LINEAR
#define GAMMA_1_3
#define GAMMA_3_0
/*
@ -29,8 +31,8 @@
* The nonlinear tables are calculating with the function:
* Iout = Iin ** gamma
*/
static const uint16_t gamma_table[] = {
#ifdef GAMMA_LINEAR
static const uint16_t gamma_table_linear[] = {
1, 4, 9, 17, 26, 37, 51, 67,
84, 104, 126, 149, 175, 203, 233, 265,
299, 334, 372, 412, 454, 499, 545, 593,
@ -63,43 +65,49 @@ static const uint16_t gamma_table[] = {
54351, 54816, 55282, 55751, 56222, 56694, 57169, 57645,
58123, 58604, 59086, 59570, 60057, 60545, 61035, 61527,
62021, 62517, 63016, 63516, 64018, 64521, 65027, 65535
#else
};
#endif
#ifdef GAMMA_1_3
static const uint16_t gamma_table_1_3[] = {
// Gamma 1.3
0, 1, 2, 4, 6, 8, 10, 13,
15, 17, 20, 23, 25, 28, 31, 34,
37, 40, 43, 46, 49, 52, 56, 59,
62, 66, 69, 73, 76, 80, 83, 87,
91, 94, 98, 102, 105, 109, 113, 117,
121, 125, 129, 133, 137, 141, 145, 149,
153, 157, 162, 166, 170, 174, 179, 183,
187, 192, 196, 200, 205, 209, 214, 218,
223, 227, 232, 237, 241, 246, 250, 255,
260, 264, 269, 274, 279, 283, 288, 293,
298, 303, 308, 312, 317, 322, 327, 332,
337, 342, 347, 352, 357, 362, 367, 372,
378, 383, 388, 393, 398, 403, 408, 414,
419, 424, 429, 435, 440, 445, 451, 456,
461, 467, 472, 477, 483, 488, 494, 499,
505, 510, 516, 521, 527, 532, 538, 543,
549, 554, 560, 566, 571, 577, 582, 588,
594, 599, 605, 611, 617, 622, 628, 634,
640, 645, 651, 657, 663, 669, 674, 680,
686, 692, 698, 704, 710, 716, 722, 727,
733, 739, 745, 751, 757, 763, 769, 775,
781, 788, 794, 800, 806, 812, 818, 824,
830, 836, 842, 849, 855, 861, 867, 873,
880, 886, 892, 898, 904, 911, 917, 923,
930, 936, 942, 949, 955, 961, 968, 974,
980, 987, 993, 999, 1006, 1012, 1019, 1025,
1032, 1038, 1044, 1051, 1057, 1064, 1070, 1077,
1083, 1090, 1096, 1103, 1110, 1116, 1123, 1129,
1136, 1142, 1149, 1156, 1162, 1169, 1176, 1182,
1189, 1196, 1202, 1209, 1216, 1222, 1229, 1236,
1242, 1249, 1256, 1263, 1269, 1276, 1283, 1290,
1297, 1303, 1310, 1317, 1324, 1331, 1337, 1344
#else
0, 49, 120, 203, 296, 395, 501, 612,
728, 848, 973, 1101, 1233, 1368, 1506, 1648,
1792, 1939, 2088, 2241, 2395, 2552, 2711, 2872,
3036, 3201, 3369, 3538, 3709, 3882, 4057, 4234,
4412, 4592, 4774, 4957, 5142, 5329, 5517, 5706,
5897, 6090, 6283, 6479, 6675, 6873, 7072, 7273,
7475, 7678, 7882, 8088, 8294, 8502, 8711, 8922,
9133, 9346, 9559, 9774, 9990, 10207, 10425, 10644,
10864, 11086, 11308, 11531, 11755, 11981, 12207, 12434,
12662, 12891, 13121, 13352, 13584, 13817, 14051, 14285,
14521, 14757, 14994, 15233, 15472, 15712, 15952, 16194,
16436, 16679, 16923, 17168, 17414, 17660, 17908, 18156,
18405, 18654, 18905, 19156, 19408, 19660, 19914, 20168,
20423, 20679, 20935, 21192, 21450, 21708, 21968, 22228,
22488, 22750, 23012, 23275, 23538, 23802, 24067, 24332,
24599, 24865, 25133, 25401, 25670, 25939, 26209, 26480,
26751, 27023, 27296, 27569, 27843, 28118, 28393, 28669,
28945, 29222, 29500, 29778, 30057, 30336, 30616, 30897,
31178, 31460, 31742, 32025, 32308, 32592, 32877, 33162,
33448, 33734, 34021, 34309, 34597, 34885, 35175, 35464,
35754, 36045, 36337, 36628, 36921, 37214, 37507, 37801,
38096, 38391, 38686, 38982, 39279, 39576, 39874, 40172,
40471, 40770, 41070, 41370, 41670, 41972, 42273, 42576,
42878, 43181, 43485, 43789, 44094, 44399, 44705, 45011,
45317, 45625, 45932, 46240, 46549, 46858, 47167, 47477,
47787, 48098, 48409, 48721, 49034, 49346, 49659, 49973,
50287, 50602, 50917, 51232, 51548, 51864, 52181, 52498,
52816, 53134, 53452, 53771, 54091, 54411, 54731, 55052,
55373, 55694, 56016, 56339, 56662, 56985, 57309, 57633,
57957, 58282, 58608, 58933, 59260, 59586, 59913, 60241,
60569, 60897, 61226, 61555, 61884, 62214, 62545, 62875,
63206, 63538, 63870, 64202, 64535, 64868, 65201, 65535
};
#endif
#ifdef GAMMA_3_0
static const uint16_t gamma_table_3_0[] = {
// gamma = 3.0014
0, 1, 4, 9, 16, 25, 36, 49,
64, 81, 100, 121, 145, 170, 197, 226,
@ -133,15 +141,13 @@ static const uint16_t gamma_table[] = {
54236, 54705, 55176, 55649, 56124, 56601, 57080, 57561,
58044, 58529, 59016, 59505, 59996, 60489, 60984, 61481,
61981, 62482, 62985, 63490, 63998, 64507, 65018, 65531
#endif
#endif
#endif
};
#endif
/* Set STM32 to 72 MHz. */
void clock_setup(void)
{
/* Select HSI as SYSCLK source. */
/* Select HSI as SYSCLK source. */
rcc_set_sysclk_source(SW_SYSCLKSEL_HSICLK);
/* Set the PLL multiplication factor to 9. */
@ -159,10 +165,10 @@ void clock_setup(void)
/* Select PLL as SYSCLK source. */
rcc_set_sysclk_source(SW_SYSCLKSEL_PLLCLK);
/* Enable TIM3 clock. */
/* Enable TIM3 clock. */
rcc_peripheral_enable_clock(&RCC_APB1ENR, TIM3EN);
/* Enable GPIOC, Alternate Function clocks. */
/* Enable GPIOC, Alternate Function clocks. */
rcc_peripheral_enable_clock(&RCC_APB2ENR, IOPCEN | AFIOEN);
}
@ -256,31 +262,31 @@ int main(void)
clock_setup();
gpio_setup();
tim_setup();
tim_setup();
j0=0;
d0=1;
j1=64;
j1=0;
d1=1;
j2=128;
j2=0;
d2=1;
j3=192;
j3=128;
d3=1;
while (1)
{
TIM3_CCR1= gamma_table[j0];
TIM3_CCR1= gamma_table_linear[j0];
j0+=d0;
if(j0==255) d0=-1;
if(j0==0) d0=1;
TIM3_CCR2= gamma_table[j1];
TIM3_CCR2= gamma_table_1_3[j1];
j1+=d1;
if(j1==255) d1=-1;
if(j1==0) d1=1;
TIM3_CCR3= gamma_table[j2];
TIM3_CCR3= gamma_table_3_0[j2];
j2+=d2;
if(j2==255) d2=-1;
if(j2==0) d2=1;
TIM3_CCR4= gamma_table[j3];
TIM3_CCR4= gamma_table_3_0[j3];
j3+=d3;
if(j3==255) d3=-1;
if(j3==0) d3=1;