1 processor expert: a tutorial aaron minard 12-07-2009 elm 4071 technical topic presentation

17
1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

Post on 22-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

1

Processor Expert:A Tutorial

Aaron Minard12-07-2009ELM 4071Technical Topic Presentation

Page 2: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

2

Freescale CodeWarrior Quickly generate helper functions and

initialize ports Cleaner main file Easy to change CPU

Processor Expert

Page 3: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

3

Startup

Start a new ProjectStart a new Project

Page 4: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

5

Project Parameters

C and/or C++C and/or C++

Page 5: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

6

Processor Expert

Page 6: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

7

Project Environment

Bean SettingsBean Settings

Cpu BeanCpu Bean

Delay FunctionDelay Function

Page 7: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

8

Example of a helper Function

Delay100US - This method realizes software delay. The length of delay is at least 100 microsecond multiply input parameter us100. As the delay implementation is not based on real clock, the delay time may be increased by interrupt service routines processed during the delay. The method is independent on selected speed mode.

ANSIC prototype:

void Delay100US(word us100)

* us100:word – Number of 100 us delay repetitions.

Example: Delay for 1 second

Delay100US(10000);

SeconduS

S

Second

1000,10100

000,1010100

16

Page 8: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

9

Adding New Beans

Page 9: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

10

Bits IO Bean

Select PortSelect Port

Select # of BitsSelect # of Bits

Assigned Pins are LabeledAssigned Pins are Labeled

Page 10: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

11

Making the Project

When ready, When ready, click “Make” to click “Make” to generate code generate code for Beansfor Beans

A check to A check to include in code include in code generationgeneration

An X to not An X to not include in code include in code generationgeneration

Dependant Dependant on IO settingson IO settings

Page 11: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

12

Main File

Double click c:main Double click c:main to display the fileto display the file

A Main file will also A Main file will also be generated. This be generated. This has code to use all has code to use all your beans. Notice your beans. Notice immediately how immediately how large the file is, but large the file is, but how clean it looks.how clean it looks.

Page 12: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

13

Example Project

Read potentiometer PWM a motor controller Light 1 of 3 LEDs to indicate speed

Need beans for: A/D PWM 3 Digital Bits IO

Page 13: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

14

After Adding Beans

This means that the This means that the bean settings need bean settings need to be adjustedto be adjusted

Page 14: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

15

Bean Settings

Page 15: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

16

Function Definitions/Syntax

From Processor Expert Help File

BitIO

ClrVal - Clears (set to zero) the output value. It is equivalent to the PutVal(FALSE). This method is available only if the direction = output or input/output.

ANSIC prototype: void ClrVal(void)

To use a function:BeanName_FunctionName();

Low_ClrVal();

This clears the bit assigned to the bean “Low”

Page 16: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

17

User Written Code

AD1_Measure(TRUE); //Measure A/D AD1_GetValue16(&pot_value); //Put Value in Variable

PWM1_SetRatio16(pot_value); //Set Motor speed

//Light Proper Speed indicator based on Pot. input

if(pot_value<SET_LOW){ Low_SetVal(); //Turn on Low Light Med_ClrVal(); //Turn off Med Light High_ClrVal(); //Turn off High Light }else if(pot_value>SET_LOW && pot_value<SET_HIGH){ Low_ClrVal(); Med_SetVal(); High_ClrVal(); }else if(pot_value>SET_HIGH){ Low_ClrVal(); Med_ClrVal(); High_SetVal(); }

Page 17: 1 Processor Expert: A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation

18

Conclusion

While the total time was only about 5 minutes, the biggest advantage is not changing code if hardware changes.

Questions?