Menu

ADC on 16F15323 doesn't work

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

    William Roth - 2017-12-06

    Here is what I would do ..

    Setup the PIC on a regular breadboard and get it working. This eliminates any problems related to wiring, solder blobs, or the board is being used. Then move the working (programmed) chip to the board and troubleshoot.

    I have set up 16F15355 on a breadboard with Franks code and a 10K pot and it all works fine. This tells me that there is not a problem with the compiler or with the ADC-Library.

     
    • Anobium

      Anobium - 2017-12-06

      @William. Good stuff. i am with you. Thanks for testing and posting the positive results.

       
  • Frank

    Frank - 2017-12-06

    Hi to all,

    I downloaded the trial version of PBP3 and tried this:

    DEFINE OSC 32
    
    Include "modedefs.bas"
    
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    
    adval VAR WORD ' Create adval to store result
    
    ANSELA = %00000100
    ADCON0 = %11101110
    ADCON1 = %1111000
    TRISA = %11111111 ' Set PORTA to all input
    
    Serout  PORTC.1,T9600,["16F15323",10,13] 
    
    start:
      ADCIN 2, adval ' Read channel 0 to adval
      Serout  PORTC.1,T9600,["value: ",#adval,10,13]
    goto start
    

    Ok, the oscillator runs here with 32MHz but the ADC seems to work!!!!! I get the values what I expected! "0" with a connection to GND and a slightly changing value around 50000. With an additional resistor against + I get values around 33600.
    My circuit seems to be ok!
    I have attached the asm-file with it...

     
  • Anobium

    Anobium - 2017-12-06

    OK. I am reviewing the ASM.

    Did you add to your code?

    #define ADSpeed LowSpeed
    #define AD_Delay 4 10us
    
     
  • Frank

    Frank - 2017-12-06

    Yes - it comes directly after "#config mclr_off, WDT_Off"...

     
    • Anobium

      Anobium - 2017-12-06

      What that the LST file or the ASM file you posted?

       
  • Frank

    Frank - 2017-12-06

    ...here is it!

     
    • Anobium

      Anobium - 2017-12-06

      Thanks. The ASM looks the same. There is one piece that could be in error but I would need the chip here - the dat file could be incorrect and we have something not correct.

      Wait please.

       
      • Anobium

        Anobium - 2017-12-06

        Please add this to your code, test and report back.

        #define ADReadPreReadCommand  ANSELA = 0x04 :ADCON0 = 0xee :ADCON1 = 0x78: TRISA = 0xff
        
         
  • Frank

    Frank - 2017-12-07

    Hi,
    I inserted the line directly for the loop - unfortunately no change... : - (

     
    • Anobium

      Anobium - 2017-12-07

      So, those were the settings for the registers from the other compiler. Odd

      Please to try increase read delay.

      `#define ADSpeed LowSpeed

      define AD_Delay 6 10us`

       
  • Frank

    Frank - 2017-12-07

    ...no change! This is my code at the moment:

    '*** 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
    #define ADReadPreReadCommand  ANSELA = 0x04 :ADCON0 = 0xee :ADCON1 = 0x78: TRISA = 0xff
    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-07

    You have one item commented out and the delay can/should be increased.

    #define ADSpeed LowSpeed
    #define AD_Delay 6 10us
    
     
  • Frank

    Frank - 2017-12-07

    Sorry, I misunderstood you!

    Ok, I implemented a poti (5V/GND) in my circuit and reflashed my chip with the PBP3 code - the ADC works perfectly with this PBP3 code.

    With the last GCB code I posted AND with your last changes (#define ADSpeed LowSpeed/#define AD_Delay 6 10us) I GET ALWAYS "0"!!!

    When I programmed the µC with the GCB code, I had the potentiometer with the PBP code set to +5V => value of approx. 65400.
    After reprogramming with the GCB code, the output remained at 65400!!
    Only since the restart only "0" is displayed!

     
    • Anobium

      Anobium - 2017-12-07

      Whilst we wait for a chip here.

      Try these things - this is what I will do when the chip arrives.... in the other compiler, print out the values of ANSELA, ADCON0 ADCON1 and TRISA. What these values?

       
  • Frank

    Frank - 2017-12-07

    I get this back after inserting this:

    Serout PORTC.1,T9600,["ANSELA: ",#ANSELA,10,13]
    Serout PORTC.1,T9600,["ADCON0: ",#ADCON0,10,13]
    Serout PORTC.1,T9600,["ADCON1: ",#ADCON1,10,13]
    Serout PORTC.1,T9600,["TRISA: ",#TRISA,10,13]

    Output:

    ANSELA: 4
    ADCON0: 9
    ADCON1: 112
    TRISA: 63

     
    • Anobium

      Anobium - 2017-12-07

      Sorry, did you insert after reading the ADC? I need the values after the read operation.

       
  • Frank

    Frank - 2017-12-07

    Ok, I changed the values from GCB to the values from PBP - no change! It seems it is another register which is wrong...

     
    • Anobium

      Anobium - 2017-12-07

      What did you change?

       
  • Frank

    Frank - 2017-12-07

    I read it in a loop. Now I changed it to:

    start:
      ADCIN 2, adval ' Read channel 0 to adval
      Serout  PORTC.1,T9600,["value: ",#adval,10,13]
    
      Serout  PORTC.1,T9600,["ANSELA: ",#ANSELA,10,13]
      Serout  PORTC.1,T9600,["ADCON0: ",#ADCON0,10,13]
      Serout  PORTC.1,T9600,["ADCON1: ",#ADCON1,10,13]
      Serout  PORTC.1,T9600,["TRISA: ",#TRISA,10,13]
    goto start
    

    => same values!

    I changed my GCB file to:

    #define ADReadPreReadCommand  ANSELA = 0x04 :ADCON0 = 0x09 :ADCON1 = 0x70: TRISA = 0x3f
    
     
    • Anobium

      Anobium - 2017-12-07

      ADCON1 set to that value is meaningless This would set the ADC Conversion Clock Select bits to a ADCRC (dedicated RC oscillator), so, they are reseting the register after reading.

      This is hard without a chip, but,

      #define ADReadPreReadCommand ADCON0 = 0x09 
      

      I have sent you a Personal Message - so, we can chat via Google Chat. This is painful.

       
  • Frank

    Frank - 2017-12-07

    Silly question: ...where is here my personal message folder?
    I have sent you a mail - your address is still the same?

     
  • Frank

    Frank - 2017-12-07

    Sorry, I have no Google account... - I mailed you again...

     
  • William Roth

    William Roth - 2017-12-09

    Hi Frank,

    We have found the problem. There is an incorrect bitname in the chip datafile for 16F15323. This has been corrected in the latest AD-H library.

    Please download and install the new AD.H library SourceForge ==> . HERE

    .
    Please let us know the result

    William

     

    Last edit: William Roth 2017-12-09
<< < 1 2 3 > >> (Page 2 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.