Analog input to PIC16F877

Discussion in 'Embedded Systems and Microcontrollers' started by Reshma, Jan 30, 2008.

  1. Reshma

    Thread Starter Active Member

    Mar 11, 2007
    54
    0
    I have to give an analog light input to the ADC port of PIC16F877. I am wondering how do I connect the photo transistors. If the collector is pulled high and the emitter is grounded and the collector is connected to the port AN0 I will get a LOW signal as collector output whenever light shines on the Base. If I pull-down the resistor the output at the collector will be HIGH when light shines. I want to take to digital output of the photo transistor inputs. I think the latter connection is suitable...but will the pin overload?
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    If you are only in the ON and OFF state, using an ADC is not necessary. Configure a pin for input and just read it as a logic HIGH or LOW input.
     
  3. Reshma

    Thread Starter Active Member

    Mar 11, 2007
    54
    0
    OK, thanks! I figured out the problem. I want find the 8-bit digital output that I can get out of a PIC if I vary the light intensity on the phototransistor. I am making use of 2 phototransistors and I want to compare the intensity of light incident on both of them. I am working out a program on PIC for this. I just want to know if the phototransistor can give a varying analog outputs if I change the light intensity. I tested my transistor output levels on a voltmeter...I do get a variation if I increase/decrease the intensity but will the ADC module in the PIC be sensitive enough to detect the variations?
     
  4. sukumaar

    New Member

    Feb 11, 2008
    2
    0
    Hi,

    what is the voltage output from phototransistor ?
    Did you configure the ADC registers correctly?
    PIC will sense analog voltages excellently but try to amplify voltage if the sensor output is in mV.


    Regards,
    Sukumar
     
  5. Reshma

    Thread Starter Active Member

    Mar 11, 2007
    54
    0
    The voltage output of the phototransistor is 0-5V. Yes, I have configured the PIC ADC module correctly. I had even tested my program first by connecting a 10kohm potentiometer and the PIC gives the correct digital output.
     
  6. CrisIgtiben

    New Member

    Apr 23, 2009
    3
    0
    hello, i was wondering if you could help me because i have a PIC 16F877A MCU and I want to input voice from a microphone input to the ADC of the PIC. is it possible? and how can I do it?

    by now what i have tried is to connect the speaker output of my laptop to 1 ADC pin (PORTA0) of this PIC. and I placed the output to PORTD 8bits I was able to produce an output that varies with respect to the signal but i am only having slight variations like this output: 248 - 255 or in binary 00000000 to 11110000
     
  7. CrisIgtiben

    New Member

    Apr 23, 2009
    3
    0
    ahm.. actually i am having an output of 5V when the laptop's wpeaker output is not connected. and when i connect it the output varies to around 4.50V to 5V. do i need to implement other circuits first for the sound input before i connect it to the PIC's analog input pin? and when i pause the music that i am playing the output reads 4.99V or mostly 5V
     
  8. CrisIgtiben

    New Member

    Apr 23, 2009
    3
    0
    this is my program

    #include<16F877A.h>
    #device adc=10
    #fuses HS,NOWDT,NOPROTECT,NOLVP
    #use delay (clock=20000000)
    #use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)

    void main()
    {

    float sample;

    //setup the ic ports in preparation for adc
    setup_port_a(ALL_ANALOG);
    setup_adc(ADC_CLOCK_INTERNAL);
    set_adc_channel(0);

    printf("Sampling");

    //place the sampling syntax inside this do-while loop to enable continuous sampling.
    do
    {
    delay_ms(100);
    sample=Read_ADC();
    printf("\n\n Measured Value: %1.2f: ",sample);
    }while(TRUE);

    }

    the output is from 1020 to 1023. it only produces this output when there is a sound input comming from the attached laptop(via speajer jack)

    the output is steady 1023 when i dont apply sound to port a0 or when the volume of the laptop is set to zero

    help people. thankz
     
    Last edited: Apr 24, 2009
Loading...