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.
- TI F28035 controlCARD with docking station
- Oscilloscope and probes
Available versions of this example:
- TI F28035 controlCARD: c28035lintest.slx
The following figure shows the example model.
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.
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 on the Board using External Mode
- Open the model
- Double-click on the "Duty Cycle" block and select a new duty cycle value
- Ensure "Simulation mode" is selected as "External"
- Select the appropriate Serial port in Configuation parameters as explained in Parameter Tuning and Signal Logging with Serial External Mode
- Press the Play Button to run the model in External mode
- Use the diagnostic viewer to follow the build progress, and wait until the code is loaded and runs in the target hardware.
- Observe the change of the PWM waveform on the oscilloscope
- Change the "Duty Cycle" while the External mode is running and observe the changes in the PWM waveform on the oscilloscope accordingly