the pin assignments for the
PIC32MM0064GLP028 peripherals that we have
previously activated are displayed. The most
recent pin assignment is AN0, which happens to
be the pin we selected for our ADC analog
input. The name of pin RA0 (AN0) is user
selectable and is named within the pin module
window shown in Screenshot 4.
Our SYSTEM_Initialize function list is growing
with the addition of the ADC peripheral to our
project mix:
void SYSTEM_Initialize(void)
{
PIN_MANAGER_Initialize();
OSCILLATOR_Initialize();
INTERRUPT_Initialize();
ADC1_Initialize();
UART1_Initialize();
INTERRUPT_GlobalEnable();
}
In addition, two new files — adc1.c and
adc1.h — have been automatically added to our
■ SCREENSHOT 3. Setting up an ADC is just a couple of clicks of
finger work. Once the ADC parameters are fed into the MPLAB Code
Configurator GUI, an analog input pin can be selected from the Code
Configurator pin module.
MPLAB X PIC32MM0064GLP028 project. A
complement of ADC driver functions was also
generated:
void ADC1_Initialize (void);
void ADC1_Start(void);
void ADC1_Stop(void);
uint16_t ADC1_ConversionResultBufferGet
(uint16_t *buffer);
uint16_t ADC1_ConversionResultGet(void);
bool ADC1_IsConversionComplete( void );
void ADC1_ChannelSelect( ADC1_CHANNEL
channel );
void ADC1_Tasks(void);
As you would expect, the MPLAB Code
Configurator kindly provided some example
code. Here’s a generic ADC sample sequence
int conversion;
ADC1_Initialize();
ADC1_ChannelSelect(AN1_Channel);
ADC1_Start();
//Provide Delay
for(int i=0;i <1000;i++)
{
}
■ SCREENSHOT 4. The Pin Manager display is always accessible.
Once you select a pin in the Pin Manager or via a peripheral
assignment, you can transition to the pin module window to
configure the selected pin’s behavior and human-readable name.
ADC1_Stop();
while(!ADC1_IsConversionComplete())
{
ADC1_Tasks();
}
conversion = ADC1_ConversionResultGet();
void ADC1_Start(void)
{
AD1CON1bits.SAMP = 1;
}
void ADC1_Stop(void)
{
AD1CON1bits.SAMP = 0;
}
uint16_t ADC1_ConversionResultGet(void)
{
return ADC1BUF0;
}
Most of the ADC driver functions are short and sweet.
Added sweetness is that you didn’t have to write one
single line of code to implement them:
bool ADC1_IsConversionComplete( void )
September 2016 53