adc

ADC hardware, built-in PIC ADC module

Author Stef Mientki, Copyright © 2002..2008, all rights reserved.
Adapted-by Sebastien Lelong, Rob Hamerling.
Compiler 2.4o

Description

Library to handle ADC peripheral, supporting:
- low (8-bits) and high (16-bits) resolution (whatever the PIC supports)
- ADC pin configuration
- channel selection
- clock selection
- reference voltage selection



Q: How to use it?
A: See http://justanotherlanguage.org/content/jallib/tutorials/tutorial_adc_intro



About Vref setup:
  - when ADC_NVREF = ADC_NO_VREF : there's no Vref pin used, vref is done
                     internally, using power supply (Vdd <-> Vss)
  - when ADC_NVREF = ADC_VREF_POS: there's only one Vref pin, this is Vref+
  - when ADC_NVREF = ADC_VREF_POS_NEG: two Vref pins are used, Vref+ and Vref-
  - when ADC_NVREF = ADC_VREF_NEG: there's only one Vref pin, this is Vref-
  - when ADC_NVREF = ADC_VREF_FVR: Vref pin internally connected to FVR module if present
                                   (user should setup FVRCON as desired).



A major trigger is when using ADC libs is ADC_DYNAMIC.
When declared, several parameters become dynamic and can be changed
at runtime. This includes:
   - ADC_NCHANNEL: the number of used ADC channels (dependent channels only,
      independent channels are always selected at runtime with set_analog_pin() ).
   - ADC_TEMP  Careful, computation related to temperature very approximative
   - ADC_RSOURCE


Notes

This is a heavy refactoring/rewriting of original library of Stef Mientki.
adc_channels.jal and adc_clock.jal.
The original library can be found:
   - Stef's: http://mientki.ruhosting.nl/pic-tools/jal/libs2/adc_hardware.jal
   - Jallib issue tracker: http://code.google.com/p/jallib/issues/detail?id=7
The main changes are about ADC configuration, which are essentially handled in
adc_channels.jal and adc_clock.jal.


Dependencies


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,
    by calling the correct routine according to the number of external references
    Settings are done according to the special ADC constants
    Sets analog pins to input
    Calculate aquisition time
    

  • adc_read_bytes(byte in adc_chan, byte out adc_hbyte, byte out adc_lbyte)

    Title: Deprecated procedure, replaced by function adc_read_high_res()
    
    

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(byte in adc_chan) return word

    Title: Deprecated function, replaced by adc_read_high_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
16f182716f1827_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
18f262018f2620_adc_dependent.jal
18f45218f452_adc_dependent.jal
18f455018f4550_adc_dependent.jal
18f455018f4550_dynamic_adc.jal
18f455018f4550_adc.jal
18f462018f4620_adc_dependent.jal