0

I had a project that requires to measure illuminance(lux) using LDR and display the result on LCD. Thanks to some references from Google, I had managed to build a equation that shows relation between Lux and LDR's resistance which is: L = 1,48.(10^7).R^(-1,43)

ADC input is voltage divider of LDR( as image showed below) enter image description here

The equation above could be described by the following equation: enter image description here

Cause I'm using PIC18F with 10bit of ADC resolution and the reference voltage used is 5v so resolution of ADC module should be 4.88mV. Thus, I can get ADC value stored in ADRESH and ADREL to multiple with ADC resolution for achieving Vadc at the input as well as value of illuminance. So the questions are:

  1. I found some sources said that the value in ADRESH and ADRESL should be combined to a 16 bit registor by multiplying ADRESH with 256 then add them with ADRESL. But where will the result be stored when all of registers in PIC are 8 bit length?
  2. Suppose that the first problem was solved, the next one is how to implement the complicated equation above in assembly language. It is too tough for me! :))
  3. If the first two questions have been handled, an another problem arise when we display the final result on LCD( it's definitely a float number). How can we do that?

I appologize for asking so many questions in a post but you know, I always think it out before posting anything here and these question did make me headache for days. I will really appreciate for your help. Thank you.

Thanh Nhon
  • 51
  • 9
  • 1
    Sorry, but this is too broad and in too many sub-parts to belong here. Given you only have 1024 distinct input values you might consider a lookup table or a smaller table and interpolation - spend some time playing with possibilities in a spreadsheet. Converting a floating point number to text and displaying it are problems you will have to approach step by step. Consider using another language and perhaps desktop computer first to work out the operations and then re-write in assembly. – Chris Stratton May 22 '20 at 04:09
  • 1
    There is a free version (unoptimized) of C you can download for that processor, but I think you’d be better to pre-compute the values for each ADC reading, as @Chris suggests, which would also give you some insight into possible resolution issues. For display you can use C functions, someone else’s library, or write your own, there is nothing complicated about it, just a bit tedious to do in assembly. – Spehro Pefhany May 22 '20 at 05:12
  • I have already configured for ADC function and LCD display for PIC in assembly language. Howerver, I'm stuck in next step because I don't know how to deal with collected data to get expected result from the specified equation. – Thanh Nhon May 22 '20 at 13:46
  • https://en.wikipedia.org/wiki/Lookup_table – Chris Stratton May 22 '20 at 14:21

0 Answers0