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:
- Spectrum Digital F2808/F2812/F28335 eZdsp
- Texas Instruments™ F2808/F28035/F28069/F28335/F28343 ControlCARD with docking station
- Texas Instruments™ F28069 ControlSTICK
- Oscilloscope and probes
Available versions of this example:
- F281x based board: c281x_cantest.mdl
- F280x/F2823x/F2833x based board: c280x_2833x_cantest.mdl
- Piccolo F2803x/F2806x based board: c280xx_cantest.mdl
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
- Open the model corresponding to the family of processor you are using.
- Click Start simulation button
- Double-click on the "Duty Cycle Change" block and select a new duty cycle value
- Observe the PWM waveform change
How to Run the Example on the Board
- Open the model corresponding to the family of processor you are using.
- Each model is configured for a default processor. Open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Next, click "Target Hardware Resources" dialog to select a different processor.
- Go to Peripherals > eCAN_A and check Self-Test Mode.
- Click the "Build/Reload & Run" button to generate, build, load and run the program.
- Select a new duty cycle value in the dialog that opens.
- Observe the PWM waveform on the oscilloscope.