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

Post on 22-Dec-2015

223 views 0 download

Tags:

Transcript of 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

2

Freescale CodeWarrior Quickly generate helper functions and

initialize ports Cleaner main file Easy to change CPU

Processor Expert

3

Startup

Start a new ProjectStart a new Project

5

Project Parameters

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

6

Processor Expert

7

Project Environment

Bean SettingsBean Settings

Cpu BeanCpu Bean

Delay FunctionDelay Function

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

9

Adding New Beans

10

Bits IO Bean

Select PortSelect Port

Select # of BitsSelect # of Bits

Assigned Pins are LabeledAssigned Pins are Labeled

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

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.

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

14

After Adding Beans

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

15

Bean Settings

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”

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(); }

18

Conclusion

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

Questions?