如何让两路端口的开关频率不同?
一个输出的开关频率必须是第二个输出的两倍,而不是相同。 我不明白如何设置它。 这是我的代码和接收到的信号。
#include "RTE_Components.h"
#include CMSIS_device_header
void delay(volatile uint32_t count)
{
while(count--)
{
__nop();
}
}
int main()
{
*(uint32_t*)(0x40021018) |= 0x00000004;//RCC->APB2ENR |= RCC_APB2ENR_IOPAEN
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
*(uint32_t*)(0x40010804) &= ~(0x00003000 | 0x0000C000);//GPIOB->CRH &= ~(GPIO_CRH_MODE11 | GPIO_CRH_CNF11)
GPIOB->CRH &= ~(GPIO_CRH_MODE13 | GPIO_CRH_CNF13);
*(uint32_t*)(0x40010804) |= 0x00002000;//SET_BIT(GPIOA->CRH, GPIO_CRH_MODE11_1)
SET_BIT(GPIOB->CRH, GPIO_CRH_MODE13_1);
for(;;)
{
*(uint32_t*)(0x40010810) = 0x00000800;//GPIOA->BSRR = GPIO_BSRR_BS11
delay(6000);
GPIOB->BSRR = GPIO_BSRR_BS13;
delay(1560);
*(uint32_t*)(0x40010814) = 0x00000800;//GPIOA->BRR = GPIO_BRR_BR11
delay(6000);
GPIOB->BRR = GPIO_BRR_BR13;
delay(1560);
}
}
It is necessary that the switching frequency of one output be twice as large as the second, and not the same.
I don't understand how I can set it up.
Here is my code and received signals.
#include "RTE_Components.h"
#include CMSIS_device_header
void delay(volatile uint32_t count)
{
while(count--)
{
__nop();
}
}
int main()
{
*(uint32_t*)(0x40021018) |= 0x00000004;//RCC->APB2ENR |= RCC_APB2ENR_IOPAEN
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
*(uint32_t*)(0x40010804) &= ~(0x00003000 | 0x0000C000);//GPIOB->CRH &= ~(GPIO_CRH_MODE11 | GPIO_CRH_CNF11)
GPIOB->CRH &= ~(GPIO_CRH_MODE13 | GPIO_CRH_CNF13);
*(uint32_t*)(0x40010804) |= 0x00002000;//SET_BIT(GPIOA->CRH, GPIO_CRH_MODE11_1)
SET_BIT(GPIOB->CRH, GPIO_CRH_MODE13_1);
for(;;)
{
*(uint32_t*)(0x40010810) = 0x00000800;//GPIOA->BSRR = GPIO_BSRR_BS11
delay(6000);
GPIOB->BSRR = GPIO_BSRR_BS13;
delay(1560);
*(uint32_t*)(0x40010814) = 0x00000800;//GPIOA->BRR = GPIO_BRR_BR11
delay(6000);
GPIOB->BRR = GPIO_BRR_BR13;
delay(1560);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的无限循环中需要一个计数器,该计数器在每次执行循环时都会增加。
每次执行循环时,您都需要切换第一个输出。
第二个输出需要每秒切换一次。即每次计数器 % 2 == 0 时。
You need a counter in your endless loop which is increased on every execution of the loop.
You than need to toggle the first output every time the loop is executed.
Than the second output needs to be toggled every second time. That is every time the counter % 2 == 0.