各位先進好,目前在學習stm32f7,自從stm出了HAL庫後,許多網上的範例已經無法使用,想將下面的程式改為stm32f7可以使用的版本,請問該如何修改?? int main() { TIM_OPMGATE_Init(); while(1) { Motor_Control(500,10); //500us,10个脉冲 } } void TIM_OPMGATE_Init() { TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct; TIM_OCInitTypeDef TIM_OCInitStruct; GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC, ENABLE);//使能PC,PA端口时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2|RCC_APB1Periph_TIM3,ENABLE);//使能定时器23的时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//使能复用IO时钟 GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE); GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6; GPIO_Init(GPIOC,&GPIO_InitStruct); //TIM2工作在单脉冲下 TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式 TIM_TimeBaseInitStruct.TIM_Prescaler = 7199;//预分频值,每100us计数一次 TIM_TimeBaseInitStruct.TIM_Period = 99; //重装值,决定单脉冲周期 TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStruct); TIM_SelectOnePulseMode(TIM2,TIM_OPMode_Single);//设置TIM2在单脉冲模式,且是单一的脉冲,在下一个更新事件停止 TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_OC1Ref); //OC1REF signal is used as the trigger output (TRGO).单一模式不需要设置 TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);//使能定时器2的通道1预装载寄存器 TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;//在向上计数时,一旦TIMx_CNT>TIMx_CCR1时通道1为有效电平 TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;//OC1输出使能 TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;//有效电平为高 TIM_OCInitStruct.TIM_Pulse = 20;//比较捕获1的预装载值,决定单脉冲占空比,这个20就是低电平延续的来源 TIM_OC1Init(TIM2,&TIM_OCInitStruct); TIM_Cmd(TIM2,DISABLE); //Enable the TIM Counter //TIM3工作在从模式门控模式下 TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式 TIM_TimeBaseInitStruct.TIM_Prescaler = 719;//预分频值,10us计数一次 TIM_TimeBaseInitStruct.TIM_Period = 29;//重装值,决定PWM周期 TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStruct); TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Gated);//TIM3为门控模式 TIM_SelectMasterSlaveMode(TIM3,TIM_MasterSlaveMode_Enable);//使能TIM3的主从模式 TIM_SelectInputTrigger(TIM3,TIM_TS_ITR1);//内部触发,TIM_TS_ITR1对应TIM2 TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);//使能定时器3的通道1预装载寄存器 TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;//在向上计数时,一旦TIMx_CNT>TIMx_CCR1时通道1为有效电平 TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;//OC1输出使能 TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;//有效电平为高 TIM_OCInitStruct.TIM_Pulse = 15;//比较捕获1的预装载值,占空比为50% TIM_OC1Init(TIM3,&TIM_OCInitStruct); TIM_Cmd(TIM3,ENABLE);//使能TIM3 } |
评分
查看全部评分
F7不支持标准库,只能有HAL库,除非楼主把所有操作直接用修改寄存器方式。
评分
查看全部评分
我使用的是f767 ZI的開發板正點原子的範例我有看過,但像单脉冲模式的部份函式設定,由於沒有做太多介紹所以還不太知道怎麼用
评分
查看全部评分
目前我有大概改了一下,還有些找不到對應的函數,我有紅色標示,還請網上的高人指點
void TIM_OPMGATE_Init(void)
{
TIM_HandleTypeDef TIM2_Handler; //
TIM_OC_InitTypeDef TIM2_CH1Handler;
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_TIM2_CLK_ENABLE();
__HAL_RCC_TIM3_CLK_ENABLE();
__HAL_RCC_AFIO_CLK_ENABLE();
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; //¼Ò¦¡³]¸m
GPIO_InitStruct.Pin = GPIO_PIN_0; //«ü©wIO¤f
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; //³t«×³]¸mhigh¥i½Õ¾ã
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_Init(GPIOC,&GPIO_InitStruct);
//TIM2
TIM2_Handler.Init.CounterMode = TIM_COUNTERMODE_UP;
TIM2_Handler.Init.Prescaler = 7199;
TIM2_Handler.Init.Period= 99;
HAL_TIM_PWM_Init(&TIM2_Handler);
TIM_SelectOnePulseMode(TIM2,TIM_OPMODE_SINGLE);
TIM_SelectOutputTrigger(TIM2,TIM_TRGO_OC1REF);
//TIM2
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStruct.TIM_Pulse = 20;
TIM_OC1Init(TIM2,&TIM_OCInitStruct);
TIM_Cmd(TIM2,DISABLE); //Disable the TIM Counter
//TIM3
TIM3_Handler.Init.CounterMode = TIM_COUNTERMODE_UP;
TIM3_Handler.Init.Prescaler = 719;
TIM3_Handler.Init.Period = 29;
HAL_TIM_PWM_Init(&TIM3_Handler);
TIM_SelectSlaveMode(TIM3, TIM_SLAVEMODE_GATED);
TIM_SelectMasterSlaveMode(TIM3,TIM_MASTERSLAVEMODE_ENABLE);
TIM_SelectInputTrigger(TIM3,TIM_TS_ITR1);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStruct.TIM_Pulse = 15;
TIM_OC1Init(TIM3,&TIM_OCInitStruct);
TIM_Cmd(TIM3,ENABLE);
}
C:\Users\user\STM32Cube\Repository\STM32Cube_FW_F4_V1.16.0\Projects\STM324xG_EVAL\Examples\TIM
评分
查看全部评分
输出PWM,原子哥有例程的,互补PWM的火哥有
评分
查看全部评分
能否提供例程的連結或檔案??
因為,我去找火哥的例程時網頁都出現檔案不存在,無法搜尋,麻煩了謝謝。
C:\Users\user\STM32Cube\Repository\STM32Cube_FW_F4_V1.16.0\Projects\STM324xG_EVAL\Examples\TIM
评分
查看全部评分
你加入火哥的QQ群,或者论坛内私信野火
可以提供論壇的入口地址嗎??
我找了好久,不是沒辦法打開網頁就是跟stm32無關的網站
火哥的论坛维护,初七后就可以了