# ADC - int

Source: [https://docs.qualcomm.com/doc/80-58740-4/topic/adc-int.html](https://docs.qualcomm.com/doc/80-58740-4/topic/adc-int.html)

This demo mainly demonstrates reading the voltage value in ADC interrupt mode. The
            default scan channel 0 ~ channel 10. It should be noted that some chips may not support
            all channels.

## Hardware connection

The GPIO used in this demo refers to `board_adc_gpio_init`.

## Software implementation

For more detailed code, refer to
                    examples/peripherals/adc/adc\_int.

    board_init();Copy to clipboard

- The ADC IP clock is turned on in `board_init`, and the ADC clock
                    source and frequency division will be selected (the ADC clock must be less than
                    or equal to 500K).

    board_adc_gpio_init();Copy to clipboard

- Configure related pins as `adc` function

    adc = qcc74x_device_get_by_name("adc");
    
    /* adc clock = XCLK / 2 / 32 */
    struct qcc74x_adc_config_s cfg;
    cfg.clk_div = ADC_CLK_DIV_32;
    cfg.scan_conv_mode = true;
    cfg.continuous_conv_mode = false;
    cfg.differential_mode = false;
    cfg.resolution = ADC_RESOLUTION_16B;
    cfg.vref = ADC_VREF_3P2V;
    
    qcc74x_adc_init(adc, &cfg);Copy to clipboard

- Get the `adc` handle, initialize the ADC configuration, and set
                    the ADC sampling frequency to 500K

    qcc74x_adc_channel_config(adc, chan, TEST_ADC_CHANNELS);Copy to clipboard

- Configure ADC channel information. The number of pairs used is configurable
                    according to `TEST_ADC_CHANNELS`. Channels 0 ~ 10 are enabled by
                    default. Other channels can be selectively closed according to
                        `board_adc_gpio_init`.

    qcc74x_adc_rxint_mask(adc, false);
    qcc74x_irq_attach(adc->irq_num, adc_isr, NULL);
    qcc74x_irq_enable(adc->irq_num);Copy to clipboard

- Call `qcc74x_adc_rxint_mask` to turn on ADC conversion
                        completion interrupt
- Call `qcc74x_irq_attach` connection interrupt handler
                        function
- Call `qcc74x_irq_enable` to enable interrupts

    for (size_t i = 0; i < TEST_COUNT; i++) {
        read_count = 0;
        qcc74x_adc_start_conversion(adc);
    
        while (read_count < TEST_ADC_CHANNELS) {
            qcc74x_mtimer_delay_ms(1);
        }
        for (size_t j = 0; j < TEST_ADC_CHANNELS; j++) {
            struct qcc74x_adc_result_s result;
            printf("raw data:%08x\r\n", raw_data[j]);
            qcc74x_adc_parse_result(adc, (uint32_t *)&raw_data[j], &result, 1);
            printf("pos chan %d,%d mv \r\n", result.pos_chan, result.millivolt);
        }
        qcc74x_adc_stop_conversion(adc);
        qcc74x_mtimer_delay_ms(100);
    }Copy to clipboard

- Call `qcc74x_adc_start_conversion(adc)` to enable conversion
                        of ADC
- Call `qcc74x_adc_parse_result(adc, (uint32_t *)&raw_data[j],
                            &result, 1)` to parse the conversion result of ADC, and save
                        the parsed value to the `result` structure
- Call `qcc74x_adc_stop_conversion(adc)` to stop ADC
                        conversion

## Experimental phenomena

Print raw data, channel number and voltage value corresponding to the channel.

**Parent Topic:** [ADC](https://docs.qualcomm.com/doc/80-58740-4/topic/adc.html)

Last Published: Feb 10, 2025

[Previous Topic
ADC - dma](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/adc-dma.md) [Next Topic
ADC - poll\_diff\_mode](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/adc-poll-diff-mode.md)