Click on our menu buttons immediately below to find MegaSquirt® information quickly:
MicroSquirt® Module
V1/V2 MicroSquirt®
Important Safety Information
MicroSquirt® Support Forum
- MShift™ TCU
- MShift™ Intro
- GPIO Build Guide for 4L60E
- Base circuits
- GPO1, GPO2, GPO3,
GPO4 (gear LEDs)
- VB1, VB2, VB3, VB4
- PWM1, PWM2, PWM3, PWM4
- GPI1, GPI2, GPI5
(2/4WD, Input2, downshift)
- GPI3 (Temperature)
- GPI4 (Brake sense)
- EGT1, EGT2, EGT3,
EGT4 (non-CAN Load, line pressure, Input3, Input1)
- VR1 (Vehicle
Speed Sensor)
- VR2 (Upshift button)
- Finishing Touches
- Testing your
GPIO Board
- External Wiring Guide for 4L60E
- Current Release Code
- User Settings
- βeta Code
- Code Archives
- Purchase a
GPIO kit
- Working with the Shift Table
- Serial
Connection Troubleshooting
- CANbus
Set-Up
- Solving VSS
Issues
- Ports, pins, circuits, connections
- MShift™ Discussion
Forums
- Misc. MShift™
Topics
- MShift™ sitemap
- Template Project Code
- GPIO Board Intro
- MShift™/GPIO
Support Forum
|
MegaShift™ Code
NOTE: v1.100 code is now obsolete. However, it is still the preferred starting point for writing your own code modifications (due to the free compiler restrictions).
For the 'official' latest code, please see the V2.100 code page.
The MegaShift™ 1.100 release code is here:
An uploadable S19 file compiled from the above source is here: Monitor_1100.abs.s19
(Right click and 'save as'.)
Note: When in bootloader mode, the GPIO allows a full 12V to flow in the TCC and Output3 (aka. SolC, 3/2sol) circuits. If your set-up depends on PWM to limit the current in these solenoids, you MUST pull the 5 Amp fuse to these solenoids (shown in this wiring diagram) before entering bootloader mode to load new code. The 4L60E does not need to have the fuse pulled in bootloader mode.
The accompanying INI file is here: GPIO_MShift_1100.ini
(For MegaTune you need to create a project folder with this file in the mtCfg sub-folder - you might have to edit the custom.ini and settings.ini files to eliminate MT start-up errors.) The ini must be renamed GPIO.ini for MegaTune.
The project files for Codewarrior V4.6 Special edition are here: GPIO_MShift_Proj1100.zip (~5MB)
This MegaShift™ code was developed entirely on Codewarrior 4.6 Special Edition. This compiler (actually a compiler/linker/locator) is available for free from Freescale (which used to be called Motorola):
You have to register to get the software. (Note that the link may eventually become stale. If it does, start at www.freescale.com and search for 'codewarrior special edition')
The 'Special Edition' of Codewarrior has a 32 Kbyte code compile limit, and a maximum of 32 files (the number of files and code size are listed on the bottom left side of the Freescale Codewarrior IDE - integrated development environment).
This code is under those limits at 30 files and ~27 Kbytes.
The files required to create a loadable S19 file for the GPIO board using Codewarrior are:
- main.c
- reset.asm
- cltfactor.inc (the file that is used to convert the trans temp ADC count into degrees Fahrenheit)
- loadfactor.inc (the file that is used to convert the load signal, MAP/TPS/MAF, into 'load' for the controller)
- sprfactor.inc (not used - for future expansion)
- Flash.asm
- flash.h
- hcs12def.h
- Monitor_linker.prm
This is a list of general blocks in the initial version of the code (in the order they appear in the source code):
- Notices and Notes
- Copyright and other notices
- General description of the code
- Compiler/Linker/Locator notes
- The 9S12C64 Microcontroller Memory Notes
- 4L60E/GPIO Port Assignments Notes
- CAN Comms Notes
- Port DDR (data direction register) Configuration Notes
- Miscellaneous Notes
- Transmission Error Code Notes
- Defines, Includes, ISR Definitions and Interrupt Table
- Function Prototypes
- Table Includes and Table Size Defines (including default values)
- Revision Number and Signature
- Global Variables
- Function MAIN
- Define local variables
- Initalize PLL (Phase Locked Loop)
- Copy Flash to RAM
- Set Up Input/Ouput ports
- Set Up Timer Ports
- Set Up CRG RTI Interrupt
- Set up SCI Serial Communications Interface
- Set Up PWM on Timer Pins
- Set Up ADC Channels
- Set variable block addresses to be used for CAN communications
- Initialize Variables
- MAIN LOOP
- Update RPM, MAP & Battery Voltage with CAN
- Determine Current Gear
- Update Rolling Load Average
- Update Rolling Shift Switch Inputs
- Set Pressure Control PWM Duty Cycle
- Check if Need to switch to Auto-Mode
- Set the Torque Converter Clutch (TCC)
- Set SOL32 PWM Duty Cycle
- Read Switches switchA, switchB, switchC and lookup manual_gear
- If check/do shift
- direct shift if enabled
- downshifts checked first
- upshifts second
- else auto sequential shift or manual mode
- downshifts checked first
- upshifts second
- Burn Flash if flagged
- Check for reinit command
- Check for CAN reset
- Slow Speedometer Decay
- Repeat MAIN LOOP
- End MAIN Function
Functions:
- tcc_unlock(): Unlocks the torque converter clutch (TCC).
- tcc_lock(): Locks the torque converter clutch if the brakes are not on and the speed threshold is met (returns 1 if TCC was locked, zero otherwise).
- reset_gear(): Set flag for gear out of range.
- reset_switches(): Initialize pressure switch manifold switches.
- vss_reset(): Reset VSS variables.
- reset(): Not used at present.
- get_adc(): Get the analog-digital conversion (ADC) for the channel passed as an argument in the function call.
- get_adc(2) returns the trans temperature (°F if Imperial, °C if Metric),
- get_adc(4) returns the line pressure (psi),
- get_adc(5) returns the voltage (0-5V) on Ampseal pin #24 (port PAD05).
- switch_page(): Used for memory management.
- intrp_1dctable(): 1D table interpolation, not used at present.
- intrp_2dctable(): Used to determine the line pressure PC solenoid PWM duty cycle by looking up in the user specified 12x12 table.
- auto_gear_lookup(): Used to determine the target gear by looking up in the user specified 12x12 table.
- VSS_timer0(): The VSS teeth are timed and counted here for use in calculating the speed and odometer values.
- ISR_Timer_Clock(): This causes events to happen periodically, regardless of the state of the main loop. The CAN message to retrieve the outpc structure from MS-II are initiated here, the ADC conversions are called (get_adc()) from here, and the seconds are updated.
- ISR_TimerOverflow(): Reset after interrupt service routine timer overflow.
- ISR_SCI_Comm(): Handle the serial communications.
- CanInit(): Initialize the CAN communications.
- CanTxIsr(): Send a CAN message.
- CanRxIsr(): Receive a CAN message.
- can_xsub01(): A routine to be executed via a CAN instruction from another processor (currently unused).
- UnimplementedISR(): A 'blank' routine as a 'catch-all' for unimplemented interrupts
- fburner(): Used to initiate a burn of ram memory to flash memory.
- Flash_Init(): Initialize Flash non-volatile memory.
- Flash_Write_Word(): Erase a flash sector.
- waitAwhile(): A delay function to wait while line pressure and TCC are adjusted, and to prevent gear changes while a shift is still pending. It stops the main loop temporarily, but not the interrupt processing.
The code has been written to be as transparent and 'modifiable' as possible. The code is copiously commented, and much of the necessary background material has been included in the source file notes. So the first place to check if you have questions is in the source code comments.
MegaSquirt® and MicroSquirt® controllers are experimental devices intended for educational purposes.
MegaSquirt® and MicroSquirt® controllers are not for sale or use on pollution controlled vehicles. Check the laws that apply in your locality to determine if using a MegaSquirt® or MicroSquirt® controller is legal for your application.
© 2004, 2010 Bruce Bowling and Al Grippo. All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks. This document is solely for the support of MegaSquirt® boards from Bowling and Grippo.