gpt4 book ai didi

linux - 在树莓派2中,如何配置PWM1 channel ?

转载 作者:太空狗 更新时间:2023-10-29 12:43:18 24 4
gpt4 key购买 nike

我可以使用以下 C 代码在 Raspberry Pi 的 GPIO 18 上使用 PWM0 channel 来驱动伺服:

#define BCM2708_PERI_BASE       0x3F000000
#define PWM_BASE (BCM2708_PERI_BASE + 0x20C000)
#define CLOCK_BASE (BCM2708_PERI_BASE + 0x101000)
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000)

#define PWM_CTL 0
#define PWM0_RNG 4
#define PWM0_DAT 5

#define PWM0_MS_MODE 0x0080 // Run in MS mode
#define PWM0_USEFIFO 0x0020 // Data from FIFO
#define PWM0_REVPOLAR 0x0010 // Reverse polarity
#define PWM0_OFFSTATE 0x0008 // Ouput Off state
#define PWM0_REPEATFF 0x0004 // Repeat last value if FIFO empty
#define PWM0_SERIAL 0x0002 // Run in serial mode
#define PWM0_ENABLE 0x0001 // Channel Enable

#define PWMCLK_CNTL 40
#define PWMCLK_DIV 41

// stop clock and waiting for busy flag doesn't work, so kill clock
*(clk + PWMCLK_CNTL) = 0x5A000000 | (1 << 5); usleep(10);

// wait until busy flag is set
while ( (*(clk + PWMCLK_CNTL)) & 0x00000080){}

*(clk + PWMCLK_DIV) = 0x5A000000 | (Divisor << 12);
*(clk + PWMCLK_CNTL) = 0x5A000011;
*(pwm + PWM_CTL) = 0; usleep(10);

*(pwm + PWM0_RNG) = Counts; usleep(10);
*(pwm + PWM0_DAT) = (int) (DutyCycle * Counts / 100); usleep(10);
*(pwm + PWM_CTL) |= ( (1 << 7) | (1 << 0) );

然而,当我试图在 PWM1 channel 上的另一个 GPIO 上驱动另一个伺服器时,它根本不起作用。 PWM1 channel 具有以下值:

#define PWM1_RNG 8
#define PWM1_DAT 9

#define PWM1_MS_MODE 0x8000 // Run in MS mode
#define PWM1_USEFIFO 0x2000 // Data from FIFO
#define PWM1_REVPOLAR 0x1000 // Reverse polarity
#define PWM1_OFFSTATE 0x0800 // Ouput Off state
#define PWM1_REPEATFF 0x0400 // Repeat last value if FIFO empty
#define PWM1_SERIAL 0x0200 // Run in serial mode
#define PWM1_ENABLE 0x0100 // Channel Enable

谁能告诉我 PWM0 和 PWM1 的寄存器在哪里被修改了?

最佳答案

涉水可用documentation ,您必须将 GPIO45 设置为其 Alternate Function 0

PWM 外设寄存器在 Broadcom peripheral documentation 中描述。 (这是指 RPi1 的 BCM2835,但在外围设备方面与 RPi 的 BCM2836 基本相同。请注意,PWM channel 在寄存器表中称为 PWM1/2 而不是 PWM0/1。

关于linux - 在树莓派2中,如何配置PWM1 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34614655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com