Analog port newbie questions


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2008
    Posts
    13

    Default Analog port newbie questions

    Hi guys,

    Im having trouble using the analog port. Regarding the analog port A, is it supposed to output high (approx 4.8V) when its not connected to anything ? I have set trisa=%111111.

    Ive programmed everything else correctly (I think), after reading some good guides on programming for port A.

    The problem is I have a photodiode which has open circuit voltage of 0.25V but when I connect it to channel 0 it jumps to 0.40V for some reason. The Vref+ is set to 2.5V.

    Thanks all.

    edit: I suspect that something is wrong with my port A. How do i check ? Anyone have a working test code ? Im also testing it now ..
    Last edited by rngd; - 8th March 2008 at 12:15.

  2. #2
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Port A is a bit different

    Hi,

    What PIC do you use? Port A usually contains a lot of stuff such as comparators and A/D and there fore requires some more registers to be set before it is working properly.

    What do you have connected to your port A and what do you want it to do? Do you want all pins digital? or just some and the others A/D.

    To help you we need some more info such as mentioned befoer PIC, simple circuit description, a clear idea of your expected end result and some beer.

    The beer most of us already have so you just add the rest and we will see where the problem is.

    /me

  3. #3
    Join Date
    Feb 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Hi jumper, these are my settings for ADC

    define OSC 20
    define adc_bits 10 'define number of bits in result
    define adc_clock 3 'clock source3=RC
    define adc_sampleus 50 'set sampling time in microsec

    adc1 var word 'store adc input values, adc1=AN0/RA0
    adc2 var word 'AN1/RA1
    adc3 var word 'AN2/RA2
    adc4 var word 'AN4/RA5

    trisa = %11111111 'port A all input

    adcon1 = %10000011 '1 for Result Format Selection Bit because using 10 bits
    '0011 for AN4, AN2, AN1, AN0 analog port. AN3 is
    'Vref+ reference voltage
    pause 500 'wait .5 second


    Im using the 16F877A. This is my main program and it is supposed to input 4 analog values, do some comparison and then high some ports.

    Ive tried a simpler version to test out the port also,


    define osc 20

    define adc_bits 10 'define number of bits in result
    define adc_clock 3 'clock source3=RC
    define adc_sampleus 50 'set sampling time in microsec

    trisa = %11111111
    trisd=0
    adcon1 = %10000010

    pause 500

    adc var word

    start:

    adcin 0, adc

    if adc > 10 then
    high portd.0

    else
    low portd.0

    endif

    pause 500

    goto start



    When I input 2.5V into porta.0 the LED does not turn on. If I leave the pin floating (5V) then it turns on. If I change the code to 'adc>0', it turns on.
    edit: I think the port A of my PIC is fried. When power is on but nothing is connected, the port A pins are at 5V. Is this normal ? Help pls !
    Last edited by rngd; - 8th March 2008 at 18:02.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    You set AN3 as Vref+. What do you have on AN3?
    Try setting Vref+ to internal +5v and see what happens...

  5. #5
    Join Date
    Feb 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    You set AN3 as Vref+. What do you have on AN3?
    Try setting Vref+ to internal +5v and see what happens...
    For the first code, I have a voltage regulator giving 2.5V to AN3.

    I have tried using internal 5V Vref+ for the code below
    define osc 20

    define adc_bits 10 'define number of bits in result
    define adc_clock 3 'clock source3=RC
    define adc_sampleus 50 'set sampling time in microsec

    trisa = %11111111
    trisd=0
    adcon1 = %10000010

    pause 500

    adc var word

    start:

    adcin 0, adc

    if adc > 10 then
    high portd.0

    else
    low portd.0

    endif

    pause 500

    goto start
    and i input the same 2.5V into channel 0, but I cannot get portd.0 to go high ? Ive also tried changing to 'define adc_clock 2' or (20Mhz which is same as my OSC freq).

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Which version of PBP are you using?
    And try
    adcon0 = $c1 : adcon1 = $f0
    Last edited by skimask; - 9th March 2008 at 08:32.

  7. #7
    Join Date
    Feb 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Which version of PBP are you using?
    And try
    adcon0 = $c1 : adcon1 = $f0
    Im using PBP 2.47. I tried to change adcon1 and add adcon0 but it still doesnt work. Is the problem in my code or is my port A burnt (I accidentally input ~10V for a short while into the Vref+ pin earlier) ?
    Is anything wrong with the quoted code ?

    Any help is appreciated.

  8. #8
    Join Date
    Feb 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    OK, I found the problem, turns out the defines must be in block letters. Weird that I did not get any compile errors though.

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rngd View Post
    OK, I found the problem, turns out the defines must be in block letters. Weird that I did not get any compile errors though.
    Which is exactly what the PBP manual says will happen...

  10. #10
    Join Date
    Feb 2008
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Which is exactly what the PBP manual says will happen...
    Yeah, too bad for me, I did not not read the part about the defines

Similar Threads

  1. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  2. Pic getting part power from Analog Port
    By ShaneMichael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd April 2009, 10:34
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Hi Everyone! Some newbie questions :-)
    By guest_05 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th October 2006, 22:24
  5. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts