Author | Stef Mientki, Copyright © 2002..2008, all rights reserved. |
Adapted-by | Sebastien Lelong, Rob Hamerling. |
Compiler | 2.4o |
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
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.
adc_read_high_res(byte in adc_chan) return word
adc_read(byte in adc_chan) return word
adc_read_low_res(byte in adc_chan) return byte
const bit _ADC_JUSTIFY_RIGHT = 1
constants
var byte adc_conversion_delay
Time to have the analog signal converted to a digital value. Value is calculated in _adc_init_acquisition_delay() and used in _adc_read().
const bit _ADC_JUSTIFY_LEFT = 0
constants for justification selection
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()
_adc_init_acquisition_delay()
Title: Calculation of acquisition delay Arguments: (none) Returns: nothing Notes: result is stored in global variable _adc_conversion_delay
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
_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).
12f675 | 12f675_12leds.jal |
12f683 | 12f683_pwm_adc.jal |
16f1827 | 16f1827_adc.jal |
16f690 | 16f690_adc_lowres.jal |
16f723 | 16f723_adc_independent.jal |
16f73 | 16f73_adc_dependent.jal |
16f767 | 16f767_pwm_adc.jal |
16f77 | 16f77_adc_lowres.jal |
16f876a | 16f876a_adc.jal |
16f877 | 16f877_adc.jal |
16f877 | 16f877_adc_dependent.jal |
16f877a | 16f877a_adc_dependent.jal |
16f88 | 16f88_adc_lowres.jal |
16f88 | 16f88_adc_highres.jal |
16f88 | 16f88_adc_independent.jal |
16f886 | 16f886_pwm_adc_freq.jal |
16f886 | 16f886_pwm_adc_res.jal |
18f14k50 | 18f14k50_adc_independent.jal |
18f2450 | 18f2450_adc_dependent.jal |
18f2520 | 18f2520_adc_dependent.jal |
18f2550 | 18f2550_adc_dependent.jal |
18f2620 | 18f2620_adc_dependent.jal |
18f452 | 18f452_adc_dependent.jal |
18f4550 | 18f4550_adc_dependent.jal |
18f4550 | 18f4550_dynamic_adc.jal |
18f4550 | 18f4550_adc.jal |
18f4620 | 18f4620_adc_dependent.jal |