
Rev.1.00 May 22 2012
REJ09B0566
4BUsage Examples
5.8 27BAnalog to Digital Converter
5.8. Analog to Digital Converter
Figure 5-10 shows an example of ADC usage. Interrupt is enabled for ADC unit 0 channels 7, which operate in the single
sample mode.
/* PDL functions */
#include "r_pdl_adc_10_library_SH7267.h"
#include "r_pdl_cpg_library_SH7267.h"
/* PDL device-specific definitions */
#include "r_pdl_definitions.h"
void ADC0_callback(void);
uint8_t adc0_complete;
void main(void)
{
uint16_t result_adc0;
/* Modify the MCU clocks */
R_CPG_Set(18E6, 144E6, 36E6, PDL_CPG_CK_2, PDL_CPG_OUT_CK_01);
/* Configure ADC channel AN1 in One shot mode */
R_ADC_10_Create( PDL_ADC_10_MODE_SINGLE |
PDL_ADC_10_CHANNELS_OPTION_7|PDL_ADC_10_INTERRUPT_ENABLE,
150E3,
ADC0_callback,
7
);
adc0_complete = 0;
/* Set ADC for conversion */
R_ADC_10_Control(PDL_ADC_10_ON);
/* Start the ADC conversion */
Start_ADC_10();
/* Wait for ADC0 to complete */
while (adc0_complete == 0);
adc0_complete = 0;
/* fetch ADC value */
R_ADC_10_Read(&result_adc0);
/* Shutdown ADC unit 0 */
R_ADC_10_Destroy(0);
while(1);
}
void ADC0_callback(void)
{
adc0_complete = 1;
Comentários a estes Manuais