LIN-Based Control of PWM Duty Cycle
This example shows how to use the C28035 LIN Receive, LIN Transmit, and PWM blocks to generate a pulse waveform.
Required Hardware:
- TI F28035 controlCARD with docking station
- Oscilloscope and probes
Available versions of this example:
- TI F28035 controlCARD: c28035lintest.mdl
Contents
Model
The following figure shows the example model.
Description
This example model runs a single LIN node in loopback mode. The "Read Duty Cycle" subsystem passes the duty cycle values set by the user to the "LIN Transmit" block. The "LIN Transmit" block transmits the values to the "LIN Receive" block, which sends them on to the "ePWM Output" block. The "Verify Data" block compares the original duty cycle values with the values from the "LIN Receive" block. If the values do not match, the "Data Non-Match LD3" block flashes the LD3 LED on the C28035 controlCARD. In addition, a "LIN_STAT" signal is attached to the "Status" output from the "LIN Receive" block. You can check the LIN communication status by looking at the "LIN_STAT" variable from the generated code running in TI CCS.
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 by double clicking "Read Duty Cycle" subsystem and selecting either 25%, 50%, or 75% value from the GUI that opens up.
Note that "Generate Waveform for Simulation" and "Display 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 LIN module is set to work in "loopback" mode. No external LIN hardware is needed as the LIN TX/RX signals are emulated in software.
How to Setup LIN Loopback Mode
- Open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Click "Target Hardware Resources".
- Go to LIN page on the "Peripherals" tab, and select "Master" as the LIN mode
- Check "Enable loopback" on the LIN page
- Set "ID slave task byte" to a value between 0x00 - 0xFF, for example, 0x30
- Keep other LIN peripheral settings as pre-configured
For "LIN Transmit" and "LIN Receive" blocks:
- Use the same ID Mask for both LIN "TX ID Mask" and "RX ID Mask"
- Use "LIN ID" to make ("LIN ID" XOR "ID Mask") == "ID slave task byte"
- Keep mask settings for "LIN Transmit" and "LIN Receive" as preconfigured
For details about how to setup LIN peripheral, please refer to Configuring LIN Communications.
How to Run the Example in the Simulation
- Open this model
- Click "Run" button in your model
- Double-click on the "Duty Cycle" block and select a new duty cycle value
- Observe the PWM waveform change
How to Run the Example on the Board
- Open the model
- Double-click on the "Duty Cycle" block and select a new duty cycle value
- Generate code by clicking "Build Model" button in your model (Ctrl+B)
- Observe the change of the PWM waveform on the oscilloscope