Partial Digital PORTA?


Closed Thread
Results 1 to 9 of 9
  1. #1
    actionplus's Avatar
    actionplus Guest

    Default Partial Digital PORTA?

    I am currently using PORTA.0 to PORTA.2 as analog inputs.
    Is there anyway to get PORTA.3 on a PIC16F877 to digital?

    This is my current setting
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 ' Set PORTA analog

    I am trying to use this PORTA.3 as an input from a optical sensor that I place on a spinning disk. You guessed it. Try to build myself a tachometer.

    Currently, I have all kinds of numbers poping up on the LCD when I make one pass. I get numbers from 2,7,10,47 depending on how long it takes to pass the reflective surface. Maybe I am not giving the PIC a clean signal to look at.

    Any remedies?

    Thanks
    Randy

  2. #2
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    Randy,

    From the datasheet I was able to gather the attached table. It looks from your statement that you are selecting A5 plus A3-A0 as analogs inputs (the whole port A), and E2,E1,E0 as digital inputs. It also looks like you can not have A2-A0 as analogs and A3 as digital.

    The closest thing you could have is A3,A1,A0 as analogs and A5,A2 as digital. This would read:

    ADCON1 = %10000100

    Hope this helps.
    Attached Images Attached Images  

  3. #3
    actionplus's Avatar
    actionplus Guest


    Did you find this post helpful? Yes | No

    Default ADCON1

    Will
    ADCON1=%10000101 give me PORTA.0 and PORTA.1 analog and PORTA.2 and PORTE's digital?

  4. #4
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    It should. Note that this configuration will also make PORTA.3 the A2D reference, so you must supply a voltage reference to this pin.

  5. #5
    actionplus's Avatar
    actionplus Guest


    Did you find this post helpful? Yes | No

    Default Shcmitt Trigger

    Do you how to get the Schmitt trigger running on the PIC16F877A.
    It is on the PORTA.4.

    tHanks
    Randy

  6. #6
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    It should be set by default. The pin, when used as digital, has the schmitt trigger as input. The output is however open-drain (i.e. it needs a pull-up if you want to use it).

    From the datasheet:

    "Pin RA4 is multiplexed with the Timer0 module clock
    input to become the RA4/T0CKI pin. The RA4/T0CKI
    pin is a Schmitt Trigger input and an open-drain output."

    The pin is also shared as a comparator output, but by default it is off:

    "On a Power-on Reset, these pins are configured as analog inputs and read as ‘0’. The comparators are in the off (digital) state."

    Hope it helps.

  7. #7
    actionplus's Avatar
    actionplus Guest


    Did you find this post helpful? Yes | No

    Smile schmitt trigger

    Thanks, you have been very helpful

    Here is what I have setup at the moment

    I have the optial sensor(phototransistor OPB703 from Optek) connected to PORTA.4.

    Count PORTA.4,100,counts
    rpm=counts*600

    Do I have this right? Because I still get bunch of numbers when I pass the reflective surface. The sensor picks up the signal the count keeps adding "counts" rather than counting 1 at each pass.
    Any clue why?


    Now, since the schmitt trigger is set automatically when it is digital and you said that I need a extrenal resistor at the output.

    What I don't understand is that, I am thinking that I am using the PORTA.4 as an input for the schmitt trigger. Where will the output be for this then?

    Thanks
    Randy

    p/s-I guess you can see that I am really new at this.

  8. #8
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    Disclaimer:
    1) I have never done a tachometer...
    ... although I have done frequency counters.

    2) There is no such things as being new at something, it is only a degree of knowledge (and it varies from day-to-day, coffee anyone?). Questions are extremely good.

    First let me try the port question.
    <ul>If you are only using the RA4 pin as an input, then you have nothing to worry about (it is only if you wanted to use it as an output that you need an external pull-up).</ul>

    Next let me try your application-specific question.
    <ul>The math used is good (i.e. you will get RPMs out of the equation).
    Two things come to mind, what are you trying to measure (i.e. what are the limits of your measurements)?. For example, on a 4MHz clock, the COUNT function has a 25kHz max frequency. This should be enough to measure 150,000RPM with your 100mS gate (if I did the math correct). By the same token the minimum you could measure would be 600RPM, and your resolution would be 600RPM (or 1 count). To achieve better resolution you have to sample longer (i.e. 1s, 10s, etc.). Problem is that if your maximum RPM is very high you are quickly getting into 32bit numbers. As it is 150,000RPM (rocket anyone?) will require an 18bit number.
    Within reason, you could sample longer and get better results (since, in my mind, you may be sampling 1,000 to 20,000RPM). What other people have done is use the PULSIN function to measure one pulse (assumption made -> 50% duty cycle), you could even average a few pulses to get a more stable measurement (I would use a median-type filter/average). I've attached a few links of examples:

    http://list.picbasic.com/forum/messages/4011/4360.html
    http://list.picbasic.com/forum/messages/20/1045.html

    Now lets try to tackle your problem at hand. You say that your numbers are jumping all over the place:
    1. Do you look at the 'counts' number or the 'RPM' number? I presume you have declared both as WORDs. The 'counts' number is a better indicator of your measurement since the 'RPM' could overflow a WORD variable.
    2. How is the sensor information applied to the COUNT pin? I am sure you need some signal conditioning before applying this signal into the PIC since you may have double-counts or things of that nature (i.e. of analog nature).
    </ul>

    Hope this leads you to some answers (more likely more questions - that's almost always the case, but then how would you learn if it were not for the questions).
    Last edited by languer; - 8th March 2004 at 19:40.

  9. #9
    actionplus's Avatar
    actionplus Guest


    Did you find this post helpful? Yes | No

    Default Specs

    Thank you for your explainations. You are getting to be very informative.

    Here is a few more information

    RPM
    Min?Max-3000rpm
    What would the best xtal I should use? I am currently running a 10MHz 18pF xtal.

    Signal conditioning.
    None at the moment. I have the sensor directly connected to PORTA.4.
    I think I should be thinking of cleaning up the signal. Maybe a LM3??, forgot which one. Shouldn't be to hard to find out. I have in paper somewhere.

    Another question I have is that, does the PIC have the capability of Input Capture of either raising edge of a signal or falling edge?
    I will try to look it up. Thought I will ask you if you happen to know of the top of your head.

    Thanks again
    Randy

Similar Threads

  1. PortA Doesn't Work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 11
    Last Post: - 8th September 2015, 18:41
  2. Replies: 5
    Last Post: - 16th October 2009, 18:29
  3. 16F877a PORTA ADC and digital help
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th February 2008, 18:44
  4. PortA analog and digital IO
    By krohtech in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th November 2007, 02:25
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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