Usage example
Get A/D conversion results of 1 pin 4 times. Then, calculate the average of the results.
[GUI setting example]
32-bit multiply-accumlator |
||||
MAC32bit |
Used | |||
32-bit multiply-accumlator operation setting |
Used | |||
Fixed point mode setting |
Disable | |||
Enable multiply-accumulation overflow/underflow (INTMACLOF) |
Unused |
A/Dconvertor |
||||
ADC |
Used | |||
A/D convertor operation setting |
Used | |||
Comparator operation setting |
Stop | |||
Resolution |
10 bits | |||
VREF(+) setting |
VDD | |||
VREF(-) setting |
VSS | |||
Trigger setting mode |
Software trigger mode | |||
Operation mode setting |
One-shot select mode | |||
|
|
|
ANI0 – ANI5 analog input selection |
ANI0 |
|
|
|
A/D channel selection |
ANI0 |
|
|
|
Conversion time mode |
Normal 1 |
|
|
|
Conversion time |
608/fCLK 25.3333(μs) |
|
|
|
Conversion result upper/lower bound value setting |
Generates an interrupt request (INTAD) when ADLL≦ADCRH≦ADUL |
|
|
|
Upper bound (ADUL) value |
255 |
|
|
|
Lower bound (ADLL) value |
0 |
|
|
|
Use A/D interrupt (INTAD) |
Unused |
[API setting example]
r_cg_main.c
/* Start user code for global. Do not edit comment generated here */
volatile mac32bit_uint64_t g_mac32bit_buf;
volatile uint16_t g_adc_fix;
volatile uint16_t g_buffer;
volatile uint8_t g_cnt;
/* End user code. Do not edit comment generated here */
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
/* Start the AD converter */
R_ADC_Start();
while (1U)
{
while (0U == ADIF)
{
;
}
ADIF = 0U;
/* Return the conversion result in the buffer */
R_ADC_Get_Result((uint16_t *)&g_buffer);
/* Caculate unsigned values in multiply-accumulation mode */
R_MAC32Bit_MACUnsigned(1U, g_buffer, (mac32bit_uint64_t *)&g_mac32bit_buf);
if ((++g_cnt) >= 4U)
{
g_cnt = 0U;
g_adc_fix = (g_mac32bit_buf.low_low >> 4U);
g_mac32bit_buf.low_low = 0U;
g_mac32bit_buf.low_high = 0U;
g_mac32bit_buf.high_low = 0U;
g_mac32bit_buf.high_high = 0U;
}
}
/* End user code. Do not edit comment generated here */
}