Vous êtes sur la page 1sur 28

Code Warrior IDE Demo

Jason Lee KLM MSG (2nd August 2008 - Smart Car Workshop)

TM

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

Code Warrior IDE Demo


- This presentation is to share with Smart Cars Participant on how to use Code Warrior IDE to create and debugging a project. It contains:
How to create an IDE project How to debug (LED Example) How to boost the bus frequency (ON PLL Module) How to drive a Motor (PWM module)

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Code Warrior IDE Demo

How to create an IDE project

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project


From IDE main menu bar, select File > New . New window appears

a. b. c. d.

Select HC(S)12 New Project Wizard In Project name, type name you want In Location, enter path to store the project. Click OK button then go to next window.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project


New Project Wizard Page 1 appears

Click Next to proceed next window

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project


New Project Wizard Page 2 appears

a. b.

Select MC9S12DG128B under derivatives. Click Next to proceed next window.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project


New Project Wizard Page 3 appears

a. b.

Select Assembly as the languages use for this Demo. Click Next to proceed next window.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project


New Project Wizard Page 4 appears

a. b.

Select Absolute Assembly. Click Next to proceed next window.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project


New Project Wizard Page 5 appears

a. b.

Select TBDML. Click Finish to start new project

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project


system creates new project based on information you specified in New Project Wizard; Project window appears, docked at left side of main window

To undock Project window, double-click docking handle (double gray lines at top of window). To re-dock window, right click in title bar of Project Window, and select Docked.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create Code Warrior IDE Project

a. b.

Expand Sources Double click on the main.asm then source window will appear on the right side of the window.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Source File Structure


Define ASM Entry Point

Define Include file

Define Constant Value

Define Code Start Address

Main code

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Code Warrior IDE Demo

How to debug an IDE project (LED Example)

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Create LED Project example


Copy and paste the following code to the main.asm file.
; export symbols ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; include derivative specific macros INCLUDE 'mc9s12dg128.inc' ; variable/data section RAMSTART: EQU $1000 FLASHSTART: EQU $C000 StackPointer: EQU $1F00 ORG RAMSTART ; ORG FLASHSTART ; code section Entry: LDS #StackPointer MOVB #$FF,DDRB MOVB #$AA,PORTB LOOP: COM PORTB BRA LOOP ORG $FFFE DC.W Entry

; initialize the stack pointer ; Set PortB as Output Drive ; Set PortB Output $AA

; Reset Vector

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Compile & Debug LED Project example


Select Project -> Compile or Press CTRL+F7. Select Project -> Debug or Press F5 to start debug. Notes: codes will start download to DUT when debug initiate. Make sure you have connect the TBMDL and EVB is power ON.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Compile & Debug LED Project example


Click OK then debugger will mass erase all NVM and download the program.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Compile & Debug LED Project example


Continues Run / Step / Halt / Reset button

Assembly Code

Source Window

Register Window

Memory Window

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Code Warrior IDE Demo

How to boost the bus frequency (ON PLL Module)

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to Monitor Bus Clock Frequency


When Special Single Chip mode (BDM connected) is select, NECLK bit will auto set to 0. Hence MCU Bus Frequency will be output to PE4 pins.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to Turn ON Phase Lock Loop Module


By default, the CRG register is map to address $0034 to $003F. More details on each register description, please refer to S12CRGV4.pdf Setting this register correctly will change the bus frequency as required.

Generally,

PLLCLK = 2 x OSCCLK x (SYNR+1) (REFDIV+1)

Notes: If PLL is selected (PLLSEL=1), Bus Clock = PLLCLK/2 Bus Clock must not exceed the maximum operating system frequency.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to Turn ON Phase Lock Loop Module


add the following codes to main.asm
BCLR PEAR,#$10 PLLON: BSET PLLCTL,PLLCTL_AUTO BSET PLLCTL,PLLCTL_PLLON MOVB #24,SYNR MOVB #15,REFDV LOOP_CRGFLG: BRCLR CRGFLG,#$08,LOOP_CRGFLG BSET CLKSEL,#$80 ; Enable E clock to verify speed.. ; Auto bit set ; PLLON bit set

; Wait for lock bit setting.. ; switch to PLL clock source .

Calculation for PLLCLK = 2 x OSCCLK X [(SYNR+1)/(REFDV+1)] = 2 x 16MHz x [(24+1)/(15+1)] = 50MHz Since Bus Clock = PLLCLK/2 = 25MHz

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to Turn ON Phase Lock Loop Module

8MHz Bus Clock (PE4)

25MHz Bus Clock (PE4)

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Code Warrior IDE Demo

How to drive a Motor (PWM module)

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to drive DC Motor (PWM module)


A motor can be driven by just applying 2 different Voltage level. For example, +5V and GND. However this will constantly ON the motor and not able to control the speed of the motor. +5V

GND A Pulse Width Modulation (PWM) signal need to be generate to control the speed of the motor.

Schematic Example for DC Motor Driving


H-Bridge Driver

MC9S12DG128B

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to drive Servo Motor (PWM module)


A Servo is a small device that has an output shaft. This shaft can be positioned to specific angular positions by sending the servo a coded signal. As you can see in the picture below, the duration of the pulse dictates the angle of the output shaft (shown as the green circle with the arrow). Note that the times here are illustrative, and the actual timings depend on the motor manufacturer. The principle, however, is the same.

Example of coded signal to turn the Servo Motor

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to Turn ON PWM Module


By default, the PWM register is map to address $00A0 to $00C7. More details on each register description, please refer to

S12PWM8B8CV1.pdf
Setting this register correctly will get the desire PWM output.

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

How to Turn ON PWM Module


add the following codes to main.asm
CLR MOVB MOVB MOVB BSET PWME #$01,PWMPRCLK #$FF,PWMPER0 #$7F,PWMDTY0 PWME,#$01 ; Disable PWM module ; ClkA = BusClk / 2 = 25MHz / 2 = 12.5MHz ; PWMFREQUENCY = 12.5MHz / (256) = 48.8KHz ; Duty Cycle = (PWMPER0-PWMDTY0)/PWMPER0 ; PWM0 ON

Notes: different frequency and duty cycle can be change by modifying the, PWMPRCLK, PWMPER0 and PWMDTY0 register. It also can be done by using different clock source.

Example of PWM0 output signal

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Any Questions?

Thank You!!!

Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2008.

TM

Vous aimerez peut-être aussi