This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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

  • Texas Instruments™ F28035 controlCARD with docking station

  • Oscilloscope and probes

Available Models

Example Model

This example model runs a single LIN node in loopback mode. The Read Duty Cycle subsystem passes the duty cycle values to the LIN Transmit block. The LIN Transmit block transmits the values to the LIN Receive block, which sends them 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. To know the LIN communication status, you can check the LIN_STAT variable in the generated code running in Texas Instruments Code Composer Studio™.

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 64,000 clock cycles. The duty cycle toggles between 25%, 50%, and 75% based on the selection.

PWM duty cycle can be changed by double-clicking the Read Duty Cycle subsystem and selecting either 25%, 50%, or 75% value from the window that opens up.

Hardware Connections

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

The LIN module is set to work in loopback mode. No external LIN hardware is needed because the LIN TX/RX signals are emulated in the software.

Setup LIN Loopback Mode

  1. Browse to Configuration Parameters > Hardware Implementation > Target hardware resources.

  2. Set Master to LIN mode.

  3. Select Enable loopback on the LIN page.

  4. Set ID slave task byte to a value between 0x00 and 0xFF.

For the LIN Transmit and LIN Receive blocks:

  • Use the same ID Mask as input for both LIN TX ID Mask and RX ID Mask.

  • Use LIN ID to make (LIN ID XOR ID Mask) == ID-Slave Task Byte.

For information about how to setup the LIN peripheral, see Configuring LIN Communications.

Run the Model on the Board in External Mode

  1. Open the model, double-click the Duty Cycle block, and select a new duty cycle value.

  2. Ensure that Simulation mode is set to External.

  3. Select the appropriate serial port in Configuation Parameters as described in Parameter Tuning and Signal Logging with Serial External Mode.

  4. Press the Run button to run the model in External mode.

  5. Use the diagnostic viewer to follow the build progress, and wait until the code loads and runs on the target hardware.

  6. Observe the change of the PWM waveform on the oscilloscope.

  7. Change the duty cycle while in External mode and observe the changes in the PWM waveform on the oscilloscope.

More About