# ADC - tsen

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

This demo mainly demonstrates measuring the voltage difference of the diode through ADC
            and calculating the ambient temperature.

## Software implementation

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

    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).

    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 = false;
    cfg.continuous_conv_mode = false;
    cfg.differential_mode = false;
    cfg.resolution = ADC_RESOLUTION_16B;
    cfg.vref = ADC_VREF_2P0V;
    
    struct qcc74x_adc_channel_s chan;
    
    chan.pos_chan = ADC_CHANNEL_TSEN_P;
    chan.neg_chan = ADC_CHANNEL_GND;
    
    qcc74x_adc_init(adc, &cfg);Copy to clipboard

- Get the `adc` handle, initialize the ADC configuration (the reference
                voltage must be set to 2.0 V), and set the ADC sampling frequency to 500K.

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

- Configure ADC channel

    qcc74x_adc_tsen_init(adc, ADC_TSEN_MOD_INTERNAL_DIODE);Copy to clipboard

- Turn on the tsen function and use the internal diode to measure the voltage
                value.

     for (i = 0; i < 50; i++) {
            average_filter += qcc74x_adc_tsen_get_temp(adc);
            qcc74x_mtimer_delay_ms(10);
        }
    
        printf("temp = %d\r\n", (uint32_t)(average_filter / 50.0));
        average_filter = 0;Copy to clipboard

- Call `qcc74x_adc_tsen_get_temp(adc)` to get the ambient temperature
                value calculated by ADC tsen.

## Experimental phenomena

Prints the calculated ambient temperature.

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

Last Published: Feb 10, 2025

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