Two hopefully easy questions?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322

    Default Two hopefully easy questions?

    Hi All!

    1. To change the results from a 12 bit A/D from 12 bit to 8 bit, would you simply change SHIFTIN DOUT, CK, MSBPRE, [RESULT\12] to SHIFTIN DOUT, CK, MSBPRE, [RESULT\8] ?

    2. When compiling a program where you are not allowed to use CMCON=7 to make all inputs digital and not analog, is this where you would use something like the TRIS command auch as TRISA for the A A/D AND TRISHB for the B A/D and so on?

    Thanks, Ed

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Two hopefully easy questions?

    Hi Ed,
    1) Since you're using MSBPRE it might work to just shift in 8 bits (try it) since that will give you the eight high bits of the result but I don't know what the ADC thinks about having the transfer interrupted in the middle. Personally I'd read the 12bit result and then shift it, EightBit = TwelveBit >> 4.

    2) If you're not "allowed" to set CMCON it's because the chip you're using doesn't HAVE that register (likely because it doesn't have comparators) so there's no need to set CMCON. By the way, CMCON is configured differently on different PIC's so just because CMCON=7 turns off the comparators on one PIC doesn't mean it necccesarily does so on another, make sure you read the datasheet.

    The TRIS registers are used to select if a particular pin/port should be an input (TRIS.x=1) or an output (TRIS.x=0) it has nothing to with the analog functions per se. The ADC is usually controlled thru the ADCON register but it depends on the particullar PIC you're using, make sure you read the datasheet.

    Finally, neither CMCON, TRIS or ADCON are commands - they are registers in the PIC which you assign values to in order to make the chip operate the way you want.

    /Henrik.

  3. #3
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: Two hopefully easy questions?

    Thanks Henrik.
    So if you have a PIC 18F1320 and you wish to make it all digital inputs is there one command to do this or do you have to do an ADCON0=1, and so on for all the A/D's (I think there are 7)?

    Thanks, Ed

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: Two hopefully easy questions?

    Hi, Ed

    There are no genuine " all digital " command in PBP ... Buuutttt ... Darrel wrote one !!!

    http://www.picbasic.co.uk/forum/showthread.php?t=11100

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Two hopefully easy questions?

    Hi Ed,
    If you look at the datasheet you'll find that on the 18F1320 you select if a pin should be analog or digital thru ADCON1 (see section 17.2), so to set all pins as digital you can simply do ADCON1 = 255. That's one command.

    It's also a good idea to look at the initialization conditions (Table 4.3), there you'll see that ADCON1 defaults to a value of 0 on power on and reset which means that all analog pins starts up in analog mode so you need to switch them to digital.

    You can use Darrels AllDigital but it's always nice to be able to do it "manually" in case AllDigital isn't kept up to date or doesn't work for whatever reason.

    /Henrik.

  6. #6
    Join Date
    Mar 2011
    Location
    Los Angeles, California
    Posts
    322


    Did you find this post helpful? Yes | No

    Default Re: Two hopefully easy questions?

    Thank you both very much! It is pleasure learning from you!

    Best, Ed

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