Comparing between 4 analogue inputs using MikcroC

Discussion in 'Embedded Systems and Microcontrollers' started by kamel2913, Mar 2, 2016.

  1. kamel2913

    Thread Starter New Member

    Mar 6, 2015
    15
    0
    Hello,

    I'm working on a project : solaire tracker, this projet have 4 light sensors, this 4 sensors has analogue outputs, my probleme is I couldn't figure out how to compare between the output voltage of this captors, for exemple, using MikcroC I want to know which gives more voltage and which gives low voltage, and how to compare and using conditions, for exemple if(cap1>cap2){do somthing}....(cap1= output voltage of the captor 1, cap2= output voltage of the captor 2)

    as I know for MikcroC, I can compare only digital outputs, so there's anyway that I can compare analgue output voltage?

    sorry for my English, thank you for your time.
     
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    1,828
    365
    1. Adc and then compare. Or
    2. Use the built-in analog comparator's.

    Both can be done by reading the data sheet.
     
    kamel2913 likes this.
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    What microcontroller are you using? As dannyf says, get one with a multi-channel ADC (even low cost PICs have one), read channels in sequence and store the values. Then look through the data to see which is most/least etc.
     
    kamel2913 likes this.
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,397
    497
    You have choices.

    Like others said, you can use microcontroller that has multiple analog to digital converters (ADC). This is a digital approach. You will take analog values, digitize them, the let software loaded into the microcontroller do the comparing. Arduino works pretty well for this and there is nice tutorials on how to use ADC on Arduino boards.

    Side note. Make sure output of the light sensor is withing acceptable range of the ADC input. You don't want to send 10 volts from light sensor to 5volt ADC.
     
    kamel2913 likes this.
  5. kamel2913

    Thread Starter New Member

    Mar 6, 2015
    15
    0
    thank you guys for your replies, I'm using PIC16F877A, do I have to write any instructions in my code to active the ADCs ports?
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    Of course you do. MikroC provides library routines for the ADC. Read up and have at it. Be sure to read the PIC datasheet sections on configuring the ADC particularly ADCON0, ADCON1 and the TRIS registers for your input pins.

    If you need help, post a schematic and your code and describe any problems you are having.

    Good luck.
     
    Last edited: Mar 3, 2016
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Given the time, the date, and your location the position of the sun is a known quantity. Mariners have used this fact for hundreds of years to back figure where they are. If you compute the position of the sun you eliminate the sensors and several other sources of error, like clouds, like chasing the sun after it set, cloud cover, and others.

    You would have to calibrate the array position on occasion, as you would anyway with your sensors.
     
  8. dannyf

    Well-Known Member

    Sep 13, 2015
    1,828
    365
    Two 555 timers (=1 556) + 4 ldrs will do the job just fine. Zero programming needed.
     
  9. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,397
    497
Loading...