Exercise: PWM Generation using the N2HET 1
Overview In this exercise we will: Create a new HALCoGen Project Configure HALCoGen to generate A basic PWM with a period of 1 second and a duty cycle of 75% Use the PWM to toggle the NHET[8] LEDs on the board Generate and Import code into Code Composer Studio Build and Deploy our code to the microcontroller Required Hardware: Windows Based PC (WinXP, Vista, 7) TMS570LS04 LaunchPad or RM48 LaunchPad Required Software: HALCoGen Code Composer Studio 2
HALCoGen GUI Overview Menus and Icons Help Module Selection/Configuration Device Block Diagram Device/ Output File Explorer Output/Status 3
HALCoGen Help HALCoGen s embedded help window provides full documentation of each communication drivers, implemented functions, file dependencies and examples. 4
HALCoGen File Dependencies and Function Listing File Information Control File Explorer File Dependency Diagram Function Listing 5
Set up a New HALCoGen Project To launch HALCoGen go to: Programs Texas Instruments Hercules HALCoGen Create a new project: File New Project 1 For the TMS570 Kit: Choose Family: TMDX570LS04x Device:TMDX570LS0432PZ For the RM42 Kit: Choose Family: RM42x Device:RM42PZ 2 3 Then define a name: N2HET Location: C:\myWorkspace 6
Driver Enable In Driver Enable tab enable the HET1 driver. 1 2 3 7
N2HET PWM Configuration In Driver Enable tab enable the NHET driver. In HET1 PWM 0-7 tab: Configure PWM 0 to 75% Duty Cycle, with a Period 1000000.00uS on Pin 8 8
N2HET Output Configuration In the HET1 Pin 0-7 tab: Make sure that the output on Pin 8 is enabled 2 1 Generate Code: File Generate Code 9
Setting up Code Composer Studio Launch Code Composer Studio (CCS) Start Programs Texas Instruments Code Composer Studio v5 Code Composer Studio v5 When it launches, CCS will ask you to select a workspace, we will chose C:\myWorkspace Once CCS loads, go to File New CCS Project 10
Setting up our Project From the New Project window, expand the Code Composer Studio folder. Select CCS Project Click Next NOTE: This step may not be required. Only some versions on CCS require this step. 1 2 3 11
Setting up our Project Our project name needs to match the name of our HALCoGen Project, Exercise Make sure that your project Family is set to ARM 1 Next, set the Variant to Cortex R For the TMS570 kits: Choose: TMS570LS043x 2 3 For the RM42 kits: Choose : RM42L432 5 4 Then set the Connection to the Texas Instruments XDS100v2 6 Then click Finish 12
Setting up our Project First delete expand the project and delete file main.c from CCS Project Explorer Note: CCSv5.2 and earlier will create a file named main.c automatically when a new project is created. Since we are using code that HALCoGen created for us, we will not need this file. This step is not necessary when creating a new empty project with CCSv5.3 and newer. 1 N2HET 2 13
Setting up our Project Drag the HalCoGen created folders to the CCS Project
Setting up our Project Following window pop out Choose Link to files and recreate Check box Create link locations relative
Setting up our Project Next we need to add our include directory to the project from the CCS Project Explorer Right click on the N2HET project in the Project Explorer 1 Then choose Properties 2 16
Setting up our Project Then in the Properties window expand the Build -> ARM Compiler category and select Include Options 1 2 Then select the + button to add the directory with our.h header files 3 4 In the Add directory path window, click the Workspace button Finally, put "${PROJECT_LOC}../../inc lude/ and click OK 17
Enter Code into the CCS Project Expand the project and open the sys_main.c file from the CCS Project Explorer Note: Since the HALCoGen and CCS project have the same project name, all the startup and driver files generated by HALCoGen will be automatically included in the CCS project. Use the sys_main.c file for your main program code. 18
Code Composer Studio In the Code Composer Project and enter the following code: Inside User Code 1, insert the code below. /* USER CODE BEGIN (1) */ #include "het.h" /* USER CODE END */ Then in User Code 3, insert the code below. /* USER CODE BEGIN (3) */ hetinit(); while(1); /* USER CODE END */ 19
Compiling the Project The code is now complete and we are ready to build our project. Go to Project Build All Now that we have our.out file, we need to program the microcontrollers Flash memory. 20
Programming the Flash We are now ready to program the flash. Go to Run Debug A new window should appear as it programs the flash memory. This may take a few moments. 21
Testing our Program Click the green arrow on the debug tab to run our program Alternatively the program can be run without the debugger connected by Clicking the red square on the debug tab to terminate the debugger s connection Hitting the reset button on the board and observe the behavior of the N2HET LEDs Congratulations! You have completed the exercise. 22
Exercise: Using the MibADC to collect Ambient Light Sensor data percentage df 23
ADC Exercise Overview In this exercise we will: Acquire data from the ambient light sensor using the ADC module Send the converted ADC value back through the SCI/UART module to the PC. 00111011000100100110 24
Set up a New HALCoGen Project To launch HALCoGen go to: Programs Texas Instruments Hercules HALCoGen Create a new project: File New Project 1 For the TMS570 Kit: Choose Family: TMDX570LS04x Device:TMDX570LS0432PZ For the RM42 Kit: Choose Family: RM42x Device:RM42PZ 2 3 Then define a name: ADC Location: C:\myWorkspace 25
Driver Enable Enable the SCI and ADC drivers in the Driver Enable sub tab of the device 26
SCI Configuration Select the SCI2 tab and then the SCI/LIN Data Format subtab Ensure that the SCI module is setup with the following parameters: Baud rate: 9600 Data bits: 8 No parity, 2 Stop bits 27
ADC Group Configuration In the ADC tab and ADC Group 1 Subtab, Configure FIFO Size, Trigger Source and ADC channel as shown below Only one conversion per software trigger is done SW Trigger as Trigger Source Ambient light sensor is connected to MibADC1 Pin9 Generate code: File Generate Code or click 28
MibADC Exercise Insert the following code in the corresponding sections within the sys_main.c file USER CODE BEGIN (0) - #include header section /* USER CODE BEGIN (0) */ #include "sci.h" #include "adc.h" #include "stdlib.h" unsigned char command[8]; /* USER CODE END */ 29
MibADC Exercise USER CODE BEGIN(3) - Main() section void main(void) {/* USER CODE BEGIN (3) */ adcdata_t adc_data; //ADC Data Structure adcdata_t *adc_data_ptr = &adc_data; //ADC Data Pointer unsigned int NumberOfChars, value; //Declare variables sciinit(); //Initializes the SCI (UART) module adcinit(); //Initializes the ADC module while(1) // Loop to acquire and send ADC sample data via the SCI (UART) { adcstartconversion(adcreg1, 1U); //Start ADC conversion while(!adcisconversioncomplete(adcreg1, 1U)); //Wait for ADC conversion adcgetdata(adcreg1, 1U, adc_data_ptr); //Store conversion into ADC pointer value = (unsigned int)adc_data_ptr->value; NumberOfChars = ltoa(value,(char *)command); scisend(scilinreg, 2, (unsigned char *)"0x"); //Sends '0x' hex designation chars scisend(scilinreg, NumberOfChars, command); //Sends the ambient light sensor data scisend(scilinreg, 2, (unsigned char *)"\r\n"); //Sends new line character } /* USER CODE END */} 30
Testing your code Upon completion open your preferred terminal program. Note: A terminal program is included in CCS. To enable it go to View -> Other and select Terminal from the Show View menu. If the Terminal option is not available it can be added as an eclipse plug-in by following these instructions: http://processors.wiki.ti.com/index.php/how_to_install_the_terminal_plugin_in_ccsv5 Setup the terminal program with the following properties: Baud rate: 9600 Data bits: 8 No parity, 2 Stop bits Click the Run button to run the program Now you should see the ADC results in the terminal program Use the LED flashlight included in the development kit to change the light level supplied to the ambient light sensor on the board and notice the output values change in the terminal program. 31
Enabling the CCS Terminal 1) Select View Other 3) Enter the proper communication settings for the Terminal Tab 2) Then select Terminal from the Show View menu. 32
Additional Hercules Information 33
Additional Information Hercules Web Page: www.ti.com/hercules RM4 Web Page: www.ti.com/rm4 TMS570 Web Page: www.ti.com/tms570 TMS470M Web Page: www.ti.com/tms470m Data Sheets Technical Reference Manual Application Notes Software & Tools Downloads and Updates Order Evaluation and Development Kits Engineer 2 Engineer Support Forum: www.ti.com/hercules-support News and Announcements Useful Links Ask Technical Questions Search for Technical Content Hercules WIKIs: RM4 WIKI: www.ti.com/hercules-rm4-wiki TMS570 WIKI: www.ti.com/hercules-tms570-wiki TMS470M WIKI: www.ti.com/hercules-tms470m-wiki How to guides Intro Videos General Information 34
Want Additional Training? Safety Critical Design and Programming with Hercules Microcontrollers: Day 1 Day 2 Day 3 Welcome and Intro Hercules Product Overview / MCU Roadmap Safety Standards and Hercules Safety Features / Exercise HALCoGen / Exercise Code Composer Studio / Demonstration Compiler Flash Overview Flash Tools: nowflash, nowecc / Exercise Summary / Questions ARM Cortex -R4F CPU System Module Overview Device setup/startup, Real Time Interrupt Module, Vectored Interrupt Manager CRC Controller, CPU Compare Module, Error Signaling Module, Dual Clock Compare, JTAG Security Module General Purpose I/Os / Exercise Direct Memory Access Controller (DMA) Serial Communication Interface (SCI/UART) / Exercise Summary / Questions Multi-Buffer ADC (MIBADC) / Exercise Multi-Buffer Serial Peripheral Interface (SPI / MIBSPI-P) DCAN FlexRay External Memory Interface (EMIF) / Parameter Overlay Module (POM) Ethernet USB Host / Device HET (High End Timer) IDE N2HET & Transfer Unit / Exercise Summary / Questions / Survey 35
Thank You! Please fill out the Training Class Survey 36