ADC problem on 18F46K22 device using all 28 ADC pins


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2012
    Posts
    64

    Default ADC problem on 18F46K22 device using all 28 ADC pins

    I am building a cable tester and need to test pin connections with each other. I want to be able to detect hard wired connections as well as resistance, so I chose Pic18F46K22 due to the amount of Analog pins (28) for connections with each other. All 28 pins are pulled to ground with a 10k resistor. I don’t care about actual resistance values, but I do want to be able to detect a hard wired short verses a resistor.
    I set up an outside loop from 0-27 which sets up All Analog capable ports to Analog/Inputs (ANSELx/TRISx registers), except for the testing pin which I set up to Digital/Output and set high. I then enter an inside loop from 0-27 reading all analog pins except for the current testing pin. Any values other than zero should indicate a connection between the testing digital pin and the analog pin being tested. I use the defines (ADC_BITS 8, ADC_CLOCK 3, ADC_SAMPLEUS 50).
    I am able to detect shorts between pins as well as resistance when I jumper wires/resistors between pins o.k., but I am having a problem where I always detect connections between certain pins although there is no connection between them. The pins falsely detecting shorts are always the same. The following lines show the pins falsely detected along with the digital pin index, and ANSELx register settings during the current test. You can see a pattern in the error where the Analog pin 16 thru 27 (Digital RC4-RD7) shows shorts. Even the pin it shows to be shorted with increases by 1 each time.
    Pins 16-0 = 127 Dpin:20 A:00101111 B:00111111 C:11101100 D:11111111 E:00000111
    Pins 17-1 = 127 Dpin:21 A:00101111 B:00111111 C:11011100 D:11111111 E:00000111
    Pins 18-2 = 127 Dpin:22 A:00101111 B:00111111 C:10111100 D:11111111 E: 00000111
    Pins 19-3 = 127 Dpin:23 A:00101111 B:00111111 C:01111100 D:11111111 E: 00000111
    Pins 20-4 = 127 Dpin:24 A:00101111 B:00111111 C:11111100 D:11111110 E:00000111
    Pins 21-5 = 127 Dpin:25 A:00101111 B:00111111 C:11111100 D:11111101 E:00000111
    Pins 22-6 = 127 Dpin:26 A:00101111 B:00111111 C:11111100 D:11111011 E:00000111
    Pins 23-7 = 127 Dpin:27 A:00101111 B:00111111 C:11111100 D:11110111 E:00000111
    Pins 24-8 = 127 Dpin:28 A:00101111 B:00111111 C:11111100 D:11101111 E:00000111
    Pins 25-9 = 127 Dpin:29 A:00101111 B:00111111 C:11111100 D:11011111 E:00000111
    Pins 26-10 = 127 Dpin:30 A:00101111 B:00111111 C:11111100 D:10111111 E:00000111
    Pins 27-11 = 127 Dpin:31 A:00101111 B:00111111 C:11111100 D:01111111 E:00000111
    I also made a test routing which does the same test except it only tests one port at a time (example: Turns on Analog pins AN20 thru AN27 (portD) and only tests them. It works correctly. I also have an all digital routine which tests all the same pins against each other digitally and that also works correctly. The problem seems to be only when all Analog pins are active at the same time, except for the testing pin).
    One more note: The value of 127 is actually a hard short. I use the following code to limit the analog reading between 0-127.
    ADCIN idx, Pinin
    If Pinin <128 then ' Sets analog range 0-127
    Pinin = 128
    Endif
    Pinin = pinin -128
    I have the weak pull-ups disabled. Am I missing anything important to do with ADC conversions on the 46k22 device?
    Thanks for any ideas,
    Jim

  2. #2
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: ADC problem on 18F46K22 device using all 28 ADC pins

    I have tried everything I can think of to try to isolate what is causing this strange ADC error I am seeing and I narrowed down the cause, but I can’t figure out Why. I can really use some help with this.
    I am trying to build a cable tester (Continuity and resistance) by using all 28 Analog pins to test for connections against each pin one at a time. To accomplish this I use two loops: The outer loop sets up one of the pins as a digital output and sets the voltage high, while setting the remaining 27 pins as Analog inputs. The Inside loop then tests each analog pin (excluding the one set to digital) using the ADCIN command, and stores the results in an array. If the digital pin being tested is wired to any of the analog pins it will record the value showing the connection. The outside loop then sets the digital pin low, and then sets up the TRISx and ANSELx registers to proceed to testing the next pin until all pins have been tested against each other. This sounds like a simple thing to accomplish, and it does work to a point, but there is an error once the outside loop reaches AN16 (RC4 set to digital) And the inside loop is >= 16. At that point the ADCIN command starts reporting connections that don’t exist. They are always the same and follow a pattern.
    AN16 show short with AN0, AN17 shows shorted to AN1, AN18 Shorted to AN2,… and so on.
    Now if I leave the Outside loop alone (0 to 27) setting up each pin to digital one at a time and testing against each other pin the same as before, but this time I set the inside loop from 0 to 15 instead, I can test all 28 pin (one at a time as digital output) against the first 16 Analog pins (1-15) without error and I can repeat this as many times as I like. Once I do a simple ADCIN read of any Analog pin higher than AN15 (Even if I don’t set any pin to digital/High), then try to run the same routing again it shows the shorts again, and I then need to cut power to the micro to get valid results again.
    The ADCIN read of pins 16-27 seems to change something. I am using the following defines:
    DEFINE ADC_BITS 8, DEFINE ADC_CLOCK 3, DEFINE ADC_SAMPLEUS 50
    I am not sure if setting the ADC Bits to 8 is valid for the 18F46k22, but it seems to work correctly when reading values from a trim port. One more thing to note is all Analog pins are tied to ground with a 10k resistor. If there are any ADC experts out there that would be willing to look at my code, I would be happy to send it to you (The code might be able to explain what I am doing better).

    Thanks,
    Jim

  3. #3
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: ADC problem on 18F46K22 device using all 28 ADC pins

    It turns out the problem was a bug in PBP. It was fixed in version 2.60C

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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