adc

ADC hardware, built-in PIC ADC module

Author Stef Mientki, Copyright © 2002..2024, all rights reserved.
Adapted-by Sebastien Lelong, Rob Hamerling, Rob Jansen
Compiler 2.5r8

Description

Library to handle ADC peripheral, supporting low (8-bits) and high 
             (16-bits) resolution (whatever the PIC supports). Since the differences
             between the various ADC features are too different for various PICs, this
             library only provides some basic ADC features.
             The user has to do the following in the main program using the datasheet
             of the PIC that is being used:
             1) Set the used ADC pin(s) as analog input
             2) Set the refernce voltage for the ADC (default is often VDD)
             3) Set the ADC clock according to the datasheet and the target clock
                being used by the main program (FRC is safe to use)


Notes

This is a heavy refactoring/rewriting of original library of Stef Mientki.
       Deprecated functions have been removed.


Dependencies

No dependency found



Summary

Global variables/contants

Procedures

Private

Functions

Private

API details

Global variables/contants

Procedures

  • adc_init()

    Tilte:     Initialise ADC module and default parameters
    Arguments: (none)
    Returns:   nothing
    
    Initializes the PIC AD-converter, calculate aquisition time.
    

Private
  • _adc_init_acquisition_delay()

    Title:     Calculation of acquisition delay
    Arguments: (none)
    Returns:   nothing
    Notes:     result is stored in global variable _adc_conversion_delay
    
    


Functions

  • adc_read_high_res(byte in adc_chan) return word

    Title:     Analog to digital conversion returning a 16-bits value
    Arguments: channel number
    Returns:   16-bits ADC value
    Notes:     - Uses right justification
     Returns a 16-bits value of the result of ADC, of which the
    range is dependent of the supported ADC resolution of the PIC
    (can be a 8-, 10-, 12-bits value).
     When the PIC supports only 8-bits ADC resolution the
    result is the same as of adc_read_low_res().
    
    

  • adc_read_low_res(byte in adc_chan) return byte

    Title:     Analog to digital conversion returning an 8-bits value
    Arguments: Channel number
    Returns:   8-bits ADC value
    Notes:     - Uses left justification.
     Returns the 8 most significant bits of the result of ADC
    
    

Private
  • _adc_read(byte in adc_chan, bit in justify) return word

    Title:     Analog to Digital conversion of the selected channel.
    Arguments: - channel number (byte)
     justification (bit 0=left, 1=right)
    Returns:   word with ADC value
    Notes:     - When PIC supports high resolution (more than 8 bits)
    all bits of the ADC conversion are stored straight over
    from ADRESH and ADRESL.  When PIC supports only 8-bits
    resolution only the contents of ADRES are stored.
     With right justification the result is immediately
    usable as binary value.
     Left justification allows easy selection of the 8 most
    significant bits of the result, regardless which
    resolution the PIC supports (can be 8-,10 or 12-bits).
    
    



Related samples

Here are the list of samples which use this library:

12f67512f675_12leds.jal
12f68312f683_pwm_adc.jal
16f1532516f15325_adc.jal
16f182716f1827_adc.jal
16f1832316f18323_adc.jal
16f1885716f18857_adc.jal
16f69016f690_adc_lowres.jal
16f72316f723_adc_independent.jal
16f7316f73_adc_dependent.jal
16f76716f767_pwm_adc.jal
16f7716f77_adc_lowres.jal
16f876a16f876a_adc.jal
16f87716f877_adc.jal
16f87716f877_adc_dependent.jal
16f877a16f877a_adc_dependent.jal
16f8816f88_adc_lowres.jal
16f8816f88_adc_highres.jal
16f8816f88_adc_independent.jal
16f88616f886_pwm_adc_freq.jal
16f88616f886_pwm_adc_res.jal
18f14k5018f14k50_adc_independent.jal
18f245018f2450_adc_dependent.jal
18f252018f2520_adc_dependent.jal
18f255018f2550_adc_dependent.jal
18f25k2218f25k22_adc.jal
18f262018f2620_adc_dependent.jal
18f45218f452_adc_dependent.jal
18f455018f4550_adc_dependent.jal
18f455018f4550_dynamic_adc.jal
18f455018f4550_adc.jal
18f462018f4620_adc_dependent.jal