Announcement

Collapse
No announcement yet.

Can't configure the 16F18326 analog ports

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't configure the 16F18326 analog ports

    I have been using the pro-compiler for a number of years on various chips and projects with no problems. I have designed a product around the expanded program memory 16F18326 chip, which I assumed was going to be a drop in for the 16F1825 (WRONG). I have not been able to configure the analog channels. They will not read. After months of trying everything, and several emails to melabs with no results, I am asking for forum help. If anyone has used this chip and has got the analog channels to work, or you know how to configure it, then I would be interested in knowing how. Thanks in advance. I'm desperate as I have wasted over 6 months messing with this one chip.
    Last edited by ROBOTKING; 3 weeks ago.

  • #2
    Sorry if I dropped the email ball. I wasn't aware of an unresolved issue.

    I've tested the following with the 16F18326 on a LAB-X20 board. It reads AN2 on RA2 (the default).


    [CODE]
    ' Name : ADCX20.pbp
    ' Compiler : PICBASIC PRO Compiler 3.1
    ' Assembler : MPASMX
    ' Target PIC : PIC16F18326
    ' Hardware : LAB-X20 Experimenter Board
    ' Oscillator : 32MHz internal osc
    ' Keywords : ADCIN, LCDOUT
    ' Description : PICBASIC PRO program to read pot and display on LCD.
    '

    #CONFIG
    __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
    __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _WDTE_ON & _LPBOREN_OFF & _BOREN_ON & _BORV_LOW & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
    __config _CONFIG3, _WRT_OFF & _LVP_OFF
    __config _CONFIG4, _CP_OFF & _CPD_OFF
    #ENDCONFIG

    DEFINE OSC 32
    OSCCON1 = %00000000 ' Configure internal osc to 32MHz

    ' Define LCD pins
    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTC
    Define LCD_RSBIT 4
    Define LCD_EREG PORTC
    Define LCD_EBIT 5


    ' Allocate variables
    x Var Byte

    ANSELA = %00000100 ' Set PORTA.2 analog, rest digital
    ANSELC = %00000000
    ADCON1 = %00110000 ' Left-justified, ADC clock = 3

    Pause 100 ' Wait for LCD to start

    mainloop:
    Adcin 2, x ' Read ADC value on AN2 (PORTA.2)
    Lcdout $fe, 1, "Pot1 = ", #x ' Send value to LCD
    Pause 100 ' Do it about 10 times a second
    Goto mainloop ' Do it forever
    [/CODE]
    Charles Leo
    ME Labs, Inc.
    http://melabs.com

    Comment


    • #3
      Not sure why CODE tags failed in last post.

      [CODE]test code[/CODE]

      I guess it's always something.
      Charles Leo
      ME Labs, Inc.
      http://melabs.com

      Comment


      • #4
        Thank you, Charles!! After months of messing around trying everything I could try, I never caught that bits <4-6> of ADCON1 needed setting. For this chip to read the analog port bits 4 and 5 must be set to 1, which your code had done. The clue was your comment "ADC clock =3." That seems to have done it, for now anyway, until I am able to proceed further into the guts of this chip. Hopefully this is it. This chip has been one difficult monster to understand.

        Comment


        • #5
          When I'm working with either a new Function or a new Processor, I make it a habit of looking at the data sheet section regarding that Function. I've noticed TMR2/4/6 works quite differently on certain newer processors, TMR0 can be either 8- or 16-bit, newer chips use ADC2 with additional features and SFRs, INTCON & PIE/PIR changes from processor to processor, some processors allow for Weak Pull Ups (WPUX Registers), Open Drain (ODCONX), and the list could be quite extensive. Even simple things like ADC really need you to look at the section of the Data Sheet that covers that function. It took a couple situations where I couldn't get something to work, communicated with Charles and have him point out what would have been obvious had I actually read that section of the Data Sheet. ...just sayin'

          Comment


          • #6
            Totally agree, mpg, and indeed I have studied the data sheets for this chip until I almost have them memorized, however, even then unless you are familiar with these things, the data can mean little. This particular chip is an absolute nightmare, and it has been from the very beginning, as nothing worked on it. It took a few phone calls to Charles to even get it to respond to getting digital data in and out of ports. You get one thing working at a time on this chip, thinking it will finally all work, and it never does. Everything that can go wrong with the 16F18326 does. It is an impossible chip unless perhaps you are the designer of it. I chose this chip because my application uses a 16F1825 with 14K memory, which I am pushing to the limits. The 16F18326 has double the program memory with the same 14 pin footprint, and I thought it would be a drop in and I could expand the capabilities of my product, which has been the biggest nightmare I have ever had with a PIC chip or PB3. As of this reply this chip still has a problem, inasmuch as it still won't read RC3/ANC3. I think once that gets solved I am home free. Any help on config would be appreciated.

            Comment


            • #7
              All problems solved and chip is working perfectly. The nightmare is over. Problem with ANC3 was a bad chip. Never had a bad chip from Microchip, but anything that can happen will.

              Comment


              • #8
                Working with a PIC16F1619 I thought I had a bad, no make that 2 bad chips. Turned out I was monitoring 4 inputs in sequence (PORTA). I absent mindedly used the MCLR port as one of them, though the code didn't reflect that, just the hardware. I had it jittering to the tune of our US 60 Hz on one, and pretty much nothing on the other. Fixed the breadboard and both chips worked just fine.

                Comment


                • #9
                  Thanks for the experience update. I try to fix problems in my logic or thinking, and rarely do I suspect the hardware, especially when it's new. The last thing I suspect is a bad chip. In this particular case, the exact pin that I was trying to read kept reading an analog value of 18, which made no sense. In my circuit that pin never is exposed to a voltage over 1.0 DCV, as it's a scaled battery monitor pin. Everything was configured right. As a last resort I said OK, let's try a different chip. Voila! That was it.The chip was never subjected to abuse on the BB, it simply had a bad analog module, or whatever happens to the innards of these things. Anyway, my expanded project is speeding along and it's nice to have program memory to finally play with. I'm gonna love this 16F18326 even after all the grief with it.

                  Comment

                  Working...
                  X