RX Family
ADC Module Using Firmware Integration Technology
R01AN1666EJ0220 Rev. 2.20
Page 62 of 74
Dec 01, 2016
Example 5: Multiple Channels with Interrupt Trigger and Comparator Checking (RX64M,
RX71M)
adc_cfg_t config;
adc_ch_cfg_t ch_cfg;
adc_cmpwin_t cmpwin;
/* INITIALIZE MTU HERE (USED FOR TRIGGER SOURCES) */
/* OPEN UNIT 0 */
/* Clear all fields of the adc_cfg_t structure */
memset(&config, 0, sizeof(config));
config.resolution = ADC_RESOLUTION_12_BIT;
config.trigger = ADC_TRIG_SYNC_TRG0AN;
config.priority = 4;
config.add_cnt = ADC_ADD_OFF;
config.alignment = ADC_ALIGN_RIGHT;
config.clearing = ADC_CLEAR_AFTER_READ_OFF;
R_ADC_Open
(0
,
ADC_MODE_SS_MULTI_CH, &config, MyCallback);
/* CONFIGURE SCAN OF CHANNELS 3-5 */
/* Clear all fields of the adc_ch_cfg_t structure */
memset(&ch_cfg, 0, sizeof(ch_cfg));
ch_cfg.chan_mask = ADC_MASK_CH3 | ADC_MASK_CH4 | ADC_MASK_CH5;
ch_cfg.diag_method = ADC_DIAG_OFF;
ch_cfg.anex_enable = false;
ch_cfg.sample_hold_mask = 0;
R_ADC_Control
(0, ADC_CMD_ENABLE_CHANS, &ch_cfg);
/* HAVE COMPARATOR CHECK ON CHANNELS 3-4 FOR DROPPING BELOW 1.65V */
/* Clear all fields of the adc_cmpwin_t structure */
memset(&cmpwin, 0, sizeof(cmpwin));
cmpwin.compare_mask = ADC_MASK_CH3 | ADC_MASK_CH4;
cmpwin.inside_window_mask = 0; // condition met when below level
cmpwin.level_lo = 0x7FF; // 12-bit 3.3V=0xFFF,
1.65V=0x7FF
cmpwin.int_priority = 3;
R_ADC_Control
(
0, ADC_CMD_EN_COMPARATOR_LEVEL, &cmpwin
);
/* ENABLE TRIGGERS */
R_ADC_Control
(0
,
ADC_CMD_ENABLE_TRIG, NULL);
/* INTERRUPT OCCURS UPON SCAN COMPLETION */
:
/* Callback called from interrupt level: */
void MyCallback(void *p_args)