全志 f1200s ADC问题,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);
}
离线
还有个adc读键盘的 触屏应该也是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); }
感谢大神,我试试下
离线
还有个adc读键盘的 触屏应该也是adc
我没找到相关的案例的,试试楼上看看
离线