引用: qwer34 发表于 2018-12-6 22:44
__interrupt VectorNumber_Vtimch0 void _Sampling_Interrupt(void)
{
// clear interrupt and call oninterrupt function
我感觉应该他妈的挺简单的,不知道为什么就是搞不出来,
我用的STM32F030C8T6,利用TIM1产生PWM和定时器中断,PWM的频率设置为11KHZ;
TIM1->ARR = 2180; TIM1->PSC = 1 ;
然后定时器中断将WAV的数据转换成TIM1->CCR1的值;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InirStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //GPIOA.8
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_2); //GPIO_AF_2
NVIC_InirStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;
NVIC_InirStructure.NVIC_IRQChannelPriority = 3;
NVIC_InirStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InirStructure);
//wav采样率 24KHz = 48000KHz/(999+1)(1+1);
// 16KHz = 48000KHz/(999+1)(2+1)
// 11KHz = 48000KHz/(2180+1)(1+1)
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
//TIM_TimeBaseInitStructure.TIM_Period = 999;
// TIM_TimeBaseInitStructure.TIM_Prescaler = 2; //16K
TIM_TimeBaseInitStructure.TIM_Period = 2180;
TIM_TimeBaseInitStructure.TIM_Prescaler = 1; //11K
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//TIM_OCInitStructure.TIM_Pulse = 500; //测试
TIM_OC1Init(TIM1,&TIM_OCInitStructure);//TIM1--CH1
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);//更新中断
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);//
引用: qwer34 发表于 2018-12-6 22:44
__interrupt VectorNumber_Vtimch0 void _Sampling_Interrupt(void)
{
// clear interrupt and call oninterrupt function
我感觉应该他妈的挺简单的,不知道为什么就是搞不出来,
我用的STM32F030C8T6,利用TIM1产生PWM和定时器中断,PWM的频率设置为11KHZ;
TIM1->ARR = 2180; TIM1->PSC = 1 ;
然后定时器中断将WAV的数据转换成TIM1->CCR1的值;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InirStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //GPIOA.8
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_2); //GPIO_AF_2
NVIC_InirStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;
NVIC_InirStructure.NVIC_IRQChannelPriority = 3;
NVIC_InirStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InirStructure);
//wav采样率 24KHz = 48000KHz/(999+1)(1+1);
// 16KHz = 48000KHz/(999+1)(2+1)
// 11KHz = 48000KHz/(2180+1)(1+1)
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
//TIM_TimeBaseInitStructure.TIM_Period = 999;
// TIM_TimeBaseInitStructure.TIM_Prescaler = 2; //16K
TIM_TimeBaseInitStructure.TIM_Period = 2180;
TIM_TimeBaseInitStructure.TIM_Prescaler = 1; //11K
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//TIM_OCInitStructure.TIM_Pulse = 500; //测试
TIM_OC1Init(TIM1,&TIM_OCInitStructure);//TIM1--CH1
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);//更新中断
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);//
举报