EmbDev.net

Forum: ARM programming with GCC/GNU tools Lookup Table doesnt work


von Lea (Guest)


Rate this post
useful
not useful
Hi All,

i am currently reading different adc values fromm a Atmega32. The ADC 
Value should ne used to look into a LUT and then display the Result out 
of the Table via RS232.

The Table looks like


//********************************************************************** 
*********************************************************
// NTC Tabelle
unsigned long 
ntctable[911]={525,427,380,350,329,313,300,289,279,271,264,258,252,247,2 
42,
238,234,230,227,223,220,217,215,212,209,207,205,203,201,199,197,195,193, 
192,190,188,187,185,184,
182,181,180,179,177,176,175,174,173,172,171,170,169,168,167,166,165,164, 
163,162,161,160,160,159,
158,157,156,156,155,154,153,153,152,151,151,150,149,149,148,148,147,146, 
146,145,145,144,143,143,
142,142,141,141,140,140,139,139,138,138,137,137,136,136,135,135,134,134, 
134,133,133,132,132,131,
131,131,130,130,129,129,129,128,128,127,127,127,126,126,126,125,125,124, 
124,124,123,123,123,122,
122,122,121,121,121,120,120,120,119,119,119,119,118,118,118,117,117,117, 
116,116,116,116,115,115,
115,114,114,114,114,113,113,113,113,112,112,112,111,111,111,111,110,110, 
110,110,109,109,109,109,
108,108,108,108,107,107,107,107,107,106,106,106,106,105,105,105,105,104, 
104,104,104,104,103,103,
103,103,102,102,102,102,102,101,101,101,101,101,100,100,100,100,100,998, 
996,994,992,990,988,987,
985,983,981,979,977,975,973,971,969,967,966,964,962,960,958,956,954,953, 
951,949,947,945,944,942,
940,938,937,935,933,931,930,928,926,924,923,921,919,918,916,914,913,911, 
909,907,906,904,903,901,
899,898,896,894,893,891,890,888,886,885,883,882,880,878,877,875,874,872, 
871,869,868,866,864,863,
861,860,858,857,855,854,852,851,849,848,846,845,843,842,840,839,837,836, 
835,833,832,830,829,827,
826,824,823,822,820,819,817,816,815,813,812,810,809,808,806,805,803,802, 
801,799,798,797,795,794,
792,791,790,788,787,786,784,783,782,780,779,778,776,775,774,772,771,770, 
768,767,766,765,763,762,
761,759,758,757,756,754,753,752,750,749,748,747,745,744,743,742,740,739, 
738,736,735,734,733,732,
730,729,728,727,725,724,723,722,720,719,718,717,716,714,713,712,711,709, 
708,707,706,705,703,702,
701,700,699,697,696,695,694,693,691,690,689,688,687,686,684,683,682,681, 
680,679,677,676,675,674,
673,672,670,669,668,667,666,665,663,662,661,660,659,658,657,655,654,653, 
652,651,650,649,647,646,
645,644,643,642,641,640,638,637,636,635,634,633,632,631,629,628,627,626, 
625,624,623,622,621,619,
618,617,616,615,614,613,612,611,610,608,607,606,605,604,603,602,601,600, 
599,597,596,595,594,593,
592,591,590,589,588,587,585,584,583,582,581,580,579,578,577,576,575,574, 
572,571,570,569,568,567,
566,565,564,563,562,561,560,558,557,556,555,554,553,552,551,550,549,548, 
547,546,545,543,542,541,
540,539,538,537,536,535,534,533,532,531,530,528,527,526,525,524,523,522, 
521,520,519,518,517,516,
515,514,512,511,510,509,508,507,506,505,504,503,502,501,500,499,498,496, 
495,494,493,492,491,490,
489,488,487,486,485,484,483,482,480,479,478,477,476,475,474,473,472,471, 
470,469,468,467,465,464,
463,462,461,460,459,458,457,456,455,454,453,451,450,449,448,447,446,445, 
444,443,442,441,440,438,
437,436,435,434,433,432,431,430,429,428,426,425,424,423,422,421,420,419, 
418,417,415,414,413,412,
411,410,409,408,407,406,404,403,402,401,400,399,398,397,395,394,393,392, 
391,390,389,388,387,385,
384,383,382,381,380,379,377,376,375,374,373,372,371,369,368,367,366,365, 
364,362,361,360,359,358,
357,356,354,353,352,351,350,348,347,346,345,344,343,341,340,339,338,337, 
335,334,333,332,331,329,
328,327,326,325,323,322,321,320,318,317,316,315,314,312,311,310,309,307, 
306,305,304,302,301,300,
299,297,296,295,293,292,291,290,288,287,286,284,283,282,281,279,278,277, 
275,274,273,271,270,269,
267,266,265,263,262,261,259,258,257,255,254,252,251,250,248,247,246,244, 
243,241,240,239,237,236,
234,233,231,230,228,227,226,224,223,221,220,218,217,215,214,212,211,209, 
208,206,205,203,202,200,
199,197,195,194,192,191,189,188,186,184,183,181,180,178,176,175,173,171, 
170,168,166,165,163,161,
159,158,156,154,153,151,149,147,146,144,142,140,138,136,135,133,131,129, 
127,125,123,122,120,118,
116,114,112,110,108,106,104,102,100};

and the function the get the adcvalue :


uint16_t adcwert(uint8_t kanal)
{
  uint16_t wert = 0;                    //Variable für Ergebnis 
deklarieren

  ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);  //ADEN aktiviert 
überhaupt erst den internen ADC-Wandler, ADPS2 bis ADPS0 stellen den 
verwendeten Prescaler ein, denn die Wandlerfrequenz muss immer zwischen 
50 und 200 kHz liegen! Der Prescaler muss bei 16MHz also zwischen 80 und 
320 eingestellt werden, als einzige Möglichkeit bleibt hier 128 (=alle 
auf 1).

  ADMUX = kanal;
  //ADMUX = (1<<REFS1)|(1<<REFS0);            //Einstellen der 
Referenzspannung auf "extern", also REFS1 und REFS0 auf "0" - daher 
auskommentierte Zeile

  ADCSRA |= (1<<ADSC);                  //nach Aktivierung des ADC wird 
ein "Dummy-Readout" empfohlen, man liest also einen Wert und verwirft 
diesen, um den ADC "warmlaufen zu lassen"
    while(ADCSRA & (1<<ADSC)) {}              //auf Abschluss der 
Konvertierung warten
  wert = ADCW;                      //ADCW muss einmal gelesen werden, 
sonst wird Ergebnis der nächsten Wandlung nicht übernommen.

  /* Eigentliche Messung - Mittelwert aus 4 aufeinanderfolgenden 
Wandlungen */
  wert = 0;
  for(uint8_t i=0; i<4; i++)
  {
    ADCSRA |= (1<<ADSC);        //eine Wandlung "single conversion" 
starten
    while(ADCSRA & (1<<ADSC)) {}    //auf Abschluss der Konvertierung 
warten
    wert = wert + ADCW;            //Wandlungsergebnisse aufaddieren
    }

  ADCSRA &= ~(1<<ADEN);          //ADC deaktivieren

  wert = wert/4;              //Durchschnittswert bilden

  return wert;
}

the adcvalue call works fine with

analog=adcwert(i); //Messung Analogport [i]
utoa(analog, wort, 10);  sendUSART(wort);sendUSART("\r\n"); 
//Ausgabe:"[Analogwert] = "

but my call

sendUSART(ntctable[adcwert(i)]);


directing to the table doesnt show any result at all and i currently 
dont know whats wrong with it.

Anybody who can help me out ?

von Uwe .. (uwegw)


Rate this post
useful
not useful
The Mega32 has 2kBytes of SRAM. But your LUT has 911 entries of 4 Bytes 
= 3644 bytes, so it's much larger than the SRAM where it is stored...

You shold move the LUT into the Flash memory, and consider storing only 
a few values and interpolating the others. And the data type can be 
changed to int.

von Lea (Guest)


Rate this post
useful
not useful
I changed to long coz i thought that i needed 32bit values, but okay 
will change back to int.

How do i tell the Atmega to move the Table into the Flash memory using 
avrstudio ?

von HELPER (Guest)


Rate this post
useful
not useful
http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html

Read about
1) PROGMEM attribute
2) pgm_read_* funktions

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.