Menu

16F18313 AN5 not working

Help
Peter
2016-10-07
2016-10-12
1 2 > >> (Page 1 of 2)
  • Peter

    Peter - 2016-10-07

    I built a device using a 16F18313 with a pot connected to AN5 (RA.5) and it didn't seem to work.

    I've built a simple test circuit on breadboard to pulse the LED based on the ADC reading and it doesn't work, the LED flashes ramdomly. I tried both AN5 and ANA5 to refer to the ADC but it made not difference.

    If I connect the pot to AN4 (RA.4) everything works as expected.

    I tried the same code on a 16F18326 (same family) and got the same results. On this device I also connected the pot to ANC2 and ANC5 and they both worked as expected.

    Is there a problem using ANA5 in GCB with this family of PICs?

     

    Last edit: Peter 2016-10-07
  • Chris Roper

    Chris Roper - 2016-10-07

    Interesting. I read your post and just happened to have the 16F18326 hooked up and running a version of the Microchip Reversible Chaselight Demo. I switched the analog input from RA4 to RA5 as a test and although it still works the adjustable speed range is much smaller than it was on RA4.

    Conclusion: It is reading analogue on RA5 but something is wrong with the magnitude of the reading.
    More investigation is needed but certainly an interesting problem.
    I will have a closer look over the weekend.

    Cheers
    Chris

     
  • Anobium

    Anobium - 2016-10-07

    I (we Hugh and I) are working on the ADC methods. We know of some issues.   Let me know what you find as we know we have to make changes to fix the known issues.

    Known issues: backward compatibility wth adc10 and we cannot create overloaded adc methods.

    When you find more.   Let us know.

     
  • Peter

    Peter - 2016-10-07

    I found it odd that ANC5 worked but ANA5 did not.

    When I had the pot on. ANA5, it was like the pin was floating rather than getting any kind reading. I was wondering if it wasn't being initialised properly?

    On the built up circuit i tried using adread instead of adread10 but that didn't work as expected, however I try again on the test circuit over the weekend.

    I didn't see anything in the datasheet regarding ANA5 working differently but I'll have another look.

     
  • Peter

    Peter - 2016-10-08

    I've done some testing on a 16F18326 - code and logs attached.

    I've read the values for ANA4, ANA5 and ANC5 while adjusting the potentiometer. Values for ANA2 and ANC5 are fine, ANA5 hardly change.
    I also tried ANA4 with the ANA2 and ANA4 and ANC5 tied to 0V, and the same again but connecting Vref+ and Vref- to Vdd and 0V respectively.
    The values of ANA5 seem to vary more when it is left floating and one of the other ADC channels is being used!

     
  • Chris Roper

    Chris Roper - 2016-10-08

    Based on Evan's comment:

    "Known issues: backward compatibility wth adc10 and we cannot create overloaded adc methods."

    I also did some test this morning and my results were as follows:

    Observed befaviour of ANA4 vs ANA5 Using ReadAD()
    10K Potentiometer and 5V supply.
    
         min < mid > max
    ANA4   0 < 121 > 255 
    ANA5   0 < 121 > 255  
    
    Observed befaviour of ANA4 vs ANA5 Using ReadAD10()
    10K Potentiometer and 5V supply.
    
         min < mid > max
    ANA4   3 < 502 > 1023 
    ANA5 408 < 573 > 725  
    
    Observed befaviour of ANA4 vs ANA5 Using ReadAD12()
    10K Potentiometer and 5V supply.
    
         min < mid > max
    ANA4   4 < 514 > 1023 
    ANA5   3 < 512 > 1023  
    

    So using ANAx as my Pin Naming I am only seeing issues with ReadAD10() not reading the full range of ANA5 but working fine on ANA4.

    I didn't try different naming conventions.

    My test code is attached

    I see no need to differentiate between 10 and 12 bit ADC read functions as the both return a word value but there are obvious coding differances that are manifesting as a hardware error in this case.

    Certanly strange bahaviour and I would sugest using ReadAD12() for all ADC reads untill this is resolved.

    Cheers
    Chris

     

    Last edit: Chris Roper 2016-10-08
    • Peter

      Peter - 2016-10-08

      I've changed my code to use ReadAD12() and it didn't help.

      I tried your code and got the following results:
      ANA5: 123 < 168 > 183
      ANA4: 2 < 498 > 1023
      ANC5: 2 < 505 > 1023 (not ANA5!)

       

      Last edit: Peter 2016-10-08
  • Chris Roper

    Chris Roper - 2016-10-08

    You get to different results for ANA5 the First being way off andresembeling my result with ReadAD10() the Second being similer to ANA4, is that correct?

     
    • Peter

      Peter - 2016-10-08

      SORRY that's a typo. It should be ANA5, ANA4 and ANC5.
      ANA5 still gives an incorrect reading on my setup.

       
  • Chris Roper

    Chris Roper - 2016-10-08

    New Test code and new results but rather than clarify anything I think it further muddies the waters.

    Power was cycled between each block of tests then 3 readings each on two pins connected to the same POT were taken.
    Test one is with RA5 Connected and RA4 Floating:

    ' AN4 Floating
    ReadAD(ANA4)
    65 < 142 > 221
    ReadAD(ANA5)
    0 < 128 > 255
    
    ReadAD10(ANA4)
    235 < 578 > 906
    ReadAD10(ANA5)
    4 < 514 > 1023
    
    ReadAD12(ANA4)
    232 < 571 > 908
    ReadAD12(ANA5)
    3 < 513 > 1023
    

    Test two is with RA4 Connected and RA5 Floating:

    ' AN5 Floating
    ReadAD(ANA4)
    0 < 129 > 255
    ReadAD(ANA5)
    30 < 144 > 252
    
    ReadAD10(ANA4)
    4 < 514 > 1023
    ReadAD10(ANA5)
    123 < 573 > 1009
    
    ReadAD12(ANA4)
    3 < 514 > 1023
    ReadAD12(ANA5)
    123 < 574 > 1010
    

    Test Three has both RA4 and RA5 simultaniously connected to the same POT.

    'AN4 and AN5 connected
    ReadAD(ANA4)
    0 < 127 > 255
    ReadAD(ANA5)
    0 < 127 > 255
    
    ReadAD10(ANA4)
    3 < 509 > 1023
    ReadAD10(ANA5)
    3 < 512 > 1023
    
    ReadAD12(ANA4)
    3 < 512 > 1023
    ReadAD12(ANA5)
    4 < 509 > 1023
    

    Test four, a control test, is with both RA4 and RA5 Flaoting.

    'AN4 and AN5 Floating
    ReadAD(ANA4)
    83 < 160 > 160
    ReadAD(ANA5)
    77 < 166 > 167
    
    ReadAD10(ANA4)
    106 < 650 > 650
    ReadAD10(ANA5)
    290 < 666 > 667
    
    ReadAD12(ANA4)
    182 < 650 > 652
    ReadAD12(ANA5)
    276 < 668 > 669
    

    Whereas the origional code showed errors with ReadADC10() this set of readings is getting expected results on all 3 ReadADC methods.

    Code is attached to see if you can recreate my results.

    Cheers
    Chris

     

    Last edit: Chris Roper 2016-10-08
  • Peter

    Peter - 2016-10-08

    I've run your code and the only modifications I made were:

    #chip 16F18326, 32
    #config RSTOSC=HFINT32, MCLRE=ON
    
    UNLOCKPPS
            RC0PPS = 0x0014       'RC0->EUSART:TX;
            RXPPS  = 0x0011       'RC1->EUSART:RX;
    LOCKPPS
    

    I get the same results as you for test 2 but different results for the others. AN5 appears dead.
    I replaced the PIC for another one and got the same result. Connecting AN5 to 0V still gives a reading of 130 (with ReadAD10).

    Results

    Pot on AN5, AN4 floating:

    ReadAD(ANA4)
    43 < 45 > 61
    ReadAD(ANA5)
    38 < 39 > 53
    
    ReadAD10(ANA4)
    141 < 142 > 189
    ReadAD10(ANA5)
    129 < 130 > 163
    
    ReadAD12(ANA4)
    125 < 148 > 148
    ReadAD12(ANA5)
    105 < 133 > 133
    

    Pot on AN4, AN5 floating:

    ReadAD(ANA4)
    0 < 124 > 255
    ReadAD(ANA5)
    1 < 123 > 251
    
    ReadAD10(ANA4)
    0 < 498 > 1023
    ReadAD10(ANA5)
    4 < 493 > 1003
    
    ReadAD12(ANA4)
    0 < 498 > 1023
    ReadAD12(ANA5)
    4 < 493 > 1004
    

    Same pot on AN4 and AN5:

    ReadAD(ANA4)
    0 < 124 > 255
    ReadAD(ANA5)
    1 < 123 > 251
    
    ReadAD10(ANA4)
    0 < 498 > 1023
    ReadAD10(ANA5)
    4 < 494 > 1005
    
    ReadAD12(ANA4)
    0 < 498 > 1023
    ReadAD12(ANA5)
    4 < 493 > 1005
    

    AN4 and AN5 floating:

    ReadAD(ANA4)
    50 < 50 > 54
    ReadAD(ANA5)
    44 < 44 > 46
    
    ReadAD10(ANA4)
    170 < 171 > 171
    ReadAD10(ANA5)
    154 < 155 > 155
    
    ReadAD12(ANA4)
    125 < 125 > 139
    ReadAD12(ANA5)
    105 < 105 > 129
    
     
    • Chris Roper

      Chris Roper - 2016-10-08

      It is interesting that with Pot on AN4, AN5 floating, AN5 looks like it is
      following AN4.
      Did you power off between each test to allow the ADC to discharge?

      I repeated my tests with another 18326 and got the same results, ANA5 is
      working in my setup.
      in your case it looks like it is floating.

      I am using the Microchip Low Pin Count Board for my tests.

       
      • Peter

        Peter - 2016-10-08

        I did not power down between those tests, I just pulled MCLR low.

        My circuit is built on a breadboard powered from the USB, however the circuit with the 16F18313 where I first identified the problem is built on Veroboard powered by a wall adaptor @ 5v.

        I just tried pulling out the power and waiting about 20 seconds and I get a slightly larger range on AN5 but it's still not correct:

        Pot on AN5, AN4 floating:

        ReadAD(ANA4)
        42 < 46 > 65
        ReadAD(ANA5)
        39 < 40 > 58
        
        ReadAD10(ANA4)
        152 < 164 > 218
        ReadAD10(ANA5)
        136 < 151 > 190
        
        ReadAD12(ANA4)
        130 < 149 > 180
        ReadAD12(ANA5)
        123 < 136 > 165
        

        And the same thing with AN5 following AN4 even after a power down.
        Pot on AN4, AN5 floating:

        ReadAD(ANA4)
        42 < 46 > 65
        ReadAD(ANA5)
        39 < 40 > 58
        
        ReadAD10(ANA4)
        152 < 164 > 218
        ReadAD10(ANA5)
        136 < 151 > 190
        
        ReadAD12(ANA4)
        130 < 149 > 180
        ReadAD12(ANA5)
        123 < 136 > 165
        
         

        Last edit: Peter 2016-10-08
      • Peter

        Peter - 2016-10-08

        It's been a worthwhile day though - I've figured out PPS (to a lmited extent) and managed to get HWSPI working!

         
  • Anobium

    Anobium - 2016-10-08

    Great test results.   Very good information.

    Let Hugh and I sort the core issues we nred to sort which will resolve one root cause of these issues. We need to do this first. There is little point in trying to resolve thsee issues when I know we need to add a new capability to the compiler.

    I will get to Hugh as soon as possible.

     
  • Anobium

    Anobium - 2016-10-10

    @Peter,

    Can you tell your Great Cow Basic build please? Date of compiler? And, can you confirm that this is a vanilla build with no custom moving of files/.h file etc?

    I have you code operating. I see no errors.

    I have updated the a-d.h. A lot. Get the file from the URL. unzip, replace in your build and test.

    Let us know the results please.

    Download here

     

    Last edit: Anobium 2016-10-10
    • Anobium

      Anobium - 2016-10-10

      And, if you want to optimise the code.... use the #define(s) in the code below. The code is optmised to support only channels (by direct port addressing) 4,5 and 21.

      Enjoy.

      #chip 16F18326
      
      #define USE_AD0 FALSE
      #define USE_AD1 FALSE
      #define USE_AD2 FALSE
      #define USE_AD2 FALSE
      #define USE_AD3 FALSE
      #define USE_AD4 TRUE
      #define USE_AD5 TRUE
      #define USE_AD6 FALSE
      #define USE_AD7 FALSE
      #define USE_AD8 FALSE
      #define USE_AD9 FALSE
      #define USE_AD10 FALSE
      #define USE_AD11 FALSE
      #define USE_AD12 FALSE
      #define USE_AD13 FALSE
      #define USE_AD14 FALSE
      #define USE_AD15 FALSE
      #define USE_AD16 FALSE
      #define USE_AD17 FALSE
      #define USE_AD18 FALSE
      #define USE_AD19 FALSE
      #define USE_AD20 FALSE
      #define USE_AD21 TRUE
      #define USE_AD22 FALSE
      #define USE_AD23 FALSE
      #define USE_AD24 FALSE
      #define USE_AD25 FALSE
      #define USE_AD26 FALSE
      #define USE_AD27 FALSE
      #define USE_AD28 FALSE
      #define USE_AD29 FALSE
      #define USE_AD30 FALSE
      #define USE_AD31 FALSE
      #define USE_AD32 FALSE
      #define USE_AD33 FALSE
      #define USE_AD34 FALSE
      
      #define LED PORTC.2
      dir LED Out
      #define Pot1 ANA5
      dir PORTA.5 In
      #define Pot2 ANA4
      dir PORTA.4 In
      #define Pot3 ANC5
      dir PORTC.5 In
      #define serTx PORTA.0
      Dir serTx Out
      #define serRx PORTA.1
      Dir serRx out
      
      #define USART_BAUD_RATE 19200
      #define USART_TX_BLOCKING
      
      'Initial startup delay
      Wait 500 ms
      
      'Pulse the LED so we know the PIC is running
      Repeat 5
        Pulseout LED, 100 ms
        Wait 100 ms
      End Repeat
      
      Wait 2 s
      
      counter = 0
      
      Repeat 2
        hserprint  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
          HSerPrintCRLF
      End Repeat
      
      'Setup
      hserprint  "PIC16F18326"
      HSerPrintCRLF
      hserprint  "ANA4 - 0V"
      HSerPrintCRLF
      hserprint  "ANA5 - 10K pot"
      HSerPrintCRLF
      hserprint  "ANC5 - 0V"
      HSerPrintCRLF
      hserprint  "RA2 - 0V"
      HSerPrintCRLF
      hserprint  "RA1 - Vdd"
      HSerPrintCRLF
      
      'Read ADC value and send to the serial port
      Do Forever
        hserprint  counter
        hserprint  " ANA5: "
        hserprint  readad10(Pot1)
        hserprint  "     ANA4: "
        hserprint  readad10(Pot2)
        hserprint  "     ANC5: "
        hserprint  readad10(Pot3)
        HSerPrintCRLF
      
        counter++
        'Delay so the terminal screen isn't flooded!
        Wait 1 s
      
      Loop
      
       

      Last edit: Anobium 2016-10-10
      • Peter

        Peter - 2016-10-11

        I swapped my a-d.h for the one that you posted and no change: ANA5 followed ANA4 when it was floating and varied between 4 and 8 when connected to the pot.
        I can run all the tests again if you want but given that you and Chris can get it working i think it must be an electrical problem at my end.

        Compiler version is 0.95.009 2016-08-09

         
        • Anobium

          Anobium - 2016-10-11

          Did you try the code above? I removed software serial and removed a few other odd things.

          Post your code as an attachment. We can review again.

          I cannot be 100% certain regarding your electrical layout. Can you post a drawing?

          Where did you get the chip from?

          But, it does work here. :-(

           
          • Peter

            Peter - 2016-10-11

            Sorry - tired. I ran Chris' test code with the revised a-d.h. I've run your code above, just adding in the PPS settings, turning MCLRE On and changing the information text to reflect how it's connected.
            With the pot on ANA5, virtually no change in the ADC values. With the pot on ANA4 or ANC5 (and ANA5 grounded) the value read from ANA5 varies with the value from the pin that is connected to the pot.

            The chips (16F18313 and 16F18326) both came from RS components. The device ID revision of the 16F18326 is 2001 - I'm not sure if there is a different version out there.

            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            PIC16F18326
            ANA4 - 0V
            ANA5 - 10K pot
            ANC5 - 0V
            RA2 - Floating
            RA1 - Floating
            0 ANA5: 755     ANA4: 1     ANC5: 1
            1 ANA5: 74     ANA4: 1     ANC5: 1
            2 ANA5: 75     ANA4: 1     ANC5: 1
            3 ANA5: 75     ANA4: 1     ANC5: 1
            4 ANA5: 75     ANA4: 1     ANC5: 1
            5 ANA5: 80     ANA4: 1     ANC5: 1
            6 ANA5: 80     ANA4: 1     ANC5: 1
            7 ANA5: 80     ANA4: 1     ANC5: 1
            8 ANA5: 81     ANA4: 1     ANC5: 1
            9 ANA5: 81     ANA4: 1     ANC5: 1
            10 ANA5: 81     ANA4: 1     ANC5: 1
            11 ANA5: 83     ANA4: 1     ANC5: 1
            12 ANA5: 105     ANA4: 1     ANC5: 1
            13 ANA5: 105     ANA4: 1     ANC5: 1
            14 ANA5: 85     ANA4: 1     ANC5: 1
            15 ANA5: 81     ANA4: 1     ANC5: 1
            16 ANA5: 80     ANA4: 1     ANC5: 1
            17 ANA5: 79     ANA4: 1     ANC5: 1
            18 ANA5: 79     ANA4: 1     ANC5: 1
            19 ANA5: 78     ANA4: 1     ANC5: 1
            20 ANA5: 78     ANA4: 1     ANC5: 1
            21 ANA5: 74     ANA4: 1     ANC5: 1
            22 ANA5: 74     ANA4: 1     ANC5: 1
            23 ANA5: 73     ANA4: 1     ANC5: 1
            24 ANA5: 73     ANA4: 1     ANC5: 1
            25 ANA5: 74     ANA4: 1     ANC5: 1
            26 ANA5: 74     ANA4: 1     ANC5: 1
            27 ANA5: 73     ANA4: 1     ANC5: 1
            28 ANA5: 74     ANA4: 1     ANC5: 1
            
             

            Last edit: Peter 2016-10-11
            • Anobium

              Anobium - 2016-10-11

              Do check this but looks like your 0v is not connected. The layout looks incorrect and so does the breakboard.

              CHeck the datasheet 0v is on 14 pin/VSS.

               
              • Peter

                Peter - 2016-10-11

                Yes it is connected, the picture is incorrect. I'm taking power. (and 0v) from the USB to serial device. There are a pair of wires from the rails to Vcc and Vss on the ISCP header.

                Edit: Updated breadboard layout attached.
                Edit2: Updated breadboard layout that doesn't have both sides of the pot on +5v

                 

                Last edit: Peter 2016-10-11
                • Anobium

                  Anobium - 2016-10-11

                  Common 0v? Make sure 0v is common. I will test again tomorrow to confirm I am not making a error at my end.

                   
                  • Peter

                    Peter - 2016-10-11

                    Everything that is Vss/0V/GND is connected to GND on the USB to serial device. This includes Vss on the ISCP header (diconnecting the PicKit3 doesn't make a difference to the problem though).
                    There's no external power applied, all the power is taken from the USB to serial converter.

                    When the potentiometer is connected to pin 3 (ANA4) then ANA4 works, if the wire is connected to pin 2 (ANA5) then ANA5 doesn't work. Nothing else gets changed.

                    I moved the PIC along a few holes on the breadboard in case it was a bad connection - didn't make a difference.

                    I'm wondering if I've somehow got a bad batch of PICs as I am getting the same problem with 2x16F18326 on breadboard and 2x16F18313 on stripboard whereas yourself and Chris are having no problems at all.
                    I am planning to order some stuff from Microchip Direct, so I can buy a new one direct from them and see if the same issue occurs.

                     

                    Last edit: Peter 2016-10-11
    • Peter

      Peter - 2016-10-11

      I will try and give the new a-d.h a go this evening.
      I have a vanilla build apart from a modified glcd.h (with the smaller buffer for low memory devices). I think my GBC is v.0.95.009 but I will check and report back.

       
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.