RX Family
ADC Module Using Firmware Integration Technology
R01AN1666EJ0220 Rev. 2.20
Page 59 of 74
Dec 01, 2016
Example 3: Grouped Channels with Interrupt Triggers, Double Trigger on Group A, and
Averaging (RX64M, RX71M, RX65x)
adc_cfg_t config;
adc_ch_cfg_t ch_cfg;
/* INITIALIZE MTU HERE (USED FOR TRIGGER SOURCES) */
/* OPEN ADC */
/* Clear all fields of each structure */
memset(&config, 0, sizeof(config));
memset(&ch_cfg, 0, sizeof(ch_cfg));
/* INITIALIZE ADC FOR GROUP SCANNING WITH DOUBLE TRIGGER
* - use synchronous trigger TRGA0N to start Group A scan; int priority 4
* - use synchronous trigger TRG0N to start Group B scan; int priority 5
* - allow each channel to be scanned four times and averaged before continuing
* - do not clear registers after reading
*/
config.resolution = ADC_RESOLUTION_8_BIT;
config.trigger = ADC_TRIG_SYNC_TRG0AN;
config.priority = 4;
config.trigger_groupb = ADC_TRIG_SYNC_TRG0EN;
config.priority_groupb= 5;
config.add_cnt = ADC_ADD_AVG_4_SAMPLES;
config.alignment = ADC_ALIGN_RIGHT;
config.clearing = ADC_CLEAR_AFTER_READ_OFF;
R_ADC_Open
(1, ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A, &config, MyCallback);
/* CONFIGURE SCAN */
/* Can only have 1 channel for double triggering, and is only channel in Group A
Have channel 8 as Group A, have 2, 3, and 9 as Group B
Perform addition/average on all channels except 9
*/
ch_cfg.chan_mask = ADC_MASK_CH8;
ch_cfg.chan_mask_groupb = ADC_MASK_CH2 | ADC_MASK_CH3 | ADC_MASK_CH9;
ch_cfg.priority_groupa = ADC_GRPA_PRIORITY_OFF;
ch_cfg.add_mask = ADC_MASK_CH8 | ADC_MASK_CH2 | ADC_MASK_CH3;
ch_cfg.diag_method = ADC_DIAG_OFF;
ch_cfg.anex_enable = false;
ch_cfg.sample_hold_mask = 0;
R_ADC_Control(1, ADC_CMD_ENABLE_CHANS, &ch_cfg);
/* After open, wait 1 us or longer before A/D conversion starts */
/* ENABLE TRIGGERS */
R_ADC_Control
(1, ADC_CMD_ENABLE_TRIG, NULL);
/* INTERRUPT OCCURS UPON SCAN COMPLETION */
/* The callback is called twice from interrupt level- once after each
* group scan completes. The order depends upon the trigger order.
*/
void MyCallback(void *p_args)
{
adc_cb_args_t *args;
uint16_t dbltrg,data2,data3,data8,data9;