Getting Started

(lily) #1

Chapter 9 – Digital Meets Analog – ADC and DAC


how the ADC value translates to light intensity’. I have no idea what the data
means other than the amount of light is inversely proportional to the data sent
back, just like it is supposed to be. I guess we could try to calibrate it in Lumens,
or furlongs or something... nah, Let’s move on.


Temperature Meter


We will measure the temperature in Fahrenheit and use an array of constants to
convert the value from a voltage to a temperature. The table is from the Butterfly
code.


// Positive Fahrenheit temperatures (ADC-value)
const int TEMP_Fahrenheit_pos[] PROGMEM =
{ // from 0 to 140 degrees
938, 935, 932, 929, 926, 923, 920, 916, 913, 909, 906, 902,
898, 894, 891, 887, 882, 878, 874, 870, 865, 861, 856, 851,
847, 842, 837, 832, 827, 822, 816, 811, 806, 800, 795, 789,
783, 778, 772, 766, 760, 754, 748, 742, 735, 729, 723, 716,
710, 703, 697, 690, 684, 677, 670, 663, 657, 650, 643, 636,
629, 622, 616, 609, 602, 595, 588, 581, 574, 567, 560, 553,
546, 539, 533, 526, 519, 512, 505, 498, 492, 485, 478, 472,
465, 459, 452, 446, 439, 433, 426, 420, 414, 408, 402, 396,
390, 384, 378, 372, 366, 360, 355, 349, 344, 338, 333, 327,
322, 317, 312, 307, 302, 297, 292, 287, 282, 277, 273, 268,
264, 259, 255, 251, 246, 242, 238, 234, 230, 226, 222, 219,
215, 211, 207, 204, 200, 197, 194, 190, 187,
};


void getTemperature()
{
char fahr[]= {'0','0','0','\0'};


int ADCresult = 0;


// Initialize the ADC to the temperature sensor channel

and reads
e program space with a 16-bit (near) address,

int i = 0;

//ADC_init(0);
ADMUX = 0;//input;


ADCresult = ADC_read();


/* The pgm_read_word() function is part of WinAVR
a word from th
Free download pdf