Skip to content

Commit dd8bc5b

Browse files
author
Microchip Technology
committed
Merging into the (master) branch
1 parent 4966052 commit dd8bc5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+9883
-0
lines changed

PICIoT.X/Makefile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#
2+
# There exist several targets which are by default empty and which can be
3+
# used for execution of your targets. These targets are usually executed
4+
# before and after some main targets. They are:
5+
#
6+
# .build-pre: called before 'build' target
7+
# .build-post: called after 'build' target
8+
# .clean-pre: called before 'clean' target
9+
# .clean-post: called after 'clean' target
10+
# .clobber-pre: called before 'clobber' target
11+
# .clobber-post: called after 'clobber' target
12+
# .all-pre: called before 'all' target
13+
# .all-post: called after 'all' target
14+
# .help-pre: called before 'help' target
15+
# .help-post: called after 'help' target
16+
#
17+
# Targets beginning with '.' are not intended to be called on their own.
18+
#
19+
# Main targets can be executed directly, and they are:
20+
#
21+
# build build a specific configuration
22+
# clean remove built files from a configuration
23+
# clobber remove all built files
24+
# all build all configurations
25+
# help print help mesage
26+
#
27+
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
28+
# .help-impl are implemented in nbproject/makefile-impl.mk.
29+
#
30+
# Available make variables:
31+
#
32+
# CND_BASEDIR base directory for relative paths
33+
# CND_DISTDIR default top distribution directory (build artifacts)
34+
# CND_BUILDDIR default top build directory (object files, ...)
35+
# CONF name of current configuration
36+
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
37+
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
38+
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
39+
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
40+
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
41+
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
42+
#
43+
# NOCDDL
44+
45+
46+
# Environment
47+
MKDIR=mkdir
48+
CP=cp
49+
CCADMIN=CCadmin
50+
RANLIB=ranlib
51+
52+
53+
# build
54+
build: .build-post
55+
56+
.build-pre:
57+
# Add your pre 'build' code here...
58+
59+
.build-post: .build-impl
60+
# Add your post 'build' code here...
61+
62+
63+
# clean
64+
clean: .clean-post
65+
66+
.clean-pre:
67+
# Add your pre 'clean' code here...
68+
# WARNING: the IDE does not call this target since it takes a long time to
69+
# simply run make. Instead, the IDE removes the configuration directories
70+
# under build and dist directly without calling make.
71+
# This target is left here so people can do a clean when running a clean
72+
# outside the IDE.
73+
74+
.clean-post: .clean-impl
75+
# Add your post 'clean' code here...
76+
77+
78+
# clobber
79+
clobber: .clobber-post
80+
81+
.clobber-pre:
82+
# Add your pre 'clobber' code here...
83+
84+
.clobber-post: .clobber-impl
85+
# Add your post 'clobber' code here...
86+
87+
88+
# all
89+
all: .all-post
90+
91+
.all-pre:
92+
# Add your pre 'all' code here...
93+
94+
.all-post: .all-impl
95+
# Add your post 'all' code here...
96+
97+
98+
# help
99+
help: .help-post
100+
101+
.help-pre:
102+
# Add your pre 'help' code here...
103+
104+
.help-post: .help-impl
105+
# Add your post 'help' code here...
106+
107+
108+
109+
# include project implementation makefile
110+
include nbproject/Makefile-impl.mk
111+
112+
# include project make variables
113+
include nbproject/Makefile-variables.mk
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
2+
/**
3+
ADC1 Generated Driver File
4+
5+
@Company
6+
Microchip Technology Inc.
7+
8+
@File Name
9+
adc1.c
10+
11+
@Summary
12+
This is the generated header file for the ADC1 driver using Foundation Services Library
13+
14+
@Description
15+
This header file provides APIs for driver for ADC1.
16+
Generation Information :
17+
Product Revision : Foundation Services Library - pic24-dspic-pic32mm : v1.26
18+
Device : PIC24FJ128GA705
19+
The generated drivers are tested against the following:
20+
Compiler : XC16 1.30
21+
MPLAB : MPLAB X 3.45
22+
*/
23+
24+
/*
25+
(c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
26+
software and any derivatives exclusively with Microchip products.
27+
28+
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
29+
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
30+
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
31+
PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
32+
WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
33+
34+
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
35+
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
36+
WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
37+
BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
38+
FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
39+
ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
40+
THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
41+
42+
MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
43+
TERMS.
44+
*/
45+
46+
/**
47+
Section: Included Files
48+
*/
49+
50+
#include <xc.h>
51+
#include "adc1.h"
52+
53+
/**
54+
Section: Data Type Definitions
55+
*/
56+
57+
/* ADC Driver Hardware Instance Object
58+
59+
@Summary
60+
Defines the object required for the maintenance of the hardware instance.
61+
62+
@Description
63+
This defines the object required for the maintenance of the hardware
64+
instance. This object exists once per hardware instance of the peripheral.
65+
66+
*/
67+
typedef struct
68+
{
69+
uint8_t intSample;
70+
}
71+
72+
ADC_OBJECT;
73+
74+
static ADC_OBJECT adc1_obj;
75+
76+
/**
77+
Section: Driver Interface
78+
*/
79+
80+
81+
void ADC1_Initialize (void)
82+
{
83+
// ASAM enabled; DMABM disabled; ADSIDL disabled; DONE disabled; DMAEN disabled; FORM Absolute decimal result, unsigned, right-justified; SAMP disabled; SSRC Internal counter ends sampling and starts conversion; MODE12 10-bit; ADON enabled;
84+
85+
AD1CON1 = 0x8074;
86+
87+
// CSCNA disabled; NVCFG0 AVSS; PVCFG AVDD; ALTS disabled; BUFM disabled; SMPI Generates interrupt after completion of every sample/conversion operation; BUFREGEN disabled;
88+
89+
AD1CON2 = 0x0000;
90+
91+
// SAMC 31; EXTSAM disabled; PUMPEN disabled; ADRC RC clock; ADCS 0;
92+
93+
AD1CON3 = 0x9F00;
94+
95+
// CH0SA AN0; CH0SB AN0; CH0NB AVSS; CH0NA AVSS;
96+
97+
AD1CHS = 0x0000;
98+
99+
// CSS30 disabled; CSS29 disabled; CSS28 disabled;
100+
101+
AD1CSSH = 0x0000;
102+
103+
// CSS9 disabled; CSS8 disabled; CSS7 disabled; CSS6 disabled; CSS5 disabled; CSS4 disabled; CSS3 disabled; CSS2 disabled; CSS15 disabled; CSS1 disabled; CSS14 disabled; CSS0 disabled; CSS13 disabled; CSS12 disabled; CSS11 disabled; CSS10 disabled;
104+
105+
AD1CSSL = 0x0000;
106+
107+
// CTMEN30 disabled; CTMEN29 disabled; CTMEN28 disabled;
108+
109+
AD1CTMENH = 0x0000;
110+
111+
// VBGEN3 disabled; VBGEN2 disabled; VBGEN1 disabled;
112+
113+
ANCFG = 0x0000;
114+
115+
116+
adc1_obj.intSample = AD1CON2bits.SMPI;
117+
118+
}
119+
120+
void ADC1_Start(void)
121+
{
122+
AD1CON1bits.SAMP = 1;
123+
}
124+
void ADC1_Stop(void)
125+
{
126+
AD1CON1bits.SAMP = 0;
127+
}
128+
uint16_t ADC1_ConversionResultBufferGet(uint16_t *buffer)
129+
{
130+
int count;
131+
uint16_t *ADC16Ptr;
132+
133+
ADC16Ptr = (uint16_t *)&(ADC1BUF0);
134+
135+
for(count=0;count<=adc1_obj.intSample;count++)
136+
{
137+
buffer[count] = (uint16_t)*ADC16Ptr;
138+
ADC16Ptr++;
139+
}
140+
return count;
141+
}
142+
uint16_t ADC1_ConversionResultGet(void)
143+
{
144+
return ADC1BUF0;
145+
}
146+
bool ADC1_IsConversionComplete( void )
147+
{
148+
return AD1CON1bits.DONE; //Wait for conversion to complete
149+
}
150+
void ADC1_ChannelSelect( ADC1_CHANNEL channel )
151+
{
152+
AD1CHS = channel;
153+
}
154+
155+
uint16_t ADC1_GetConversion(ADC1_CHANNEL channel)
156+
{
157+
ADC1_ChannelSelect(channel);
158+
159+
ADC1_Start();
160+
ADC1_Stop();
161+
162+
while (!ADC1_IsConversionComplete())
163+
{
164+
}
165+
166+
return ADC1_ConversionResultGet();
167+
}
168+
169+
170+
void ADC1_Tasks ( void )
171+
{
172+
// clear the ADC interrupt flag
173+
IFS0bits.AD1IF = false;
174+
}
175+
176+
177+
/**
178+
End of File
179+
*/

0 commit comments

Comments
 (0)