NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.
C6747 eCAP to EHRPWM example
Important Note:
The software discussed on this site is available for download, but is no longer being actively developed. This wiki is in maintenance mode and the software is supported on C67x Single core DSP E2E forum
Contents
Project Purpose[edit]
This is an example project for the C6747 eCAP module (although this can be used on the OMAP-L137's DSP as well). This example serves to function as a basic starting point for a DSP/BIOS-based project which utilizes the eCAP module. In this example the EHRPWM is configured to output a shifting duty cycle which is then read in through the eCAP. After the eCAP captures the time between 4 different edges the PWM period is either increased or decreased.
Necessary Hardware/Software[edit]
While this code should be easily adaptable to something other than what is listed below the hardware and software listed below was used to verify the project.
Hardware[edit]
This project was built and tested using the OMAP-L137/C6747 EVM in addition to the OMAP-L137 EVM Prototype Board. The prototype board was used to allow for access to the EPWM0A output pin and ECAP2 input pin for measurement/verification.
Software[edit]
This software was built using CGT v6.1.11 and DSP/BIOS 5.33.06 with CCS v3.3 SR 12.1. It has also been tested with CGT v6.1.10. The code requires the cslr from PSP 1.20.00.
NOTE that much of the initialization code was copied from the EVM GEL file and modified into cslr code.
Project Contents[edit]
This project (downloaded here:C6747_EHRPWM_eCAP.zip) contains the following source files:
- C6747_EHRPWM_eCAP_example.c
- Peripheral_Init.c
- defines.h
as well as the BIOS configuration file
- c6747_EHRPWM_eCAP.tcf
NOTE that during the build process several other BIOS-related files will be generated including C6747_EHRPWM_eCAPcfg.cmd. Do not be alarmed if you receive a missing file dialog box the first time you open the project. Simply rebuild and the remaining files should populate themselves in the project folder.
C6747_EHRPWM_eCAP_example.c[edit]
This file contains the main function as well as the ISR function EcapIsr(). Main() simply initializes two counter variables and then calls into Peripheral_Init() which initializes all necessary peripherals (see below). The EcapIsr() verifies that the edges are the same amount of time apart and then either increments or decrements the PRD value. Changing the PRD value increases or decreases the period of the PWM output. When the PRD value reaches a pre-defined min or max value then the shifting PRD value flips the other direction.
Peripheral_Init.c[edit]
This file contains all of the peripheral initialization code that this project requires.
NOTE that if you plan on plugging this code into another project or using it on something other than the C6747/OMAP-L137 EVM that you may need to modify or remove some pieces of this code's initialization. For example, the PLL initialization may need to change for custom hardware or the PINMUX registers could require additional modification so that the appropriate pins are configured.
This file is responsible for:
- Configuring the PLL
- Powering up the necessary peripherals (PSC0 and PSC1)
- Configuring the necessary pins (PINMUX)
- Enabling up interrupts (IER)
- Initializing EHRPWM0
- Initializing eCAP2
Each function in this file need only be called a single time at system startup.
defines.h[edit]
This file holds all of the #includes each file needs as well as some symbol definitions.
Setting up the Prototype Board[edit]
The prototype board ships almost completely unpopulated, so some simple work is necessary. First off, the J1 header must be populated so as to gain access to the EPWM0A pin (J1.29) and the J2 header must be populated to gain access to the ECAP2 pin (J2.29). Once this headers are populated you must also flip SW1.4 ON so as to route the EPWM0A pin to the header. Finally, plug the prototype board onto the C6747 EVM.
Rebuilding the Project[edit]
The project was built assuming default installation for the PSP (C:\Program Files\Texas Instruments\pspdrivers_01_20_00\packages). If the PSP is installed elsewhere you will need to modify the Include Search Path inside the Project->Build Options->Compiler tab->Preprocessor Category to point to the proper location.
NOTE that the cslr_ehrpwm.h header includes 5 multiple redefinition warnings. This has been submitted as a bug #SDOCM00060340. For the purposes of this project it poses no risk to proper operation. There are also a number of redefinition warnings for the cslr_ecap.h header file as well and these will be catalogued into a bug report soon.
Execution[edit]
Now load the .out file to the DSP and execute the code. You should now be able to see the EPWM0A period increasing and decreasing across an osciloscope. If you set a breakpoint inside the ISR you should be able to compare the CAP2-4 values and see them equal each other.