A special feature on LPC4300 microcontrollers, the serial GPIO interface, lets you expand the number of PWM channels in a design without resorting to CPU-intensive software techniques like bit-banging.
Every SGPIO pin can be used as an extra PWM pin, and the duty cycle and the frequency can be changed on the fly. Each slice has a 32-bit FIFO buffer, so there are 33 PWM duty cycles possible. This creates a 5-bit PWM that can be fully on or fully off.
The SGPIO are supported by a command library that makes it easier to configure SGPIO operation. For example, there is a command for initializing the SGPIO interface for PWM use. It disables all interrupts, makes each SGPIO slice an output, and enables all SGPIO clocks. There is also a command for initializing a single SGPIO slice for PWM use, or for changing the PWM frequency. You can also use commands to change the PWM duty cycle of any slice and confirm that the adjustment has been made.
Figure 2 shows the flowchart we used to create the PWM signals. As mentioned above, it's possible to concatenate the slices. For a PWM function, using concatenation can increase precision, but, to keep things simple, our example doesn't use concatenation.
Figure 2. Flowchart of the code when changing a PWM value.
In our example PWM channel, the process starts when a slice is used as output and the PWM data is loaded in the REG and REG_SS registers. After that, the slice only has to repeat the data in the REG register. When the PWM duty cycle is changed, the value in the REG_SS register is updated twice. This is because the REG and REG_SS registers are swapped every 32 clock cycles. Writing the data twice ensures the PWM output is accurate, since it avoids the possibility of using a previous register value.
The flowchart is relatively straightforward, and reflects the simplicity of using the SGPIO to create PWM channels. There's no need for code loops that manipulate GPIO in real-time, and there's less CPU overhead than when using bit-banging.
You'll find a more in-depth description of the LPC4300 SGPIO and how to configure PWM channels in the application note AN11275.
In all of NXP's dual-core Cortex-M4/M0-based LPC4300 series of MCUs, the SGPIO interface can be used to create or capture multiple real-time serial data streams. This saves design time and improves performance by reducing CPU overhead. This article shows the SGPIO performing PWM functions, but the SGPIO can also be configured to implement as serial interfaces, including UART, SPI, I2S, I2C, or even a camera interface.