这是我定时器和ADC的配置 ,求大佬们看看,我现在一直触发不了ADC转换
定时器配置
void TIM5_PWM_Init(u16 arr,u16 psc)
{
TIM5_Handler.Instance=TIM5; //¶¨ê±Æ÷3
TIM5_Handler.Init.Prescaler=psc; //¶¨ê±Æ÷·ÖÆμ
TIM5_Handler.Init.CounterMode=TIM_COUNTERMODE_UP;//ÏòéϼÆêyÄ£ê½
TIM5_Handler.Init.Period=arr; //×Ô¶ˉÖØ×°ÔØÖμ
TIM5_Handler.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;
HAL_TIM_PWM_Init(&TIM5_Handler); //3õê¼»ˉPWM
TIM5_CH1Handler.OCMode=TIM_OCMODE_PWM2; //Ä£ê½Ñ¡Ôñ
WM1
TIM5_CH1Handler.Pulse=arr/2; //éèÖñè½ÏÖμ,′ËÖμóÃà′è·¶¨Õ¼¿Õ±è£¬
//Ĭèϱè½ÏÖμÎa×Ô¶ˉÖØ×°ÔØÖμμÄò»°ë,¼′Õ¼¿Õ±èÎa50%
TIM5_CH1Handler.OCPolarity=TIM_OCPOLARITY_LOW; //êä3ö±è½Ï¼«DÔÎaμí
HAL_TIM_PWM_ConfigChannel(&TIM5_Handler,&TIM5_CH1Handler,TIM_CHANNEL_1);//ÅäÖÃTIM3í¨μà4
HAL_TIM_PWM_Start(&TIM5_Handler,TIM_CHANNEL_1);//¿aÆô
WMí¨μà4
HAL_TIM_PWM_Start_IT(&TIM5_Handler,TIM_CHANNEL_1);//¿aÆô
WMí¨μà4
}
adc配置
void MY_ADC_Init(void)
{
ADC1_Handler.Instance=ADC1;
ADC1_Handler.Init.ClockPrescaler=ADC_CLOCK_SYNC_PCLK_DIV4; //4·ÖÆ죬ADCCLK=PCLK2/4=108/4=27MHZ
ADC1_Handler.Init.Resolution=ADC_RESOLUTION_12B; //12λÄ£ê½
ADC1_Handler.Init.DataAlign=ADC_DATAALIGN_RIGHT; //óò¶ÔÆë
ADC1_Handler.Init.ScanConvMode=DISABLE; //·Çé¨ÃèÄ£ê½
ADC1_Handler.Init.EOCSelection=ENABLE; //1رÕEOCÖD¶Ï
ADC1_Handler.Init.ContinuousConvMode=ENABLE; //1رÕá¬Dø×a»»
ADC1_Handler.Init.NbrOfConversion=1; //1¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD1
ADC1_Handler.Init.DiscontinuousConvMode=DISABLE; //½ûÖ12»á¬Dø2éÑùÄ£ê½
ADC1_Handler.Init.NbrOfDiscConversion=1; //2»á¬Dø2éÑùí¨μàêyÎa0
ADC1_Handler.Init.ExternalTrigConv=ADC_EXTERNALTRIGCONV_T5_TRGO;//ADC_SOFTWARE_START; //èí¼t′¥·¢
//ADC1_Handler.Init.ExternalTrigConvEdge=ADC_EXTERNALTRIGCONVEDGE_RISING;//ADC_EXTERNALTRIGCONVEDGE_RISING;// ADC_EXTERNALTRIGCONVEDGE_NONE;//ADC_EXTERNALTRIGCONVEDGE_RISING;//ADC_EXTERNALTRIGCONVEDGE_NONE;//ADC_EXTERNALTRIGCONVEDGE_RISING;// ADC_EXTERNALTRIGCONVEDGE_NONE;//ê1óÃèí¼t′¥·¢
ADC1_Handler.Init.DMAContinuousRequests=ENABLE; //¿aÆôDMAÇëÇó
HAL_ADC_Init(&ADC1_Handler); //3õê¼»ˉ
HAL_ADC_Channel_Set(ADC_CHANNEL_5,1);
HAL_ADC_Start_IT(&ADC1_Handler);
}
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_ADC1_CLK_ENABLE(); //ê1ÄüADC1ê±Öó
__HAL_RCC_GPIOA_CLK_ENABLE(); //¿aÆôGPIOAê±Öó
GPIO_Initure.Pin=GPIO_PIN_5; //PA5
GPIO_Initure.Mode=GPIO_MODE_ANALOG; //Ä£Äa
GPIO_Initure.Pull=GPIO_NOPULL; //2»′øéÏÏÂà-
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
}
因为用的是hal库,没找到能用的代码 ,网上很多的资料我也看了,也试着改,但是都没成功,
不知道有没有人用hal库做个这个事情 最好是用stm32F767开发的
或者有没有大神很了解这个,帮小弟指点指点!!!
一周热门 更多>