CAN-Based Control of PWM Duty Cycle

This example shows how to use the CAN Receive, CAN Transmit, PWM, and C2812 Memory Copy blocks to generate a pulse waveform.

Required Hardware:

Available versions of this example:

Note: These models run only with Code Composer Studio v3.3

Contents

Model

The following figure shows the example model.

Description

Memory Copy block labeled "Read Duty Cycle" reads duty cycle value stored at the memory location 0x8FF0. "Transmit CAN Msg" block uses mailbox 5 to transmit this value packed in a standard CAN message frame, while "Receive CAN Msg" uses mailbox 0 to receive it. When the CAN message is received, "Process CAN Msg" unpacks the duty cycle value and sends it to the PWM1. The duty cycle of the generated pulse waveform is determined by the relative ratio of the received pulse width value and the pulse period which is fixed at 64000 clock cycles. The duty cycle toggles between 25%, 50%, and 75% based on user selection.

PWM Duty Cycle can be changed while the generated code is running using "write" method of the IDE Link component. This method writes selected value to the memory location 0x8FF0. Select either 25%, 50%, or 75% value from the GUI that opens up when "Build/Reload & Run" is pressed.

NOTE: 'Self-Test' mode is enabled for eCAN_A to receive the data transmitted back to the processor in the example models. If 'Self-test' mode is disabled, the CAN transmitter and receiver have to be physically connected for the example to work.

Note that "Simulate Duty Cycle Change" and "Simulate PWM Waveform" are dedicated to simulation only. Use these blocks to simulate and observe effects achieved with the generated code.

Hardware Connections

Connect the output of PWM1 on the board to the analog input of the oscilloscope.

Note that CAN module is set to work in "Self Test Mode". No external CAN hardware is needed as the CAN handshaking signals are emulated in software.

How to Run the Example in Simulation

How to Run the Example on the Board