Solar panel
Loading...
Searching...
No Matches
adc.c
Go to the documentation of this file.
1
24/*
25 (c) 2018 Microchip Technology Inc. and its subsidiaries.
26
27 Subject to your compliance with these terms, you may use Microchip software and any
28 derivatives exclusively with Microchip products. It is your responsibility to comply with third party
29 license terms applicable to your use of third party software (including open source software) that
30 may accompany Microchip software.
31
32 THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
33 EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
34 IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
35 FOR A PARTICULAR PURPOSE.
36
37 IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
38 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
39 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
40 HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
41 THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
42 CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
43 OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
44 SOFTWARE.
45*/
46
51#include <xc.h>
52#include "adc.h"
53#include "device_config.h"
54
56
62{
63 // set the ADC to the options selected in the User Interface
64
65 // VCFG1 VSS; VCFG0 VDD;
66 ADCON1 = 0x00;
67
68 // ADFM right; ACQT 0; ADCS FOSC/2;
69 ADCON2 = 0x80;
70
71 // ADRESL 0;
72 ADRESL = 0x00;
73
74 // ADRESH 0;
75 ADRESH = 0x00;
76
77 // GO_nDONE stop; ADCAL Normal_a/d_operation; ADON enabled; CHS AN0;
78 ADCON0 = 0x01;
79
80}
81
83{
84 // select the A/D channel
85 ADCON0bits.CHS = channel;
86 // Turn on the ADC module
87 ADCON0bits.ADON = 1;
88}
89
91{
92 // Start the conversion
93 ADCON0bits.GO_nDONE = 1;
94}
95
96
98{
99 // Start the conversion
100 return ((bool)(!ADCON0bits.GO_nDONE));
101}
102
104{
105 // Conversion finished, return the result
106 return ((adc_result_t)((ADRESH << 8) + ADRESL));
107}
108
110{
111 // select the A/D channel
112 ADCON0bits.CHS = channel;
113
114 // Turn on the ADC module
115 ADCON0bits.ADON = 1;
116
117 // Start the conversion
118 ADCON0bits.GO_nDONE = 1;
119
120 // Wait for the conversion to finish
121 while (ADCON0bits.GO_nDONE)
122 {
123 }
124
125 // Conversion finished, return the result
126 return ((adc_result_t)((ADRESH << 8) + ADRESL));
127}
128
130{
131 __delay_us(200);
132}
void ADC_SelectChannel(adc_channel_t channel)
Definition: adc.c:82
void ADC_TemperatureAcquisitionDelay(void)
Definition: adc.c:129
adc_result_t ADC_GetConversion(adc_channel_t channel)
Definition: adc.c:109
adc_result_t ADC_GetConversionResult(void)
Definition: adc.c:103
void ADC_Initialize(void)
Definition: adc.c:61
bool ADC_IsConversionDone(void)
Definition: adc.c:97
void ADC_StartConversion(void)
Definition: adc.c:90
void(* ADC_InterruptHandler)(void)
Definition: adc.c:55
adc_channel_t
Definition: adc.h:96
uint16_t adc_result_t
Definition: adc.h:72