完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
|
|
你好像没有使能相关的GPIO口呀。
|
|
|
|
通过STM32CubeMX配置试试看。
|
|
|
|
能在仿真时出现正确的波形,但是在硬件上没有,这个还是硬件的问题,看看你的硬件是否连线正常,先测试下相应的基本功能。再根据出现的情况一步一步分析。
|
|
|
|
仿真是有点区别。还是按实际的用吧
|
|
|
|
/* System Clocks Configuration */
RCC_Configuration(); /* GPIO Configuration */ GPIO_Configuration(); /* TIM1 Configuration --------------------------------------------------- TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density and Connectivity line devices and to 24 MHz for Low-Density Value line and Medium-Density Value line devices The objective is to generate 7 PWM signal at 17.57 KHz: - TIM1_Period = (SystemCoreClock / 17570) - 1 The channel 1 and channel 1N duty cycle is set to 50% The Timer pulse is calculated as follows: - ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100 ----------------------------------------------------------------------- */ /* Compute the value to be set in ARR regiter to generate signal frequency at 17.57 Khz */ TimerPeriod = (SystemCoreClock / 17570 ) - 1; /* Compute CCR1 value to generate a duty cycle at 50% for channel 1 and 1N */ Channel1Pulse = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10); /* Time Base configuration */ TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = TimerPeriod; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* Channel 1 Configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse = Channel1Pulse; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure); /* TIM1 counter enable */ TIM_Cmd(TIM1, ENABLE); /* TIM1 Main Output Enable */ TIM_CtrlPWMOutputs(TIM1, ENABLE); -------------------------------------------------------------------- 以上是官方例程,请参考! 楼主确实IO初始化和 TIM_CtrlPWMOutputs(TIM1, ENABLE); 不妨试试! 另外,仿真和脱机运行会不一致是正常的! |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2049 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1893 浏览 3 评论
4485 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2040 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2549 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 19:20 , Processed in 0.587940 second(s), Total 53, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号