User`s manual
RX62N Group, RX621 Group 5. Usage Examples
5.16. 10-bit Analog to Digital Converter
5.16.1. ADC Conversion
Figure 5-38 shows an example of ADC usage. ADC unit 0 is polled until the conversion is complete. Interrupts
are enabled for ADC unit 1, which operates in the one-cycle scan mode.
/* Peripheral driver function prototypes */
#include "r_pdl_adc_10.h"
#include "r_pdl_cgc.h"
#include "r_pdl_intc.h"
/* RPDL device-specific definitions */
#include "r_pdl_definitions.h"
volatile uint16_t adc0_result;
volatile uint16_t adc1_result[4];
void ADC1Handler(void);
void main(void)
{
/* Initialise the system clocks */
R_CGC_Set(
12E6,
96E6,
48E6,
0,
PDL_CGC_BCLK_DISABLE
);
/* Set the CPU’s Interrupt Priority Level to 0 */
R_INTC_Write(
PDL_INTC_REG_IPL,
0
);
/* Configure ADC unit 0 for single scan on pin AN1, polled */
R_ADC_10_Create(
0,
PDL_ADC_10_MODE_SINGLE | PDL_ADC_10_CHANNELS_OPTION_1,
48E6,
0.5E-6,
PDL_NO_FUNC,
0
);
/* Configure ADC unit 1 for one cycle scan on pins AN4 to AN7, interrupts */
R_ADC_10_Create(
1,
PDL_ADC_10_MODE_ONE_CYCLE_SCAN | PDL_ADC_10_CHANNELS_OPTION_4,
48E6,
0.5E-6,
ADC1Handler,
6
);
/* Start conversions on ADC units 0 and 1 */
R_ADC_10_Control(
PDL_ADC_10_0_ON | PDL_ADC_10_1_ON
);
/* Read the level on AN1 */
R_ADC_10_Read(
0,
&adc0_result
);
R20UT0084EE0112 Rev.1.12 Page 5-71
July. 16, 2014