找回密码
 立即注册

微信扫码登录

查看: 135|回复: 1

[ADC] 用的测试代码,电压没有输出

[复制链接]

5

主题

0

回帖

37

积分

英勇黄铜

积分
37
发表于 2025-9-23 10:39:13 | 显示全部楼层 |阅读模式 来自 陕西西安
Information
说明:   建议参照本版块置顶帖内容输入必要信息
芯片型号: -
驱动SDK版本: V4.0.1
用的测试代码,PB4接3.3V没有电压输出

void adc_gpio_ain_init(void)
{
        //set misc channel en,  and adc state machine state cnt 2( "set" stage and "capture" state for misc channel)
        adc_set_chn_enable_and_max_state_cnt(ADC_MISC_CHN, 2);          //set total length for sampling state machine and channel

        //set "capture state" length for misc channel: 240
        //set "set state" length for misc channel: 10
        //adc state machine  period  = 24M/250 = 96K, T = 10.4 uS
        adc_set_state_length(240, 0, 10);          //set R_max_mc,R_max_c,R_max_s


        //set misc channel use differential_mode (telink advice: only differential mode is available)
        //single mode adc source, PB4 for example: PB4 positive channel, GND negative channel
        gpio_set_func(GPIO_PB4, AS_GPIO);
        gpio_set_input_en(GPIO_PB4, 0);
        gpio_set_output_en(GPIO_PB4, 0);
        gpio_write(GPIO_PB4, 0);
        adc_set_ain_channel_differential_mode(ADC_MISC_CHN, B4P, GND);


        //set misc channel resolution 14 bit
        //notice that: in differential_mode MSB is sign bit, rest are data,  here BIT(13) is sign bit
        adc_set_resolution(ADC_MISC_CHN, RES14);  //set resolution


        //set misc channel vref 1.2V
        adc_set_ref_voltage(ADC_MISC_CHN, ADC_VREF_1P2V);                                          //set channel Vref



        //set misc t_sample 6 cycle of adc clock:  6 * 1/4M
        adc_set_tsample_cycle(ADC_MISC_CHN, SAMPLING_CYCLES_6);          //Number of ADC clock cycles in sampling phase

        //set Analog input pre-scaling 1/8
        adc_set_ain_pre_scaler(ADC_PRESCALER_1F8);
}




void app_adc_test_init(void)
{
////Step 1: power off sar adc/////////////////////////////////////////////////////////
        /******power off sar adc********/
        adc_power_on_sar_adc(0);
//////////////////////////////////////////////////////////////////////////////////////





////Step 2: Config some common adc settings(user can not change these)/////////////////
        /******enable signal of 24M clock to sar adc********/
        adc_enable_clk_24m_to_sar_adc(1);

        /******set adc sample clk as 4MHz******/
        adc_set_sample_clk(5); //adc sample clk= 24M/(1+5)=4M

        /******set adc L R channel Gain Stage bias current trimming******/
        adc_set_left_gain_bias(GAIN_STAGE_BIAS_PER100);
        adc_set_right_gain_bias(GAIN_STAGE_BIAS_PER100);
////////////////////////////////////////////////////////////////////////////////////////





////Step 3: Config adc settings  as needed /////////////////////////////////////////////

        adc_gpio_ain_init();


////////////////////////////////////////////////////////////////////////////////////////



////Step 4: power on sar adc/////////////////////////////////////////////////////////
        /******power on sar adc********/
        adc_power_on_sar_adc(1);
////////////////////////////////////////////////////////////////////////////////////////
}



u16 Adc_cur_rawData;   //unit: m V
u16 Adc_raw_data[256];
u8  Adc_raw_datIndex = 0;



//just for display, fake data
u32 Adc_cur_vol_oct; //debug
u16 Adc_cal_vol_oct[256];
u8  Adc_cal_vol_octIndex= 0;



u32 tick_adc_sample = 0;
void app_adc_test_start(void)
{



        if(clock_time_exceed(tick_adc_sample, 200000)){
                tick_adc_sample = clock_time();


                Adc_cur_rawData =  adc_sample_and_get_result();

                Adc_raw_data[Adc_raw_datIndex ++]  = Adc_cur_rawData;


//debug
                Adc_cur_vol_oct =   (Adc_cur_rawData/1000)<<12 | ((Adc_cur_rawData/100)%10)<<8 \
                                                      | ((Adc_cur_rawData%100)/10)<<4  | (Adc_cur_rawData%10);
                Adc_cal_vol_oct[Adc_cal_vol_octIndex ++] = Adc_cur_vol_oct;
                printf("vol%d\n",Adc_cur_vol_oct);


        }
}






0

主题

24

回帖

98

积分

不屈白银

积分
98
发表于 昨天 11:47 | 显示全部楼层 来自 上海
那款芯片?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Telink forum ( 沪ICP备17008231号-1 )

GMT+8, 2025-10-12 15:13 , Processed in 0.087613 second(s), 21 queries .

Powered by Telink 隐私政策

泰凌微电子版权所有 © 。保留所有权利。 2024

快速回复 返回顶部 返回列表