Lab 3 part 4 – Option 2

 

You can complete either the original part 4 or the new part 4. The original part 4 requires you to calibrate to match the output of the example display by interpolating values experimentally. The new part 4 (option 2) eliminates the problem of matching to actual light meter but replaces it with a simple way of dynamically calibrating.

Objective:

Read the analog value coming from the photoresistor. The values may not swing all the way from 0 to 0xff, but you will calibrate it to match the light scale listed in Step 2. One of your buttons should toggle between the raw ADC output displayed in hex (8 msbs), and the scaled Weston light meter units. The other button should toggle you through a state machine that allows you to calibrate a minimum light level and a maximum light level.

Steps:

 

1.     Build a state machine using button 1. The first button push displays "LO" in hex display to indicate the system is ready to calibrate the low light point. The second button push captures the low calibration point, and displays "HI", indicating it’s ready to capture the high calibration point. The third push of the button captures the high calibration setting, and switches to calibrated display mode. Button 2 toggles between raw data and calibrated/scaled data.

2.     Implement a lookup table with the following values so they are displayed on your 7-segment LED display. The values in this table should the only values displayed when in calibrated/scaled data. Values of the calibrated scale:

 

0.1       Min. value

0.2

0.3

0.4

0.6

0.8

1.2

1.6

2.4

3.2

4.9

6.5

9.5

13

19

25

38

50

75

99        Max. value

 

3.     Write a function to scale the ADC data bounded by the calibrated range (Step 1) to the table of values in Step 2. From the maximum and minimum values obtained during the calibration (Step 1) a range of reading values is established (possible examples are 5-200, 51-98, 110-114, 215-255, etc). A conversion should automatically occur that will take the raw ADC values and output the calibrated values in Step 2 based off the calibration from Step 1.  Here are the specifics:

 

4.     If values are noisy, average 8 or 16 readings.

 

Hint:

            Scaling should be simple:

 

                ADC value - Min Value      Index of output value
                ------------------------------- = ------------------------------
                Range (Max - Min)              Size of Light Scale
 

            Do not use floating point math!

Deliverables:

  1. Demonstrate your light meter to a TA.
  2. Turn in a hardcopy of your C code