Electronics PIC input questions

Discussion in 'Modding' started by shotgunefx, 27 Oct 2004.

  1. shotgunefx

    shotgunefx What's a Dremel?

    Joined:
    4 Feb 2004
    Posts:
    449
    Likes Received:
    0
    I'm gathering some info on project for my car. I want to replace my dash with a digital one (eventually).

    I'm going to use OBD-II for most of the capture (I've got an Elmscan box). Unfortunately, the sample rate is rather slow (3 ~ 4s a second) and won't do for a speedometer or tachometer. Instead of tapping into the ECU's (There's 7 on a dedicated bus), I'd like to tap into the electronics for the gauges which seems less perilous. I also need to tap the turn signals outputs.

    The speedometer signal that I'd like to tap is a 5v pulsed signal. (4 pulses per revolution of speed sensor).
    The tach signal is similar but 12v. So the first stage is to use a PIC to read these signals, time the internvals and output the value serially.

    I've got a pretty good notion of how to do most of this with a PIC (software anyway), my concern is how to minimize the effect on the existing instrument panel. Anyone have any recommendations? How much current is required to drive a pin high? I've looked at the specs and while I'm sure the answer is in there, I can't find it.

    Thanks,
    -Lee
     
  2. theshadow27

    theshadow27 What's a Dremel?

    Joined:
    23 Sep 2004
    Posts:
    616
    Likes Received:
    2
    the PIC will sink 50ma, but i would use an opto isolator. thats what is industry standerd for stuff like this. ultra low current draw, and it will stop any electrical spikes from the engine from getting into your circuts. with 1 resistor you can make the same model isolator run 12v or 5v. throw a 13.2v zener on there, and your set to go. the pic should have plenty of time to count pulses, but if you used a dedicated timer + counter chips you could get higher accurcy with out taxing your prossesor.
     
  3. ConKbot of Doom

    ConKbot of Doom What's a Dremel?

    Joined:
    2 Jul 2003
    Posts:
    2,160
    Likes Received:
    6
    A pic sinks current only when it is an low output. When it is an input, it is high-impedance. Should be fine to hook straight to the signal. If you really want to you can use an op-amp or comparitor to provide more isolation. An opto-isolator would actually draw more current, since it has to run the LED.

    EDIT: BTW don't put 12v into the PIC, use a zener diode to dro voltage, or something else to lower the voltage.
     
  4. theshadow27

    theshadow27 What's a Dremel?

    Joined:
    23 Sep 2004
    Posts:
    616
    Likes Received:
    2
    if he uses a zener diode, it will mess up the gauges that are ment to run off 12v. i helped the guys that worked on megasquirt (http://www.megasquirt.info/) and there were so many problems with the 12v tach signal (it comes right from the ignition coil!!). a optoisolator and a tiny capacitor fixed it right up. as for the spedo, thats a sensor on the trany and you could probably hook it right up to the pic, but because of the EMI i would use an isolator for that too. the PIC input is highZ at 3.3 volts, as voltage increases, resistance decreases. hooking up 5 "car" volts to a PIC pin is a great way to fry it.

    car electronics are a whole diffrent beast then 12v robotics (ive been head of electronics for 3 years in FIRST), computer electronics, or just about anything else. the whole pricaple of regular ignition is basicly a big radio transmitter, and PICs, and just about any regualr microchip dont like that. also, as voltage decreases with RPM increase (current goes up, voltage down), there is a lot of variation in voltage, all the time. optoisolators help a lot for input, and for output you genraly need a optoisolator and a big FET/MOSFET with large flyback circut.

    so in a perfect world, you could use a diode + zener diode and hook that up to one pin, and you could hook 5 volts up to the other pin, and the PIC would be happy. but in any real car, you will get a rediculous amout of resetting, brownouts, and random memory errors. (been there, by the 6th chip its :wallbash: )
     
  5. ConKbot of Doom

    ConKbot of Doom What's a Dremel?

    Joined:
    2 Jul 2003
    Posts:
    2,160
    Likes Received:
    6
    meh, forgot that cars don't exactly have nice power :duh: yeah 12v anywhere from 10-18v and spikes to 40+ :wallbash:

    /me puts on the dunce cap
     
  6. shotgunefx

    shotgunefx What's a Dremel?

    Joined:
    4 Feb 2004
    Posts:
    449
    Likes Received:
    0
    My original tach was a LM2917 which ran off the coil. Had quite a few problems. This one is going to read an output from the ECU that reads the tach signal. I'm thinking I'll have enough speed to do everything I want, but if not I'll dedicate a pic to this directly.
     
  7. shotgunefx

    shotgunefx What's a Dremel?

    Joined:
    4 Feb 2004
    Posts:
    449
    Likes Received:
    0
    The speedometer signal I'm tapping is output from one of the car's ECUs and not directly from the sensor (because it's a nice 5v regulated signal). Same with the tach (except voltage is 12v). The ecu reads the tach signal coming from the distributor and then outputs a nice signal to the tach display. So a 5.6v zener on the tach signal input pin would do the trick?
     
  8. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    Zener diodes are a bad way to buffer a signal.

    Since it is a car, I second the use of opto-isolators. Use a resistor for half the mAmps required for the internal LED so that spikes dont burnit out. Use a pull-up resistor on the output since its a transistor output.

    And no PIC sinks or sources 50mAmps on a single pin. 25mAmps is maximum, and thats where it should burn-out, not where it should constantly run.

    Oh, and buffer the 5V signal with an opto also. Auto voltages are just too damn messy.
     
  9. shotgunefx

    shotgunefx What's a Dremel?

    Joined:
    4 Feb 2004
    Posts:
    449
    Likes Received:
    0
    The only reason I've shyed away from optoisolators is that when in the past, I've looked (at say mouser) I've found trying to figure out which one is appropriate difficult. Though I'm not too worried about surges as from what I've seen (and read) the ECU outputs are clean (other people have scoped them when interfacing aftermarket fuel controllers etc) and the service manuals themselves list 5v and 12v as the maximum voltages that should be observed without considering the ECU defective.

    Wouldn't happen to have a part number in mind for the optoisolator?

    Thanks,
    -Lee
     
  10. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    4n25
     
  11. shotgunefx

    shotgunefx What's a Dremel?

    Joined:
    4 Feb 2004
    Posts:
    449
    Likes Received:
    0
    Thanks. I got them and finally got around to playing with them. No problems and nice and easy to use. So I've traced out all the signals I need to tap. Now to the fun stuff.

    The pic is going to be doing software pwm as well as processing some inputs.

    I need 4 inputs.
    the tach signal, the speedometer signal, and the left and right directional signals.
    The tach signal generates 4 pulses per revolution.
    The speedo signal generates 4 pulses per mile (I believe).
    The directionals pulse about once per second when active.

    The pic will sample these and output the tach and speedo serially (amongst other things for use in my soon to have carpc).

    I'd like to output 10 samples of the speedo and tach per second serially.

    Here is what I was thinking. I'd appreciate any comment or criticism.

    I'm thinking of using the PORTB Interrupt on change. I've got a TMR0 interrupt (for other things) occuring at the least every millisecond.
    My plan is to count the tach signals during the PORTB interrupts and every 100 milliseconds save the value (for the main code to transmit) and reset the counter.

    I'm figuring at 4 pulses per revolution (and using integer math), the maximum rpm I need to consider is 10000 rpm (though likely my engine would seize well before that, 6k is redline), so the most pulses I could have in a 100 millisecond window is roughly 66. ( 10,000 * 4 / 60 / 10 = 66 )

    The minium rpm I need to consider is 500 rpm, my engine would probably stall below 700 rpm, so the minimum pulse count I can get is 3 ( 500 * 4 / 60 / 10 = 3)

    So it looks like this would work. My factory tach is listed at having an error of ~100rpm @ 700 rpm and ~300 rpm at 6000 rpm. According to my calculations, my maximum drift (not counting a missed or extra pulse) is 100 rpm. Not too bad. If a pulse is missed or an extra pulse is "added" due to drift, it makes the worst case error at <=250 rpm.

    RPM = Rotations per Minute
    CALC = Calculated RPM
    DIFF = Difference between actual and calculated RPM
    PULSE = Pulse Count (4 x RPM)
    PPS = Pulses per second at RPM
    SAMPLE = Pulses received in the sampling interval (100ms)
    ERROR_RANGE = Range if one pulse is missed or one extra is counted in sampling frame
    -----------------------------------------------------------
    RPM: 500 CALC: 450 DIFF: 50 Pulse: 2000 PPS: 33 SAMPLE: 3 ERROR_RANGE: 300 - 600 (200 rpm)
    RPM: 2000 CALC: 1950 DIFF: 50 Pulse: 8000 PPS: 133 SAMPLE: 13 ERROR_RANGE: 1800 - 2100 (200 rpm)
    RPM: 3500 CALC: 3450 DIFF: 50 Pulse: 14000 PPS: 233 SAMPLE: 23 ERROR_RANGE: 3300 - 3600 (200 rpm)
    RPM: 5000 CALC: 4950 DIFF: 50 Pulse: 20000 PPS: 333 SAMPLE: 33 ERROR_RANGE: 4800 - 5100 (200 rpm)
    RPM: 6500 CALC: 6450 DIFF: 50 Pulse: 26000 PPS: 433 SAMPLE: 43 ERROR_RANGE: 6300 - 6600 (200 rpm)
    RPM: 8000 CALC: 7950 DIFF: 50 Pulse: 32000 PPS: 533 SAMPLE: 53 ERROR_RANGE: 7800 - 8100 (200 rpm)
    RPM: 9500 CALC: 9450 DIFF: 50 Pulse: 38000 PPS: 633 SAMPLE: 63 ERROR_RANGE: 9300 - 9600 (200 rpm)


    Does this sound reasonable? I've not doing anything with PORTB interrupt on change, but from what I've read, it seems like it should work.

    As far as the speedometer, I'm still contemplating that one. But from what I can dig up it's a 5v pulsed signal that I believe is 4 pulses per mile. What determines the "frame" of this signal I'm not really sure. (Anyone more familiar with this?)

    Thanks,
    -Lee
     

Share This Page