树莓派4B外设(BCM2711)

GPIO

58个GPIO,分为3个bank
bank0:0-27
bank1:28-45
bank2:46-57

所有的GPIO至少有两种功能。

PWM

脉宽调制器
特点:

  • 两个独立的比特输出流,频率固定
  • 一个32bit字进行配置
  • 可变的输出
  • 序列模式从一个缓冲中读取数据(64个32bit字)
  • 由100MHz的时钟驱动,可以被时钟管理模块改变

树莓派4bPython输出pwm 树莓派4b有几路pwm输出_单片机


BCM2711有两个pwm模块,每个有两个通道。

A value represented as a ratio of N/M can be transmitted along a serial channel with pulse width modulation, in which the value is represented by the duty cycle of the output signal。

用比率表示的值N/M可以用PWM进行串行传输,这个值表示为输出信号的占空比。

To send value N/M within a periodic sequence of M cycles, output should be 1 for N cycles and 0 for (M-N) cycles.

要在M个周期中发送N/M的值,输出应该N个周期为1,剩下的(M-N)个周期为0。

The desired sequence should have 1s and 0s spread out as evenly as possible, so that during any arbitrary period of time the duty cycle achieves the closest approximation of the value.

所需的序列应该有1s和0s尽可能均匀地展开,以便在任意时间段内占空比达到最接近该值。

This can be shown in the following table where 4/8 is modulated (N=4, M=8).

这可以在下表中显示,其中4/8被调制(n=4,m=8)。

树莓派4bPython输出pwm 树莓派4b有几路pwm输出_sed_02


Sequence which gives the ‘good’ approximation from the table above can be achieved by the following algorithm:

好的序列可以用如下的算法进行实现:

1. Set context = 0
2. context = context + N
3. if (context >= M)
		context = context - M
		send 1
	else
		send 0
4. Repeat from step 2

where context is a register which stores the result of the additions/subtractions.
其中context是存储加/减结果的寄存器。

8.4. Modes of Operation

操作模式

The PWM controller consists of two independent channels (pwm_chn_i in Figure 14) which implement the PWM algorithm

explained in the previous section. Each channel can operate in either PWM mode or serialiser mode.

PWM控制器由两个独立的通道(图14中的pwm_chn_i)组成,它们实现了前一节中解释的PWM算法。每个通道可以工作在PWM模式或串行模式。

PWM mode: There are two sub-modes in PWM mode: MSEN=0 and MSEN=1.

PWM模式:PWM模式有两个子模式:MSEN=0和MSEN=1。

When MSEN=0 (which is the default mode), data to be sent is interpreted as the value N of the algorithm explained above. The number of clock cycles (range) used to send data is the value M of the algorithm. Pulses are sent within this range so that the resulting duty cycle is N/M. The channel sends its output continuously as long as the data register is used (USEFi=0), or the FIFO is used and it is not empty.

当MSEN=0(这是默认模式)时,要发送的数据被解释为上述算法的值N。用于发送数据的时钟周期数(范围)是算法的值M。脉冲在此范围内发送,因此结果占空比为N/M。只要使用了数据寄存器(usefi=0),或者使用了FIFO并且它不是空的,通道就会连续地发送输出。

When MSEN=1, the PWM channel does not use the algorithm explained above, instead it sends serial data with the M/S ratio as in Figure 15. M is the data to be sent, and S is the range. This mode may be preferred if high frequency modulation is not required or has negative effects. The channel sends its output continuously as long as the data register is used (USEFi=0), or the FIFO is used and it is not empty.

当MSEN=1时,PWM通道不使用上述算法,而是以M/S 比率发送串行数据,如图15所示。M是要发送的数据,S是范围。如果不需要高频调制或有负面影响,则此模式可能是首选的。只要使用了数据寄存器(usefi=0),或者使用了FIFO并且它不是空的,通道就会连续地发送输出。

树莓派4bPython输出pwm 树莓派4b有几路pwm输出_嵌入式硬件_03


8.5. Quick Reference

快速参考

  • PWM0 DMA is mapped to DMA channel 5.
    PWM0 DMA映射到DMA通道5。
  • PWM1 DMA is mapped to DMA channel 1 (muxed with DSI0).
    PWM1 DMA映射到DMA通道1(与DSI0多路复用)。
  • GPIOs are assigned to PWM channels as below. Please refer to the GPIO chapter for further details:
    GPIO分配给PWM通道如下。详情请参阅GPIO章节:

树莓派4bPython输出pwm 树莓派4b有几路pwm输出_嵌入式硬件_04