如何让两路端口的开关频率不同?

发布于 2025-01-14 12:49:58 字数 1221 浏览 3 评论 0原文

一个输出的开关频率必须是第二个输出的两倍,而不是相同。 我不明白如何设置它。 这是我的代码和接收到的信号。

#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);
    }
}

image signals

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失去的东西太少 2025-01-21 12:49:58

您的无限循环中需要一个计数器,该计数器在每次执行循环时都会增加。

每次执行循环时,您都需要切换第一个输出。

第二个输出需要每秒切换一次。即每次计数器 % 2 == 0 时。

int cnt = 0;
for(;;) 
{
    output1 ^= 1;
    if (cnt % 2 == 0) 
        output2 ^= 1;
    delay(sometime);
    cnt++;
}

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.

int cnt = 0;
for(;;) 
{
    output1 ^= 1;
    if (cnt % 2 == 0) 
        output2 ^= 1;
    delay(sometime);
    cnt++;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文