How do you chose ADCIN channel in this case


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,956

    Question How do you chose ADCIN channel in this case

    PIC 16F18877 at 32MHz with FOSC/128 (as per table 23-1 on p. 331) and right-justified results.

    I'd like to use E0:

    Name:  ADCIN channel.png
Views: 48
Size:  48.3 KB


    HPWM backlight to LCD does work, I see it briefly on start-up using default value.

    Code:
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
    
    DEFINE  ADC_BITS 10                 ' 10-bit Analog to digital
                                            
    DEFINE  LCD_DREG      PORTD         ' Set LCD data port
    DEFINE  LCD_DBIT      4             ' Set starting data bit
    DEFINE  LCD_RSREG     PORTB         ' Set LCD register select port
    DEFINE  LCD_RSBIT     4             ' Set LCD register select bit
    DEFINE  LCD_EREG      PORTB         ' Set LCD enable port
    DEFINE  LCD_EBIT      0             ' Set LCD enable bit
    DEFINE  LCD_BITS      4             ' Set LCD bus size
    DEFINE  LCD_LINES     4             ' Set number of lines on LCD
    DEFINE  LCD_COMMANDUS 1000          ' Set command delay time in microseconds
    DEFINE  LCD_DATAUS    50            ' Set data delay time in microseconds
    
    define  CCP1_REG     0              ' Must clear unused CCP pins or else unpredictable results
    DEFINE  CCP1_BIT     0
    define  CCP2_REG     0
    DEFINE  CCP2_BIT     0
    define  CCP3_REG     PORTD          ' PWM Pulse out to LCD backlight
    DEFINE  CCP3_BIT     1
    define  CCP4_REG     0              ' Must clear unused CCP pins or else unpredictable results
    DEFINE  CCP4_BIT     0
    define  CCP5_REG     0
    DEFINE  CCP5_BIT     0
    
    RB5PPS = 0                          ' Disable CCP3
    
    ADCON0 = %10000100                  ' ADC CONTROL REGISTER 0
    '   bit 7   ADON: ADC Enable bit
    '        --->   1 = ADC is enabled
    '               0 = ADC is disabled
    '   bit 6   ADCONT: ADC Continuous Operation Enable bit
    '               1 = ADGO is retriggered upon completion of each conversion trigger until ADTIF is set (if ADSOI is
    '                   set) or until ADGO is cleared (regardless of the value of ADSOI)
    '               0 = ADGO is cleared upon completion of each conversion trigger
    '   bit 5   Unimplemented: Read as ‘0’
    '   bit 4   ADCS: ADC Clock Selection bit
    '               1 = Clock supplied from FRC dedicated oscillator
    '               0 = Clock supplied by FOSC, divided according to ADCLK register
    '   bit 3   Unimplemented: Read as ‘0’
    '   bit 2   ADFRM0: ADC results Format/alignment Selection
    '        --->   1 = ADRES and ADPREV data are right-justified
    '               0 = ADRES and ADPREV data are left-justified, zero-filled
    '   bit 1   Unimplemented: Read as ‘0’
    '   bit 0   ADGO: ADC Conversion Status bit
    '               1 = ADC conversion cycle in progress. Setting this bit starts an ADC conversion cycle. The bit is
    '                   cleared by hardware as determined by the ADCONT bit
    '               0 = ADC conversion completed/not in progress
    
    ADCLK = %00111111                   ' ADC CLOCK SELECTION REGISTER
    '   bit 7-6 Unimplemented: Read as ‘0’
    '   bit 5-0 ADCCS<5:0>: ADC Conversion Clock Select bits
    '        --->   111111 = FOSC/128
    '               111110 = FOSC/126
    '               111101 = FOSC/124
    '                  •
    '               000000 = FOSC/2
    
    ADPCH = %00100000                   ' ADC POSITIVE CHANNEL SELECTION REGISTER
    '   bit 7-6 Unimplemented: Read as ‘0’
    '   bit 5-0 ADPCH<5:0>: ADC Positive Input Channel Selection bits
    '               111111 = Fixed Voltage Reference (FVR)
    '               111110 = DAC1 output
    '               111101 = Temperature Indicator
    '               111100 = AVSS (Analog Ground)
    '               111011 = Reserved. No channel connected.
    '               •
    '               •
    '               •
    '               100010 = ANE2       * 16F18877 only
    '               100001 = ANE1       * 16F18877 only
    '        --->   100000 = ANE0       * 16F18877 only
    '               011111 = AND7       * 16F18877 only
    '               011110 = AND6       * 16F18877 only
    '               011101 = AND5       * 16F18877 only
    '               011100 = AND4       * 16F18877 only
    '               011011 = AND3       * 16F18877 only
    '               011010 = AND2       * 16F18877 only
    '               011001 = AND1       * 16F18877 only
    '               011000 = AND0       * 16F18877 only
    '               010111 = ANC7
    '               010110 = ANC6
    '               010101 = ANC5
    '               010100 = ANC4
    '               010011 = ANC3
    '               010010 = ANC2
    '               010001 = ANC1
    '               010000 = ANC0
    '               001111 = ANB7
    '               001110 = ANB6
    '               001101 = ANB5
    '               001100 = ANB4
    '               001011 = ANB3
    '               001010 = ANB2
    '               001001 = ANB1
    '               001000 = ANB0
    '               000111 = ANA7
    '               000110 = ANA6
    '               000101 = ANA5
    '               000100 = ANA4
    '               000011 = ANA3
    '               000010 = ANA2
    '               000001 = ANA1
    '               000000 = ANA0
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000000
    ANSELE = %00000001                      ' Pin E0 = ADC input
    
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %10011000
    TRISD = %00001100
    TRISE = %00001001
    
    DefaultBacklight    CON 150
    
    LCD1pin             VAR PORTD.2
    LCD2pin             VAR PORTD.3
    LCD3pin             VAR PORTC.4
    LCD4pin             VAR PORTC.5
    
    ADCinput            var WORD
    
    HPWMbacklight       var BYTE
    
        Pause 200                           ' Let PIC and LCD stabilize
        ADCinput = 0
        HPWMbacklight = 0
    
        HPWM 3,DefaultBacklight,1953
        INPUT LCD1pin : INPUT LCD2pin : INPUT LCD3pin : INPUT LCD4pin
        LCDOUT $FE, 1 : Pauseus 1
        LCDOUT $FE, $80, "ADC test" : Pauseus 1
    
    Mainloop:
        adcin 7, ADCinput
        HPWMbacklight = (1023 - ADCinput) / 4       ' Inverse, then reduce from 0-1023 to 0-255
        HPWM 3,HPWMbacklight,1953
      GOTO Mainloop
    end

    I tried several:

    ADCIN 2, ADCinput ' started counting from 0 at E2
    ADCIN 3, ADCinput ' started counting from 1 at E2
    ADCIN 7, ADCinput ' started counting from 0 at the top
    ADCIN 8, ADCinput ' started counting from 1 at the top
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: How do you chose ADCIN channel in this case

    I'd like to use E0:
    why would it not be 32 like it says ? 0b100000 = ANE0
    Warning I'm not a teacher

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,956


    Did you find this post helpful? Yes | No

    Default Re: How do you chose ADCIN channel in this case

    Quote Originally Posted by richard View Post
    why would it not be 32 like it says ?
    Because I'm a potato-head.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,956


    Did you find this post helpful? Yes | No

    Default Re: How do you chose ADCIN channel in this case

    Note to the next guy:

    You don't need the register if there's only the ADC channel inside it (I keep the list only as documentation for the channel numbers).

    Code:
    'ADPCH = %00000000                   ' ADC POSITIVE CHANNEL SELECTION REGISTER
    '   bit 7-6 Unimplemented: Read as ‘0’
    '   bit 5-0 ADPCH<5:0>: ADC Positive Input Channel Selection bits
    '               111111 = Fixed Voltage Reference (FVR)
    '               111110 = DAC1 output
    '               111101 = Temperature Indicator
    '               111100 = AVSS (Analog Ground)
    '               111011 = Reserved. No channel connected.
    '               •
    '               •
    '               •
    '               100010 = ANE2       * 16F18877 only
    '               100001 = ANE1       * 16F18877 only
    '               100000 = ANE0       * 16F18877 only
    '               011111 = AND7       * 16F18877 only
    '               011110 = AND6       * 16F18877 only
    '               011101 = AND5       * 16F18877 only
    '               011100 = AND4       * 16F18877 only
    '               011011 = AND3       * 16F18877 only
    '     26 --->   011010 = AND2       * 16F18877 only
    '     25 --->   011001 = AND1       * 16F18877 only
    '               011000 = AND0       * 16F18877 only
    '               010111 = ANC7
    '               010110 = ANC6
    '               010101 = ANC5
    '               010100 = ANC4
    '               010011 = ANC3
    '               010010 = ANC2
    '               010001 = ANC1
    '               010000 = ANC0
    '               001111 = ANB7
    '               001110 = ANB6
    '               001101 = ANB5
    '               001100 = ANB4
    '               001011 = ANB3
    '               001010 = ANB2
    '               001001 = ANB1
    '               001000 = ANB0
    '               000111 = ANA7
    '               000110 = ANA6
    '               000101 = ANA5
    '               000100 = ANA4
    '               000011 = ANA3
    '               000010 = ANA2
    '               000001 = ANA1
    '               000000 = ANA0

    You only need to declare the channel in the ADCIN command:

    Code:
            ADCIN 26, ADCinput
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,970


    Did you find this post helpful? Yes | No

    Default Re: How do you chose ADCIN channel in this case

    I think this was always the case with the integrated ADCIN command of the PBP.

    Then you can always mess with the registers if your are brave enough!

    Ioannis

Similar Threads

  1. Best way to shut down HPWM channel?
    By LetTheSmokeOut in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th January 2010, 22:01
  2. 16-Channel LED Drivers
    By Sponge Bob in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 16th February 2009, 04:48
  3. Multiplexer channel selection
    By Castor in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 19th May 2008, 10:51
  4. I need Help to Connect P-Channel Mosfet
    By jetpr in forum Schematics
    Replies: 1
    Last Post: - 6th February 2006, 12:06
  5. 16F819 ADCIN Channel Select?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th April 2005, 18:31

Members who have read this thread : 6

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts