您尚未登录。

楼主 #1 2021-01-14 15:24:23

sawgsxiao
会员
注册时间: 2020-07-15
已发帖子: 2
积分: 2

全志 f1200s ADC问题

全志 f1200s ADC问题,adc 怎么用,没有相关的资料,请大神指点,求助

离线

#2 2021-01-14 18:13:05

sjshe3326
会员
注册时间: 2020-10-19
已发帖子: 125
积分: 69.5

Re: 全志 f1200s ADC问题

可用的测试代码如下

 //------------------------------------------------------//
    // ADC input test 
    #if(0)
    {
        adc_init();
        printf("adc test init OK. \n\r");
        delay_s();
        i = 0;
        
        while(1)
        {
            delay_s();
            u32_t v1 = adc_f1c100s_read(ADC_CHANNEL_FMINL);
            delay_s();
            u32_t v2 = adc_f1c100s_read(ADC_CHANNEL_FMINR);  
            delay_s();
            u32_t v3 = adc_f1c100s_read(ADC_CHANNEL_LINL);  
            delay_s();        
            u32_t v4 = adc_f1c100s_read(ADC_CHANNEL_MIC);    
            printf("ADC: %08X, %08X, %08X, %08X \n\r", v1,v2,v3,v4);
        }
    }
    #endif

u32_t adc_f1c100s_read(int channel)
{
    u32_t mixerReg = read32(ADC_BAISADDR + ADC_MIXER_CTRL) & ~(0x1f << 8);
    switch (channel) 
    {
        case ADC_CHANNEL_FMINL:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 12));
            break;
        case ADC_CHANNEL_FMINR:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 11));
            break;
        case ADC_CHANNEL_LINL:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 10));
            break;
        case ADC_CHANNEL_MIC:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 13));
            break;
        default:
            // mute all
            break;
    }
    
    udelay();  // wait for internal filter to be stable

    // FIFO flush
    write32(ADC_BAISADDR + ADC_FIFOC, read32(ADC_BAISADDR + ADC_FIFOC) | (1 << 0));
    while( (read32(ADC_BAISADDR + ADC_FIFOS) & (1 <<23))==0);
    
    // by default, 0V = -24000 and VRA = 0.
    // make 0V = 0 and vreference = 65535.
    int val = (read32(ADC_BAISADDR + ADC_RXDATA));// >> 16);

    return (u32_t)val;
}

void adc_init(void)
{
	
    // ADC打开时钟 //
    write32( 0x01C20008, (read32(0x01C20008) | (1<<31)) );
    write32( 0x01C20068, (read32(0x01C20068) | (1<<0)) );
    write32( 0x01C20140, (read32(0x01C20140) | (1<<31)) );
    udelay(); 
    write32( 0x01C202D0, (read32(0x01C202D0) | (1<<0)) );
    udelay();
    
    //24kHz采样率 ,// digital enable // fifo mode 0 delay 0 8fifo 16bit mono
	u32_t regVal = 	(2 << 29) | (1 <<28) | (0xf << 8) | (1 << 7);
    write32(ADC_BAISADDR + ADC_FIFOC, regVal);


    // ADC enable gain 0  all mute
	regVal = (1 << 31) | (3<<24) | (3<<16)| (1 <<14) | (1<<7) | (1<<3) | (0 << 0); 
    write32(ADC_BAISADDR + ADC_MIXER_CTRL, regVal);
    
}

离线

#3 2021-01-14 18:27:57

david
会员
注册时间: 2018-03-05
已发帖子: 393
积分: 324.5

Re: 全志 f1200s ADC问题

还有个adc读键盘的 触屏应该也是adc

离线

楼主 #4 2021-01-15 02:04:31

sawgsxiao
会员
注册时间: 2020-07-15
已发帖子: 2
积分: 2

Re: 全志 f1200s ADC问题

sjshe3326 说:

可用的测试代码如下

 //------------------------------------------------------//
    // ADC input test 
    #if(0)
    {
        adc_init();
        printf("adc test init OK. \n\r");
        delay_s();
        i = 0;
        
        while(1)
        {
            delay_s();
            u32_t v1 = adc_f1c100s_read(ADC_CHANNEL_FMINL);
            delay_s();
            u32_t v2 = adc_f1c100s_read(ADC_CHANNEL_FMINR);  
            delay_s();
            u32_t v3 = adc_f1c100s_read(ADC_CHANNEL_LINL);  
            delay_s();        
            u32_t v4 = adc_f1c100s_read(ADC_CHANNEL_MIC);    
            printf("ADC: %08X, %08X, %08X, %08X \n\r", v1,v2,v3,v4);
        }
    }
    #endif

u32_t adc_f1c100s_read(int channel)
{
    u32_t mixerReg = read32(ADC_BAISADDR + ADC_MIXER_CTRL) & ~(0x1f << 8);
    switch (channel) 
    {
        case ADC_CHANNEL_FMINL:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 12));
            break;
        case ADC_CHANNEL_FMINR:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 11));
            break;
        case ADC_CHANNEL_LINL:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 10));
            break;
        case ADC_CHANNEL_MIC:
            write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 13));
            break;
        default:
            // mute all
            break;
    }
    
    udelay();  // wait for internal filter to be stable

    // FIFO flush
    write32(ADC_BAISADDR + ADC_FIFOC, read32(ADC_BAISADDR + ADC_FIFOC) | (1 << 0));
    while( (read32(ADC_BAISADDR + ADC_FIFOS) & (1 <<23))==0);
    
    // by default, 0V = -24000 and VRA = 0.
    // make 0V = 0 and vreference = 65535.
    int val = (read32(ADC_BAISADDR + ADC_RXDATA));// >> 16);

    return (u32_t)val;
}

void adc_init(void)
{
	
    // ADC打开时钟 //
    write32( 0x01C20008, (read32(0x01C20008) | (1<<31)) );
    write32( 0x01C20068, (read32(0x01C20068) | (1<<0)) );
    write32( 0x01C20140, (read32(0x01C20140) | (1<<31)) );
    udelay(); 
    write32( 0x01C202D0, (read32(0x01C202D0) | (1<<0)) );
    udelay();
    
    //24kHz采样率 ,// digital enable // fifo mode 0 delay 0 8fifo 16bit mono
	u32_t regVal = 	(2 << 29) | (1 <<28) | (0xf << 8) | (1 << 7);
    write32(ADC_BAISADDR + ADC_FIFOC, regVal);


    // ADC enable gain 0  all mute
	regVal = (1 << 31) | (3<<24) | (3<<16)| (1 <<14) | (1<<7) | (1<<3) | (0 << 0); 
    write32(ADC_BAISADDR + ADC_MIXER_CTRL, regVal);
    
}

感谢大神,我试试下

离线

楼主 #5 2021-01-15 02:08:20

sawgsxiao
会员
注册时间: 2020-07-15
已发帖子: 2
积分: 2

Re: 全志 f1200s ADC问题

david 说:

还有个adc读键盘的 触屏应该也是adc

我没找到相关的案例的,试试楼上看看

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn