190 likes | 425 Views
Processor Expert: A Tutorial. Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation. Processor Expert. Freescale CodeWarrior Quickly generate helper functions and initialize ports Cleaner main file Easy to change CPU. Startup. Start a new Project. Project Parameters.
E N D
Processor Expert:A Tutorial Aaron Minard 12-07-2009 ELM 4071 Technical Topic Presentation
Processor Expert • Freescale CodeWarrior • Quickly generate helper functions and initialize ports • Cleaner main file • Easy to change CPU
Startup Start a new Project
Project Parameters C and/or C++
Project Environment Bean Settings Cpu Bean Delay Function
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);
Bits IO Bean Assigned Pins are Labeled Select Port Select # of Bits
Making the Project When ready, click “Make” to generate code for Beans An X to not include in code generation A check to include in code generation Dependant on IO settings
Main File A Main file will also be generated. This has code to use all your beans. Notice immediately how large the file is, but how clean it looks. Double click c:main to display the file
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
After Adding Beans This means that the bean settings need to be adjusted
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”
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(); }
Conclusion While the total time was only about 5 minutes, the biggest advantage is not changing code if hardware changes. Questions?