Sei sulla pagina 1di 6

;-------------------------------------------------------------------------------

--------------
;Description: Program for replacing the exhaust servo mechanism on a 2008-1020 H
onda CBR1000RR
; Hereby called the Exhaust Servo Replacement Module (ESRM)
; Copyright (C) 2009 Pat Fruth
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
;Version: 1.1
;Date: 12.20.2009
;MCU: PIC16F683
;Author: Pat Fruth email:pat@patfruth.com
;Change History:
; V1.0 12.15.2009
; Initial stable version. Implemented on PIC16F88
; V1.1 12.20.2009
; Ported to smaller (8-pin), but equally capable, PIC12F683
;-------------------------------------------------------------------------------
--------------
; DISCLAIMER:
; IN NO EVENT, UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SHALL
I, OR ANY
; PERSON BE LIABLE FOR ANY LOSS, EXPENSE OR DAMAGE, OF ANY TYPE OR NATURE ARISIN
G OUT OF THE
; USE OF, OR INABILITY TO USE THIS SOFTWARE OR PROGRAM, INCLUDING, BUT NOT LIMIT
ED TO, CLAIMS,
; SUITS OR CAUSES OF ACTION INVOLVING ALLEGED INFRINGEMENT OF COPYRIGHTS, PATENT
S, TRADEMARKS,
; TRADE SECRETS, OR UNFAIR COMPETITION.
;-------------------------------------------------------------------------------
--------------
;Overview:
; The 2008-2010 Honda CBR1000RR motorcycle incorporates an exhaust gas control v
alve (EGCV).
; The EGCV is located inside the muffler, just inside the tip of the exit. The
EGCV's purpose
; is to quiet the motorcycle's exhaust note, by closing, during low speed/rpm ri
ding conditions.
; During high speed/rpm riding, the valve opens, allowing for maximum performanc
e. The EGCV is
; open and closed by an electro-mechanical servo, which is controlled by the mot
orcycle's Engine
; Control Module (ECM).
;
; Upon replacing the CBR1000RR stock exhaust system, with an after-market exhaus
t, there is often
; no longer a need for the EGCV servo. Thus, it is desirable to remove the serv
o.
; However, simply removing the servo is not possible, without causing the check
engine light (aka.
; malfunction indicator lamp) to illuminate, due to the lack of feedback from th
e EGCV servo
; mechanism.
;
; This program effectively simulates the electrical characteristics of the EGCV
servo. This
; program interfaces with the motorcycle's ECM, by interpreting signals/commands
, that would
; normally be sent to the servo, and producing the necessary output signal, that
would normally
; be fed back to the motorcycle's ECM (by the servo). In doing so, the stock se
rvo may be
; removed, thus reducing weight, and freeing up much needed space.
;
; The stock servo mechanism is comprised of a simple DC motor, which is coupled
to an output
; shaft, via a small gear reduction transmission. The end of the output shaft h
as a wheel/arm
; affixed, to which a cable attaches. This cable is then routed to the EGCV, in
side the muffler.
; There is a standard three-terminal 5K ohm potentiometer (POT) mechanically fix
ed to the servo's
; wheel/arm, which is used as the means of determining proper servo wheel positi
oning. The 5K ohm
; POT is configured as a simple voltage divider, in a 5V circuit. Based on posi
tioning, the
; voltage at the POT's wiper will be anywhere from 0 - 5V. The wiper voltage is
fed back to the
; ECM, whereby it is then used as a means to determine proper positioning of the
servo wheel.
; The ECM will determine which direction the servo motor needs to turn, how far,
and how fast.
; As the servo wheel is repositioned, the ECM continues to monitor the POT's wip
er voltage, until
; the proper position is achieved, at which time the servo motor is turned off.
; The signal, provided by the ECM, is interrupted DC, with a 12V magnitude. The
signal is a
; 1KHz square wave, whose duty cycle varies depending on speed.
;
; This program simulates the stock servo motor by -
; Interpreting which direction the ECM is commanding the motor to run
; Varying the feedback voltage sent back to the ECM
;
; GPIO, pins GP0 & GP1, are configured as input pins, and are used to determine
whether the
; feedback voltage should be increased or decreased. If GP0 goes high, the the
feedback
; voltage should be decreased. If GP1 goes high, the the feedback voltage shoul
d be increased.
; Feedback voltage is generated by configuring the CCP module to run in PWM mode
. The PWM
; frequency is set to 1.9Khz, and the duty cycle is varied, depending on the dir
ection inputs
; (described above). The PWM signal is available on the CCP1 pin. To achieve a
flat/stable
; feedback voltage, this 5V 1.9Khz square wave is then routed to a simple two st
age R-C type
; low pass filter. A nearly continuously variable voltage is produced by varyin
g the duty cycle.
;
; Following are typical feedback voltages observed during design, testing, and c
onstruction of
; the ESRM.
; - Initial power-up.
; Immediately after turning on the motorcycle's ignition switch - 2.25V
; - Starting.
; While pressing the starter button - voltage briefly goes to 4.5V, then dow
n to .3V
; - Once the engine is started, and idling, the voltage settles to .3V
; - With the engine running, and the motorcycle in 6th gear
; The voltage remains at .3V while engine RPMs are below 4,000.
; Upon increasing engine RPM to 4,000 RPM or above, the voltage increases to
4.5V
;-------------------------------------------------------------------------------
--------------
ERRORLEVEL -302 ;remove message about using proper bank
;***** Declarations and microcontroller configuration *****
PROCESSOR 12F683
#include "P12F683.inc"
__CONFIG _CP_OFF&_CPD_OFF&_BOD_ON&_MCLRE_OFF&_PWRTE_ON&_WDT_OFF&_INTOSCIO&_F
CMEN_OFF&_IESO_OFF
;***** Declaration of variables *****
cblock 0x20 ; Beginning of RAM in bank 0
NEWDUTYLSB ; Least significant 2 bits of the new duty cycle
NEWDUTYMSB ; Most significant 8 bits of the new duty cycle
LOOPCNT ; Loop counter, used by the pause routine
endc
;***** Declaration of symbol equates *****
VOLTSDOWN equ 0 ; GPIO, pin GP0, Decreace duty cycle
VOLTSUP equ 1 ; GPIO, pin GP1, Increase duty cycle
;***** Beginning of program memory structure *****
ORG 0x00 ; Reset Vector
goto Init ; After power-on-reset, jump to this location
ORG 0x04 ; Interrupt vector
goto IntSvc ; Interrupt Service routine
;***** Beginning of interrupt service routine *****
; This code is executed any time an "Interrupt", of any kind, occurs.
; Here we place logic that queries the various interrupt flags in order to deter
mine the reason
; for the interrupt.
IntSvc
retfie ; Return from interrupt
Init
; Initialize the system clock oscillator frequency
banksel OSCCON
bsf OSCCON,IRCF2 ; IRCF2:IRFC1:IRFC0 = b'111'
bsf OSCCON,IRCF1 ; Configure the internal clock to run at 8MHz
bsf OSCCON,IRCF0
; Initialize the Watch Dog Timer prescaler for a 1 second timeout
banksel WDTCON
movlw B'00010100' ; period select = 1:32768, SWDTEN = 0 (off)
movwf WDTCON
bcf OPTION_REG,PS2 ; PS2:PS0 = 000 means prescaler 1:1
bcf OPTION_REG,PS1
bcf OPTION_REG,PS0
; Initialize Comparators
banksel CMCON0
movlw B'00000111' ; Disable Comparator. Make all channels digital
I/O
movwf CMCON0
; Initialize A/D converter channels
banksel ANSEL
movlw B'00000000' ; Disable A/D converter. Make all channels digit
al I/O
movwf ANSEL
; Intialize GPIO
banksel TRISIO
movlw b'00000011' ; Make GPIO output, except GP0 & GP1
movwf TRISIO
; Setup the CCP module to do PWM
banksel CCP1CON
bsf CCP1CON,CCP1M3 ; configure the CCP module to run in PWM active-
high mode
bsf CCP1CON,CCP1M2
bcf CCP1CON,CCP1M1
; Configure Timer2 (the time base for the PWM module) for the overall PWM freque
ncy
; Frequency is given by the formula - (Fosc/4) / (T2 pre-scaler) / (PR2)
; If Fosc=8Mhz, T2PS = 4, and PR2 = 255, then we have a PWM freq = 1920 Hz
banksel T2CON
bsf T2CON,T2CKPS0 ; set TMR2 prescaler to 4
banksel PR2
movlw 0xFF ; set period register to divide TMR2 by 255
movwf PR2
; Initialize RAM variables
banksel 0
clrf NEWDUTYLSB
movlw 0x80
movwf NEWDUTYMSB
movwf CCPR1L
bsf T2CON,TMR2ON ; finally, start Timer2 running
; Main loop
Loop
btfsc GPIO,VOLTSUP ; Is the ECM commanding the motor to run in a di
rection
; that would result in an increased voltage of
the POT?
call DoVoltsUp ; Yes, go increass the PWM duty cycle
btfsc GPIO,VOLTSDOWN ; Is the ECM commanding the motor to run in a di
rection
; that would result in an decreased voltage of
the POT?
call DoVoltsDown ; Yes, go decrease the PWM duty cycle
goto Loop ; Start over again
; Increase feedback voltage
DoVoltsUp
movfw NEWDUTYMSB ; Is the duty cycle already at maximum?
xorlw 0xFF
btfsc STATUS,Z
return ; Yes, do nothing, and get out
call DutyUp ; Otherwise, so go increment the duty cycle coun
ters
call SetDuty ; And make em take effect
return
; Decrease feedback voltage
DoVoltsDown
movfw NEWDUTYMSB ; Is the duty cycle already at minimum?
btfsc STATUS,Z
return ; Yes, do nothing, and get out
call DutyDown ; Otherwise, so go decrement the duty cycle coun
ters
call SetDuty ; And make em take effect
return
; Increase duty cycle counters
DutyUp
incf NEWDUTYLSB,F ; Add 1 to the least significant 2 bits
btfss NEWDUTYLSB,2 ; Have we wrapped?
return ; No
clrf NEWDUTYLSB ; Yes, reset the least significant 2 bits
incf NEWDUTYMSB,F ; And, add 1 to the most significant 8 bits
return
; Decrease duty cycle counters
DutyDown
decf NEWDUTYLSB,F ; Subtract 1 from the least significant 2 bits
btfss NEWDUTYLSB,7 ; Have we wrapped?
return ; No
movlw 0x03 ; Yes, reset the least significant 2 bits
movwf NEWDUTYLSB
decf NEWDUTYMSB,F ; And, subtract 1 from the most significant 8 b
its
return
; Put the new duty cycle counters into effect
SetDuty
swapf NEWDUTYLSB,W
iorlw b'00001100'
movwf CCP1CON
movfw NEWDUTYMSB
movwf CCPR1L
call Delay1ms ; Give the low-pass filter capaciters a chance t
o [dis]charge
return
; Waste 1ms worth of processing time, doing nothing
; Note: Assumes an 8Mhz processor clock frequency (Fosc)
Delay1ms ; Delay1ms produces a one milisecond delay
movlw .200 ; 200*10us=1ms
movwf LOOPCNT ; LOOPcnt<-200
DelayLoop ; -----------------
nop ; / \
nop ; |
nop ; |
nop ; 10us
nop ; |
nop ; |
nop ; |
decfsz LOOPCNT,F ; \ /
goto DelayLoop ; -----------------
return
End

Potrebbero piacerti anche