一、特性参数
1、专门用来用音频处理的AD芯片
2、内部固定好8K的采样速率
3、8位AD芯片
二、内部结构图
三、芯片管脚图
四、管脚功能说明
管脚名称 | 功能 |
IN0~IN7 | 数据输入端 |
ABC | 数据输入端口选择 |
ST |
ST 为转换启动信号。当ST 上跳沿时,所有内部寄存器清零;下跳沿时,开始进行A/D 转换;在转换期间,ST 应保持低电平。 |
EOC |
EOC 为转换结束信号。当EOC 为高电平时,表明转换结束;否则,表明正在进行A/D 转换 |
OE |
OE为输出允许信号,用于控制三条输出锁存器向单片机输出转换得到的数据。OE=1,输出转换得到的数据;OE=0,输出数据线呈高阻状态。D7-D0 为数字量输出线。 |
D7-D0 | 数字量输出线 |
CLK |
时钟输入信号线。因ADC0809的内部没有时钟电路,所需时钟信号必须由外界提供,通常使用频率为500KHZ |
VREF(+) | 参考电压输入正极 |
VREF(-) | 参考电压输入负极 |
五、STM32F103ZE驱动程序
#include "stm32f10x.h" #define CLK GPIO_Pin_0
//#define B GPIO_Pin_1
//#define C GPIO_Pin_2
#define ALE GPIO_Pin_4
//#define IN0 GPIO_Pin_4
#define ST GPIO_Pin_5
#define OE GPIO_Pin_6
//#define A GPIO_Pin_7 #define D0 GPIO_Pin_0
#define D1 GPIO_Pin_1
#define D2 GPIO_Pin_2
#define D3 GPIO_Pin_3
#define D4 GPIO_Pin_4
#define D5 GPIO_Pin_5
#define D6 GPIO_Pin_6
#define D7 GPIO_Pin_7
#define EOC GPIO_Pin_8 double val=0; void delay(u32 kk)
{
while(kk--);
} /*
const unsigned short CLK= GPIO_Pin_0;
const unsigned short B=GPIO_Pin_1;
const unsigned short C=GPIO_Pin_2;
const unsigned short ALE=GPIO_Pin_3;
const unsigned short IN0=GPIO_Pin_4;
const unsigned short ST=GPIO_Pin_5;
const unsigned short OE=GPIO_Pin_6;
const unsigned short A=GPIO_Pin_7; const unsigned short D0=GPIO_Pin_0;
const unsigned short D1=GPIO_Pin_1;
const unsigned short D2=GPIO_Pin_2;
const unsigned short D3=GPIO_Pin_3;
const unsigned short D4=GPIO_Pin_4;
const unsigned short D5=GPIO_Pin_5;
const unsigned short D6=GPIO_Pin_6;
const unsigned short D7=GPIO_Pin_7;
const unsigned short EOC=GPIO_Pin_8;
*/ void ad_init()
{ GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_ResetBits(GPIOA, ALE);
// GPIO_ResetBits(GPIOA, A);
// GPIO_ResetBits(GPIOA, B);
// GPIO_ResetBits(GPIOA, C);
//delay(10); GPIO_SetBits(GPIOA, ALE);
//CLK
} void adc0809_input()
{
//ST²úÉúÉÏÉýÑغÍϽµÑØ
GPIO_ResetBits(GPIOA, ST);
delay(10);
GPIO_SetBits(GPIOA,ST);
delay(10);
GPIO_ResetBits(GPIOA, ST);
delay(10);
while(GPIO_ReadInputDataBit(GPIOB, EOC)==0); GPIO_SetBits(GPIOA,OE);
val=GPIO_ReadInputDataBit(GPIOB, D0)*0x0001+
GPIO_ReadInputDataBit(GPIOB, D1)*0x0002+
GPIO_ReadInputDataBit(GPIOB, D2)*0x0004+
GPIO_ReadInputDataBit(GPIOB, D3)*0x0008+
GPIO_ReadInputDataBit(GPIOB, D4)*0x0010+
GPIO_ReadInputDataBit(GPIOB, D5)*0x0020+
GPIO_ReadInputDataBit(GPIOB, D6)*0x0040+
GPIO_ReadInputDataBit(GPIOB, D7)*0x0080; GPIO_ResetBits(GPIOA,OE); //val=val*2*0.98;
} void timer_init() //¶¨Ê±Æ÷ÖжÏÅäÖÃ
{ NVIC_InitTypeDef NVIC_InitStructure; //ÅäÖÃÖжϽṹ
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //ÅäÖÃÄÚ²¿Ê±ÖÓ
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);//¶¨Ê±Æ÷3µÄÖжϳõʼ»¯ TIM_TimeBaseStructure.TIM_Period=100; //ÓëÏÂÒ»ÐÐÓï¾äÅäºÏ£¬µ¥Æ¬»úʱÖÓÐźÅĬÈÏÇé¿öÏÂÊÇ72MHz£¬¸Ä10000Õâ¸öÊý¿ÉÒÔÉèÖÃÖжÏʱ¼ä
TIM_TimeBaseStructure.TIM_Prescaler=72; //ÕâÐÐÒ²¿ÉÒԸģ¬µ«ÊÇΪÁËÊý¾Ý·ÖÅäÇå³þ£¬»¹ÊÇÉÏÒ»ÐÐÕû°ÙÕû°ÙµØ¸Ä±È½ÏºÃ
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM3,TIM_IT_Update|TIM_IT_Trigger,ENABLE);
TIM_Cmd(TIM3, ENABLE);
} int i=1;
void TIM3_IRQHandler()
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET) //È·¶¨½øÈëÁËÕâ¸öÖжÏ
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); // Çå³ý±êÖ¾£¬±£ÏÕÆð¼ûÒª¼Ó
adc0809_input();
if(i==1)
{
GPIO_SetBits(GPIOA, GPIO_Pin_8);
i=0;
} else
{
i=1;
GPIO_ResetBits(GPIOA, GPIO_Pin_8);
}
}
} void ADC0809_Clock()
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); //PWM--->100Hz
TIM_TimeBaseStructure.TIM_Period=10;
TIM_TimeBaseStructure.TIM_Prescaler=12;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
// //PA6--->50% //?????
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse=5; //pulse????period??????
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
// //PA7--->40%
// TIM_OCInitStructure.TIM_Pulse=40;
// TIM_OC2Init(TIM3, &TIM_OCInitStructure);
// //PB0--->60%
// TIM_OCInitStructure.TIM_Pulse=60;
// TIM_OC3Init(TIM3, &TIM_OCInitStructure);
// //PB1--->80%
// TIM_OCInitStructure.TIM_Pulse=80;
// TIM_OC4Init(TIM3, &TIM_OCInitStructure); TIM_Cmd(TIM2, ENABLE);
} int main()
{ ad_init();
GPIO_SetBits(GPIOA, GPIO_Pin_3);
ADC0809_Clock();
timer_init(); while(1)
{ }
}