PDA

View Full Version : Source code for Yaris Tachometer


metalshark
12-07-2008, 06:41 PM
http://i351.photobucket.com/albums/q443/scloyd_01/April209DL.jpg
If you want to build a tachometer using a BS2 micro-processor the following will help:
' {$STAMP BS2}
' {$PBASIC 2.5}
'************************************************* **************************************
'* TACHOMETER PROGRAM FOR 2008 TOYOTA YARIS. *
'* VERSON 2.0 BY STAN CLOYD 3/07/2009. *
'* THIS UPDATE EXPANDS TACHOMETER INDICATION RANGE TO 6,800 PLUS RPM AND RAISES RPM *
'*FLASH WARNING (4 hZ FLASH RATE) TO 6,000 RPM. THE YARIS ECU REPORTEDLY STARTS *
'*LIMITING RPM AT 6,400 RPM AND CAN KEEP CALCULATING ECU OUTPUT VALUES UP TO 7,000 RPM.*
'* PARALLAX BS2 PIN #15 IS USED TO READ TACH SIGNAL FROM THE OBD2 SERVICE CONNECTOR.*
'*INPUT SIGNAL IS ATTENUATED FROM A 0-12 VOLT SQUARE WAVE TO A 0-5 VOLT SQUARE WAVE BY *
'*A 100 K CURRENT LIMITING RESISTER AND A 5.01 VOLT ZENER DIODE. OUTPUT PINS #s 0-14 *
'*ARE IMPEDANCE MATCHED TO THE LED LOADS BY LM342-N OP-AMP QUAD PACKS IN A UNITY GAIN *
'*CONFIGURATION. *
'* PULL DOWN RESISTERS WITH A VALUE OF 47 K ARE USED TO KEEP THE PROCESSOR OUTPUTS *
'*FROM FLOATING HIGH WHEN THE LOGIC HAS THEM OFF. COMPARISON OF RPM TO A COMMERCIAL *
'*DIGITAL TACHOMETER SHOWED A 1 % DIFFERANCE AT 650 RPM AND A 1/2 % DIFFERANCE AT *
'*3,200 RPM. CALIBRATION INTEGERS USED ARE FOR A 4 CYLINDER 4-CYCLE ENGINE ONLY. *
'*EEPROM DATA BELOW STORES THE RPM LIMIT VALUES THAT TURN ON AND OFF EACH DISPLAY LED. *
'************************************************* **************************************
DATA Word 540, Word 950, Word 1400, Word 1850, Word 2300 'EPROM DATA
DATA Word 2750, Word 3200, Word 3650, Word 4100, Word 4550 'EPROM DATA
DATA Word 5000, Word 5450, Word 5900, Word 6350, Word 6800 'EPROM DATA

'************************************************* ***********
'* DECLARATIONS & INITIALIZATIONS *
SAMPLE_L VAR Word '*INPUT SQUARE WAVE TIME-LOW COUNT *
SAMPLE_H VAR Word '*INPUT SQUARE WAVE TIME-HIGH COUNT *
PERIOD VAR Word '*TOTAL SQUARE WAVE PERIOD COUNT (INVERSE OF FREQUENCY) *
RPM VAR Word '*REVOLUTIONS PER MINUTE (CRANKSHAFT RPM) *
RPM_L VAR Word '*RPM CELL LIMITS READ FROM EEPROM TABLE *
INDEX VAR Byte '*OUTPUT PIN INDEX # *
CAL1 VAR Byte '*SCALING CONSTANT TO KEEP CAL2 BELOW INTEGER OVERFLOW LIMIT*
CAL2 VAR Word '* *
CAL1=230 '*FOUR CYLINDER ENGINE-SPECIFIC CALIBRATION VALUE *
CAL2=63050 '*FOUR CYLINDER ENGINE-SPECIFIC CALIBRATION VALUE *
'************************************************* ***********

START: '************************************************* ***********
PERIOD = 0 '*RESET/CLEAR LAST SCAN-LOOP VALUES *
SAMPLE_L= 0 '* *
SAMPLE_H= 0 '* *
RPM = 0 '* *
'* *
PULSIN 15, 0, SAMPLE_L '*SAMPLE PIN #15 LOW COUNT AT ZERO VOLTS *
PULSIN 15, 1, SAMPLE_H '*SAMPLE PIN #15 HIGH COUNT AT 5 VOLTS *
PERIOD = SAMPLE_L+SAMPLE_H '*CALCULATE TOTAL PERIOD COUNT *
PERIOD = PERIOD/CAL1 '*SCALING FACTOR TO PREVENT POSITIVE INTEGER OVERFLOW *
RPM = CAL2/PERIOD '*CALULATE RPM *
'* *
IF RPM>6000 THEN '*FLASH LEDS ON AND OFF AT 4 HZ WHEN RPM EXCEEDS 6000 RPM *
'*(SHIFT WARNING). *
FOR INDEX=0 TO 14 '************************************************* ***********
LOW INDEX
NEXT
PAUSE 25
ENDIF






'********************************************
FOR INDEX=0 TO 28 STEP 2 '*TURN ON CORRECT LEDS FOR ANALOG DISPLAY *
READ INDEX, RPM_L.LOWBYTE '*INDICATION(ENGINE-RUNNING CONDITION ONLY).*
READ (INDEX+1), RPM_L.HIGHBYTE '********************************************
IF RPM>RPM_L THEN
HIGH (INDEX/2)
ELSEIF RPM<RPM_L THEN
LOW (INDEX/2)
ENDIF
NEXT
'********************************************
DO WHILE PERIOD=0 '*REVERSING STROBE FLASH SEQUENCE WHEN *
FOR INDEX=0 TO 14 '*IGNITION KEY IS ON BUT ENGINE IS NOT *
HIGH INDEX '*RUNNING (HARDWARE DIAGNOSTIC). *
PAUSE 20 '********************************************
LOW INDEX
PAUSE 20
NEXT
FOR INDEX=14 TO 0
HIGH INDEX
PAUSE 20
LOW INDEX
PAUSE 20
NEXT
LOOP
GOTO START

custom Lftback
12-07-2008, 07:15 PM
wow that makes no sense to me. lol

metalshark
12-07-2008, 09:08 PM
A smart alec would say its basic but actually its pBasic.wow that makes no sense to me. lol

auxmike
12-07-2008, 09:12 PM
You are a mental giant!:bow:

metalshark
02-28-2009, 06:29 AM
Had to change jobs and be punished on day shift for a while. Here is the schematic from which I'm working on a 2-layer board layout.
http://i351.photobucket.com/albums/q443/scloyd_01/tachboard.jpg

metalshark
03-30-2009, 10:41 PM
Had to change jobs and be punished on day shift for a while. Here is the schematic from which I'm working on a 2-layer board layout.
http://s351.photobucket.com/albums/q443/scloyd_01/
I ordered 3 2-layer copper boards for this project today. Express should have them back Wednesday. These won't have a solder mask or silkscreen but may work.

jkuchta
03-30-2009, 11:03 PM
Can't wait to see how they come out...I have the plugs almost done for my steeringwheel project!

metalshark
03-31-2009, 06:46 PM
I will have 2 extra boards left over and some parts. I can solder in the parts I have and sell the extra boards with the schematic, bill of material, and source code listing if anyone is interested. I'll post all the pics here if it was laied out correctly. It was my first layout going to the etcher.

jkuchta
04-02-2009, 03:39 AM
My soldering abilities are good enough to connect wires, but not good enough to populate a board. What would one cost assembled (I can wire the thing into the car)?

CtrlAltDefeat
04-02-2009, 03:52 AM
I am very interested in this... If I read the schematics correctly it uses LEDs to show the revs... how responsive will this be? If it's cheaper then an aftermarket tach and can be made to look good I would love a DIY tach... trying to think of where would be best to put the LEDs...

metalshark
04-02-2009, 06:14 PM
http://i351.photobucket.com/albums/q443/scloyd_01/April209DL066.jpg
http://i351.photobucket.com/albums/q443/scloyd_01/ProtoStichWire.jpg
http://i351.photobucket.com/albums/q443/scloyd_01/HPIM1368.jpg

The first picture is the trial layout.

The second picture is the stitch wire prototype I've used in the car for a year now.

The third picture is how I installed 15 LEDs in the dash. The display is currently set to start flashing all lit lites at 4 Hz when my revs hit my 6000 RPM shift point. The top red comes on at 6'800 RPM as programed and, yes the mill will make it.

metalshark
04-02-2009, 06:22 PM
My soldering abilities are good enough to connect wires, but not good enough to populate a board. What would one cost assembled (I can wire the thing into the car)?As beta test consumer I might be able to cost it low. The biggest problem is the BS2 chip costs $50. I need to re-prototype this project using the new Parallax Propeller chip since they just dropped the cost to $7.95. The propeller has so many beans you could put the entire Toyota engine management code on it if they would let you have a copy. The parts at-cost is roughly $80 without display LED's AND you'd want me to load the program into the BS2 EEPROM for you too. It is a neat integrated prototype though and cops always ask what it is because when the key is on and the motor dead the display chases left to right and right to left like the original KIT. The cops have to know its not an illegal mobile police scanner. They give it a thumbs up. In a Propeller version I would integrate the dash dimmer control into the unit.

POORSHA
04-02-2009, 07:10 PM
i would be interested in your extra board and parts. i have been looking for a tach like this for a while. pm me when you know more.

metalshark
04-02-2009, 07:20 PM
I am very interested in this... If I read the schematics correctly it uses LEDs to show the revs... how responsive will this be? If it's cheaper then an aftermarket tach and can be made to look good I would love a DIY tach... trying to think of where would be best to put the LEDs... The BS2 chip scans at 20,000 cycles per second on its clock. The entire code is less than 100 lines. The output display driver section is a rather primitive analog/linear op-amp arrangement but it is very fast. This design is WAY faster in its response than any mechanical tachometer needle can possibly be. The code uses the pulsein command for data and in a worst case situation will generate an accurate RPM number in one revolution of the crankshaft.

CTScott
04-02-2009, 09:17 PM
As beta test consumer I might be able to cost it low. The biggest problem is the BS2 chip costs $50. I need to re-prototype this project using the new Parallax Propeller chip since they just dropped the cost to $7.95. The propeller has so many beans you could put the entire Toyota engine management code on it if they would let you have a copy. The parts at-cost is roughly $80 without display LED's AND you'd want me to load the program into the BS2 EEPROM for you too. It is a neat integrated prototype though and cops always ask what it is because when the key is on and the motor dead the display chases left to right and right to left like the original KIT. The cops have to know its not an illegal mobile police scanner. They give it a thumbs up. In a Propeller version I would integrate the dash dimmer control into the unit.

Switch to a Microchip PIC microcontroller. Same or better functionality for <$5 max and many of the PICs can directly drive LEDs with the outputs.

For example the PIC16F57 is $1.55 and has 20 I/O Pins and runs at up to 20mHz. If you're not comfortable with C or assembly programming, there is even a basic compiler for the PICs.

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F57-I/P-ND

fuji
04-02-2009, 10:12 PM
This project has tons of potential and looks great! When will it be avaliable for the rest of us willing to pay?????:biggrin::thumbup:

Shroomster
04-03-2009, 12:00 AM
lol might want to pm PK about this...I've been trying for months w/o success to procure a gauge cluster for him....

CtrlAltDefeat
04-03-2009, 03:33 AM
The biggest problem is the BS2 chip costs $50. I need to re-prototype this project using the new Parallax Propeller chip since they just dropped the cost to $7.95. yes, $50 for just the chip would be way too much, an aftermarket tach would cost less. The Propeller version, however, sounds right up my alley... I think it would look good with rectangle or square LEDs (or rectangle shaped covers) closely set together. It would be awesome to somehow incorporate it into the gauge cluster...

metalshark
04-03-2009, 05:01 AM
Switch to a Microchip PIC microcontroller. Same or better functionality for <$5 max and many of the PICs can directly drive LEDs with the outputs.

For example the PIC16F57 is $1.55 and has 20 I/O Pins and runs at up to 20mHz. If you're not comfortable with C or assembly programming, there is even a basic compiler for the PICs.

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F57-I/P-ND

Thanks for the info. If I wanted to sell these I'd do as you suggest. I'd rather just release the info as public domain/open source and move on. Porting to the Propeller with tach projects would be something I'd do just to learn Spin and cog assembler. I've programmed in C and assembler in the past so that's nothing new. I'm also on DIYelectriccar.com. On there I advocate using a Propeller to build an AC drive for an electric car. I've been building files on IGBTs, fiber optics, true vector drives and so-on. By building up my skill set I'll have the drive and car ready about the time the lithium batteries are available at a competitive cost. Now a good set runs $20-25K. Not something I'll do while gas costs just $2/gallon.

JustAnotherAsian
04-03-2009, 05:10 AM
The BS2 chip scans at 20,000 cycles per second on its clock. The entire code is less than 100 lines. The output display driver section is a rather primitive analog/linear op-amp arrangement but it is very fast. This design is WAY faster in its response than any mechanical tachometer needle can possibly be. The code uses the pulsein command for data and in a worst case situation will generate an accurate RPM number in one revolution of the crankshaft.
^20,000 per second... without delay incorporated, you are correct with the accuracy statement- it will be annoyingly accurate.
Switch to a Microchip PIC microcontroller. Same or better functionality for <$5 max and many of the PICs can directly drive LEDs with the outputs.

For example the PIC16F57 is $1.55 and has 20 I/O Pins and runs at up to 20mHz. If you're not comfortable with C or assembly programming, there is even a basic compiler for the PICs.

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F57-I/P-ND
^i was gonna suggest the same thing. i'm sure with enough fishing, someone already put out a tach program in C.

Thanks for the info. If I wanted to sell these I'd do as you suggest. I'd rather just release the info as public domain/open source and move on. Porting to the Propeller with tach projects would be something I'd do just to learn Spin and cog assembler. I've programmed in C and assembler in the past so that's nothing new. I'm also on DIYelectriccar.com. On there I advocate using a Propeller to build an AC drive for an electric car. I've been building files on IGBTs, fiber optics, true vector drives and so-on. By building up my skill set I'll have the drive and car ready about the time the lithium batteries are available at a competitive cost. Now a good set runs $20-25K. Not something I'll do while gas costs just $2/gallon.
^interesting! cost of lithium-ion" batteries will definitely drop within the next few years.

metalshark
04-03-2009, 05:14 AM
yes, $50 for just the chip would be way too much, an aftermarket tach would cost less. The Propeller version, however, sounds right up my alley... I think it would look good with rectangle or square LEDs (or rectangle shaped covers) closely set together. It would be awesome to somehow incorporate it into the gauge cluster... I've figured out how to do that but people with more experience than I already know the cost of this can be shrunk a lot by just going to a cheaper microprocessor. When I get two of these beta test units out into the field I'd rather just public domain all the technical data to a thread/sticky on Yaris-World.com and let the hobby members grow the project. A processor in the BS2 class can be had for about $5 and support up to 4 digital readouts with ease. One like the BS2p40 can support up to 8 digital readouts or even more with serial display panel. At that point its getting into the full dash board display area. This is the type thing the folks at scan-gage are good at. The Parallax Propeller can support a small video display complete with graphics.

metalshark
04-03-2009, 06:08 AM
lol might want to pm PK about this...I've been trying for months w/o success to procure a gauge cluster for him....

send him this link. http://www.parallax.com/Store/Accessories/Displays/tabid/159/CategoryID/34/List/0/Level/a/ProductID/337/Default.aspx?SortField=ProductName%2cProductName

metalshark
04-03-2009, 07:01 AM
Switch to a Microchip PIC microcontroller. Same or better functionality for <$5 max and many of the PICs can directly drive LEDs with the outputs.

For example the PIC16F57 is $1.55 and has 20 I/O Pins and runs at up to 20mHz. If you're not comfortable with C or assembly programming, there is even a basic compiler for the PICs.

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F57-I/P-ND

I bookmarked it to look at after I catch up on sleep.

metalshark
04-04-2009, 07:26 PM
Switch to a Microchip PIC microcontroller. Same or better functionality for <$5 max and many of the PICs can directly drive LEDs with the outputs.

For example the PIC16F57 is $1.55 and has 20 I/O Pins and runs at up to 20mHz. If you're not comfortable with C or assembly programming, there is even a basic compiler for the PICs.

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F57-I/P-ND Even though I'm building my last two BS2 based tachometers I ordered the chip you recommended. Its expanded I/O will allow me to incorporate features already requested by my beta testers, (ambient light sensor/auto dimming & auxiliary digital readout.).

metalshark
04-04-2009, 07:31 PM
yes, $50 for just the chip would be way too much, an aftermarket tach would cost less. The Propeller version, however, sounds right up my alley... I think it would look good with rectangle or square LEDs (or rectangle shaped covers) closely set together. It would be awesome to somehow incorporate it into the gauge cluster... Another Yaris-World member is incorporating the display into the steering wheel on a beta test unit. I'm porting the application over to a better, cheaper uP as suggested by a member that has more experience than I. With the reduced hours at work, I'm starting to make better progress on the hobby.

metalshark
04-05-2009, 07:36 AM
Switch to a Microchip PIC microcontroller. Same or better functionality for <$5 max and many of the PICs can directly drive LEDs with the outputs.

For example the PIC16F57 is $1.55 and has 20 I/O Pins and runs at up to 20mHz. If you're not comfortable with C or assembly programming, there is even a basic compiler for the PICs.

http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F57-I/P-ND
What is the equipment to get started with it run? I talked to a Microchip forum member this morning that is recommending the 16 bit PIC24/dspic trouble being that the starter kit is $300. On the up side the kit comes with a student version C compiler.

CTScott
04-05-2009, 09:51 AM
What is the equipment to get started with it run? I talked to a Microchip forum member this morning that is recommending the 16 bit PIC24/dspic trouble being that the starter kit is $300. On the up side the kit comes with a student version C compiler.

You can spend from $10 to $1000 to get going. You can download the student/evaluation versions of the compilers for free from Microchip's website. The purchased version adds optimization, but I seldom compile with optimization, as I find it often messes up critical timing.

$10 Programmer for many processors:
http://robokitsworld.com/index.php?main_page=product_info&products_id=57&zenid=sbie9l3vqjakfl6nbiqsr52nu0


$50 programmer (USB/serial):
http://www.hobbyengineering.com/H3317.html


Real Microchip programmers:

PicKit2 (directly integrates with Microchip's development system):
http://www.microchipdirect.com/ProductDetails.aspx?Catalog=BuyMicrochip&Category=Getting%20Started%20Programmers&mid=1&treeid=6

$220 Microchip In Circuit Debugger:
The latest version is the ICD3. I use the ICD2 for most of my development work.
http://www.microchipdirect.com/productsearch.aspx?Keywords=icd3


To use the Pickit2 or ICD2/3 you have to add a header (or RJ11 jack) to your board to connect to. The two third party programmers allow you to plug the DIP package IC's in for programming.

metalshark
04-06-2009, 01:41 AM
Here are the photos at the end of the day. Testing so far: Power supply OK. Input circuit OK. 15 Led driver amps OK. Tomorrow I check out the RS-232 connection.
http://i351.photobucket.com/albums/q443/scloyd_01/45ACP019.jpg
http://i351.photobucket.com/albums/q443/scloyd_01/45ACP018.jpg