Menu

ADC on 16F15323 doesn't work

Help
Frank
2017-12-05
2018-01-21
1 2 3 > >> (Page 1 of 3)
  • Frank

    Frank - 2017-12-05

    Hi to all,

    I can't get the ADC on a 16F15323 working. I get only "0" without voltage (GND) and "512" with any voltage after a new power on! This means I get ALWAYS "0" with GND on my ADC on startup (changing to any voltage has no effect) and I get ALWAYS "512" with voltage at startup even if I remove the voltage (short to GND).

    Here is my code - did I do something wrong?

    '*       *** (Compiled with GCB 0.98.010) ***                     *
    '*** Initialisation ***
    'Select chip model and speed
    #chip 16F15323
    #config mclr_off, WDT_Off
    
    #define DEBUG_TRANS  PORTC.1    'TxD Pin for debugging
    
    '*** Config Software-UART ***
    Dir DEBUG_TRANS Out
    #define SendAHigh Set DEBUG_TRANS ON
    #define SendALow  Set DEBUG_TRANS OFF
    InitSer 1, r19200, 1+WaitForStart, 8, 1, None, Normal
    Set DEBUG_TRANS ON
    
    SerPrint 1, " PIC 16f15323"
    
    SerSend 1, 13  ' "Carriage Return"
    SerSend 1, 10  ' "Line Feed"
    
    do
      SerPrint 1,readad10(AN2)
      SerSend 1, 13  ' "Carriage Return"
      SerSend 1, 10  ' "Line Feed"
      wait 200 ms
    loop
    
    End
    

    Thank you very much for any help!!!

    Frank

     
    • Anobium

      Anobium - 2017-12-05

      Try this,

      'Set the input pin direction
      Dir PORTA.2 In

       
  • Frank

    Frank - 2017-12-05

    Hi Evan,

    I tried this before (and tried it in the moment again) - same result!

    Frank

     
    • Anobium

      Anobium - 2017-12-05

      Looking at the asm.
      - ANSEL looks correct.
      - ADCON0.CHx looks correct
      I may have messed up my ASM review but nothing is jumping out at me.

      Try another port? AN3?

      Does anyone else have the same chip?

       
  • Frank

    Frank - 2017-12-05

    This chip has no AN3 - I tried AN4 - ALWAYS "0" !?! :-(

     
    • Anobium

      Anobium - 2017-12-05

      I can get a chip if not one else has this chip. Will take a week to obtain a chip.

       
  • Frank

    Frank - 2017-12-05

    ...I have a chip here - but I don't think it's really going to go any faster if I send it from here...

     
  • Frank

    Frank - 2017-12-05

    ...I downloaded it and replaced it - no change...

     
    • Anobium

      Anobium - 2017-12-05

      Sister chip: 16F15355. results range from 0 to 1022. That is the OK.
      Only change was the chip, chip frequency, debug port and the LED toggle. I have tried with frequency missing no different. My code is shown below: So looks ok on this chip - I have got one coming here.

      Please check connectivity and try

      #define ADSpeed LowSpeed
      #define AD_Delay 4 10us
      

      My code for the 16F15355

      'Select chip model and speed
      #chip 16F15355, 32
      #config mclr_off, WDT_Off
      
      #define DEBUG_TRANS  PORTC.6    'TxD Pin for debugging
      
      '*** Config Software-UART ***
      Dir DEBUG_TRANS Out
      #define SendAHigh Set DEBUG_TRANS ON
      #define SendALow  Set DEBUG_TRANS OFF
      InitSer 1, r19200, 1+WaitForStart, 8, 1, None, Normal
      Set DEBUG_TRANS ON
      
      SerPrint 1, " PIC 16f15355"
      
      SerSend 1, 13  ' "Carriage Return"
      SerSend 1, 10  ' "Line Feed"
      
      dir porta.0 out
      
      do
       SerPrint 1,readad10(AN2)
        SerSend 1, 13  ' "Carriage Return"
        SerSend 1, 10  ' "Line Feed"
        wait 200 ms
        porta.0 = ! porta.0
      loop
      
      
      End
      
      
      ''' GCB Optimisation file
      
      'Optmise PWM.h
          #define USE_HPWMCCP1 false
          #define USE_HPWMCCP2 false
          #define USE_HPWMCCP3 false
          #define USE_HPWMCCP4 false
        #define USE_HPWMCCP5 false
      
          #define USE_HPWM5 false
          #define USE_HPWM6 false
          #define USE_HPWM7 false
      
          #define USE_HPWM_TIMER2 false
          #define USE_HPWM_TIMER4 false
          #define USE_HPWM_TIMER6 false
          #define USE_HPWM_TIMER7 false
      
      'Optimise A-d.h
          'Standard family chips
          #define USE_AD0 false
          #define USE_AD1 false
          #define USE_AD2 true
          #define USE_AD2 false
          #define USE_AD3 false
          #define USE_AD4 false
          #define USE_AD5 false
          #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 false
          #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
      
          'Family of chips based on 16f1688x with ADCON3 register
          #define USE_ADA0 false
          #define USE_ADA1 false
          #define USE_ADA2 true
          #define USE_ADA3 false
          #define USE_ADA4 false
          #define USE_ADA5 false
          #define USE_ADA6 false
          #define USE_ADA7 false
          #define USE_ADB0 false
          #define USE_ADB1 false
          #define USE_ADB2 false
          #define USE_ADB3 false
          #define USE_ADB4 false
          #define USE_ADB5 false
          #define USE_ADB6 false
          #define USE_ADB7 false
          #define USE_ADC0 false
          #define USE_ADC1 false
          #define USE_ADC2 false
          #define USE_ADC3 false
          #define USE_ADC4 false
          #define USE_ADC5 false
          #define USE_ADC6 false
          #define USE_ADC7 false
          #define USE_ADD0 false
          #define USE_ADD1 false
          #define USE_ADD2 false
          #define USE_ADD3 false
          #define USE_ADD4 false
          #define USE_ADD5 false
          #define USE_ADD6 false
          #define USE_ADD7 false
          #define USE_ADE0 false
          #define USE_ADE1 false
          #define USE_ADE2 false
      
       
      • Anobium

        Anobium - 2017-12-05

        16F15356 and 16F15355 - work but this is not to say the the 16F15323 will work. I have tried and tested the 16F15356 and 16F15355 - both work.

        If I use HighSpeed then I do get 0 returned but this would make sense - so, do try LowSpeed

        #define ADSpeed LowSpeed 
        
         
  • Frank

    Frank - 2017-12-05

    I tried this at the moment (with and without your GCB Optimisation) - both with no success - its always the same result: The output is always "0" or "512" after a new powering - changing the voltage has no effect during runtime:

    '*** Initialisation ***
    
    'Select chip model and speed
    #chip 16F15323,32
    #config mclr_off, WDT_Off
    
    #define ADSpeed LowSpeed
    #define AD_Delay 4 10us
    
    
    #define DEBUG_TRANS  PORTC.1    'TxD Pin for debugging
    
    '*** Config Software-UART ***
    Dir DEBUG_TRANS Out
    #define SendAHigh Set DEBUG_TRANS ON
    #define SendALow  Set DEBUG_TRANS OFF
    InitSer 1, r19200, 1+WaitForStart, 8, 1, None, Normal
    Set DEBUG_TRANS ON
    
    SerPrint 1, " PIC 16f15323"
    
    SerSend 1, 13  ' "Carriage Return"
    SerSend 1, 10  ' "Line Feed"
    
    dir porta.0 out
    do
      SerPrint 1,readad10(AN2)
      SerSend 1, 13  ' "Carriage Return"
      SerSend 1, 10  ' "Line Feed"
      wait 200 ms
      porta.0 = ! porta.0
    loop
    
    End
    
     
  • Anobium

    Anobium - 2017-12-05

    Unless someone has got an insight - wait.. but! there are lots of smarted folks than me maybe we are missing the obvious It will take a few days for the chip to arrive then I can test on the same chip.

    Really puzzled, I checked the errata - nothing there. I also checked using MPLAB-IDE our code looks same.

    As William Roth always tells me... there is nothing like real silicon!

     
  • Frank

    Frank - 2017-12-05

    Yes, I found only a problem with the compare module in the errata. This chip has different reference sources and internal temperature sensor - are you sure that all settings are automatically set correctly? I have problems to understand all the settings in the datasheet - otherwise I would have tried to configure the chip manually...

     
    • Anobium

      Anobium - 2017-12-05

      Yes - I thinking things are correctly, I wrote major parts of the library. I will be corrected if it is incorrect by folks which means we all benefit.

      What is really puzzling me the same family chips work.

      Post a photo of you board etc. Whilst I wait for a chip let us look at the board/layout. I have a 10k pot with the wiper connected to the Pic port, 0v and 5v are connect to the other connections of the pot. Like this i also have 5v and 0v to the PIC with a cap between 5v and 0v for decoupling. What is your layout?

       
  • Frank

    Frank - 2017-12-05

    Hi Evan,
    thank you very much for your effort!
    I have in the moment a 4K7 between Pin RA2 and GND and a second 4K7 to 7.5V which I connect to RA2 when required. I measure about 3.8V to RA2 with both resistors.
    The PIC is supplied with 5V via an MCP1702. At the end, everything together should become a battery-operated application which only takes one measurement every minute.
    I should have enough capacitors on my MCP1702 and a 100nF between Vcc and GND on my PIC.

     
    • Anobium

      Anobium - 2017-12-05

      Ok. Sounds ok to me. At no time have you applied 7.5 to the chip?

      I will wait till I get a chip to help further unless someone else spot an error.

       
  • Frank

    Frank - 2017-12-05

    No - there was not more than 4.3V on RA2. Thanks again!

     
    • Anobium

      Anobium - 2017-12-05

      Can you check that you have a common 0v rail between the chip and the pot.

      A foto of the setup would help.

       
  • Frank

    Frank - 2017-12-06

    Photo is a problem at the moment...
    The board was designed for an 8-pin chip, but I had to change to a 14-pin chip...
    The 16F15323 is currently hung on an adapter board above the actual carrier board and is wired with individual wires.
    I'm gonna try another chip to make sure it's not damaged.

     
    • Anobium

      Anobium - 2017-12-06

      Good idea.

       
  • Frank

    Frank - 2017-12-06

    I tried another chip - similar, but also strange behavior! With GND on startup I get "0" - no changing with another voltage on input. With voltage on startup I get mostly "4096", sometimes "4224" and "129"... - no changing of the output when input changed to GND...
    ...the first chip was much more stable with the "512" output...

     
    • Anobium

      Anobium - 2017-12-06

      Pull apart the board, do you have a 10k pot/pic that you can test on a bread board? Get the setup really cleaned up - there is no reason for these reading that I can think of.

       
  • Frank

    Frank - 2017-12-06

    I have no poti available at the moment - but there is only a change of the output after a new start! :-( I've never seen one behave like this before on an ADC...

     
    • Anobium

      Anobium - 2017-12-06

      Let us wait till I get my chip. A few days to go.

       
1 2 3 > >> (Page 1 of 3)

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.