Menu

PIC16F1788 ADC Patch

2014-03-07
2014-03-07
  • Chuck Hellebuyck

    I saw that GCB had support for the new PIC16F1788 so I decided to test it on my CHIPINO module. Everything seemed to work fine except ADC.
    It would report a constant zero no matter what the voltage was on the ADC pin.
    So I pulled up the data sheet and saw the 16F1788 added a Differential Channel Selection feature allowing the negative reference to come from a pin other than -Vref.
    This added a setup to the ADCON2 register and unfortunately defaults to the AN0 pin instead of defaulting to the ADNREF setting.

    So I added one line to the top of my program to set the ADCON2 to the ADNREF setting.

    ADCON2 = 15 
    

    Fortunately this worked perfect and the ADC is working again.

    Maybe Hugh or Evan can fix this in a future update.
    Until then, this simple one line patch seems to fix the issue.

    Here is the simple code example I tested using the PICkit 2 USART Terminal window for communication.

    'This program reads the potentiometer on AN0 and Serially sends results to PICkit 2  
    'USART terminal. Using the CHIPINO module with 16 MHz Crystal. 
    
    'Chip Settings 
    #chip 16F1788,16 
    
    'Serial settings 
    #define SerInPort PORTB.6 
    #define SerOutPort PORTB.7 
    #define SendAHigh Set SerOutPort off 
    #define SendALow Set SerOutPort on 
    #define RecAHigh SerInPort off 
    #define RecALow SerInPort on 
    
    'Set pin directions 
    Dir SerOutPort Out 
    Dir SerInPort In 
    
    InitSer 1, r9600, 1+WaitForStart, 8, 1, none, invert 
    
    ADCON2 = 15 ' Set Negative Reference Setting to ADNREF in ADCON1 
    
    Start: 
    SerPrint 1, "AN0 Reading: " 
    SerPrint 1, ReadAD(AN0) 
    SerSend 1, 13 
    SerSend 1, 10 
    
    goto Start 
    
     
  • Anobium

    Anobium - 2014-03-07

    Good work, added to the list. :-)

     

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.