exercise: pwm generation using the n2het · dual clock compare, jtag security module • general...

36
1 Exercise: PWM Generation using the N2HET

Upload: others

Post on 14-Aug-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

1

Exercise: PWM Generation using the N2HET

Page 2: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

2

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

Page 3: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

3

HALCoGen GUI Overview

Output/Status

Device/ Output File

Explorer

Menus and Icons

Device Block

Diagram

Module Selection/Configuration Help

Page 4: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

4

HALCoGen Help • HALCoGen’s embedded help window provides full documentation of

each communication drivers, implemented functions, file dependencies and examples.

Page 5: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

5

HALCoGen File Dependencies and Function Listing

File Information

Control

File Dependency

Diagram

Function Listing

File Explorer

Page 6: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Set up a New HALCoGen Project

6

• To launch HALCoGen go to:

• → Programs → Texas Instruments → Hercules → HALCoGen

• Create a new project:

• File → New → Project

• For the TMS570 Kit: – Choose Family: TMDX570LS04x – Device:TMDX570LS0432PZ

• For the RM42 Kit:

– Choose Family: RM42x – Device:RM42PZ

• Then define a name: ‘N2HET’ • Location: “C:\myWorkspace”

1

3

2

Page 7: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Driver Enable • In ‘Driver Enable’ tab enable the HET1 driver.

7

1

2

3

Page 8: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

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

Page 9: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

N2HET Output Configuration • In the ‘HET1’ ‘Pin 0-7’ tab:

• Make sure that the output on Pin 8 is enabled

• Generate Code: File → Generate Code

9

1

2

Page 10: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

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

Page 11: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Setting up our Project • From the New Project window, expand the ‘Code Composer Studio’

folder .

• Select ‘CCS Project’

11

• Click ‘Next’

NOTE: This step may not be required. Only some versions on CCS require this step.

1

3

2

Page 12: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

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

12

• Next, set the Variant to “Cortex R”

• For the TMS570 kits: – Choose: TMS570LS043x

• For the RM42 kits:

– Choose : RM42L432

• Then click ‘Finish’

1

3 2

• Then set the ‘Connection’ to the Texas Instruments XDS100v2

4

6

5

Page 13: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

• 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.

Setting up our Project

13

1

2

N2HET

Page 14: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Setting up our Project • Drag the HalCoGen created folders to the CCS Project

Page 15: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Setting up our Project • Following window pop out

• Choose “Link to files and recreate…”

• Check box “Create link locations relative…”

Page 16: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

• Next we need to add our ‘include’ directory to the project from the CCS “Project Explorer”

Setting up our Project

16

1

2

• Right click on the ‘N2HET’ project in the Project Explorer

• Then choose ‘Properties’

Page 17: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Setting up our Project

17

1

4 3

2

• Then in the ‘Properties’ window expand the ‘Build -> ARM Compiler’ category and select ‘Include Options’

• Then select the ‘+’ button to add the directory with our ‘.h’ header files

• In the ‘Add directory path’ window, click the ‘Workspace…’ button

• Finally, put "${PROJECT_LOC}../../include/” and click “OK”

Page 18: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

• 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.

Enter Code into the CCS Project

18

Page 19: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

19

Code Composer Studio • In the Code Composer Project and enter the following code:

– Inside User Code 1, insert the code below. – Then in User Code 3, insert the code below.

/* USER CODE BEGIN (1) */ #include "het.h" /* USER CODE END */

/* USER CODE BEGIN (3) */ hetInit(); while(1); /* USER CODE END */

Page 20: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

• 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.

Compiling the Project

20

Page 21: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

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

Page 22: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

• 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.

Testing our Program

22

Page 23: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Exercise: Using the MibADC to collect Ambient Light Sensor data percentage df

23

Page 24: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

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.

24

00111011000100100110

Page 25: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Set up a New HALCoGen Project

25

• To launch HALCoGen go to:

• → Programs → Texas Instruments → Hercules → HALCoGen

• Create a new project:

File → New → Project

• For the TMS570 Kit: – Choose Family: TMDX570LS04x – Device:TMDX570LS0432PZ

• For the RM42 Kit:

– Choose Family: RM42x – Device:RM42PZ

• Then define a name: ‘ADC’ • Location: “C:\myWorkspace”

1

3

2

Page 26: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Driver Enable

• Enable the SCI and ADC drivers in the ‘Driver Enable’ sub tab of the device

26

Page 27: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

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

Page 28: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

ADC Group Configuration • In the ‘ADC’ tab and ‘ADC Group 1’ Subtab, Configure FIFO Size, Trigger Source and

ADC channel as shown below

• Generate code: File → Generate Code or click

28

Only one conversion per software trigger is done

SW Trigger as Trigger Source

Ambient light sensor is connected to MibADC1 Pin9

Page 29: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

MibADC Exercise

• Insert the following code in the corresponding sections within the ‘sys_main.c’ file

– USER CODE BEGIN (0) - #include header section

29

/* USER CODE BEGIN (0) */ #include "sci.h" #include "adc.h" #include "stdlib.h" unsigned char command[8]; /* USER CODE END */

Page 30: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

MibADC Exercise – USER CODE BEGIN(3) - Main() section

30

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 */}

Page 31: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

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

31

• 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.

Page 32: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Enabling the CCS Terminal

1) Select View → Other

2) Then select ‘Terminal’ from the ‘Show

View’ menu.

3) Enter the proper communication settings for the ‘Terminal Tab’

32

Page 33: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Additional Hercules™ Information

33

Page 34: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

34

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

Page 35: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

35

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

Page 36: Exercise: PWM Generation using the N2HET · Dual Clock Compare, JTAG Security Module • General Purpose I/Os / Exercise • Direct Memory Access Controller (DMA) • Serial Communication

Thank You!

Please fill out the Training Class Survey

36