Speedometer / odometer on IN14


    Good day!
    Once again, creativity attacked. I decided to update the old speedometer in the VAZ 2121 battle tank. Having made an audit of the bins, I found 3 IN14 pieces. Not enough for a watch, much for a thermometer. Not there - not here. In the speedometer - that’s it.
    To begin with, the standard speedometer was removed and gutted. The current mileage is saved on a piece of paper, to be honest. A speed sensor of 10 pulses per revolution (DSA-3) was purchased. As indicators of speed - the aforementioned IN14, for displaying mileage, hours and other things - widely known in narrow circles of designers of AONs on the z80 - ALS318.

    Initially, the core of the device was PIC18F452 for the abundance of GPIO. Then I came across the i2c port expander mcp23017, which I had long wanted to get to. With him, the need for many GPIOs disappeared, and msp430g2452, which was close to me in the latest designs, was chosen. Also found RTC - i2c watch ds1307.
    IN14 requires 170 volts for normal operation. Step-up DC-DC was assembled according to a tested circuit on the MC34063 + IRF740. I will describe some of the nuances that appeared during the creation process.
    1. Round body. Not quite a convenient form for placement inside electronics and displays. I had to make the internal structure modular with several connectors. The task was also to make the case airtight (well, or almost airtight), since the waterline in connection with the operating conditions of the car is higher than the roof. This was decided by filling the excess holes with epoxy glue and installing a single connector for communication with the outside world. Actually design:

    and connector:

    2. Dynamic indication. In order not to notice the switching of discharges during a dynamic display, so infuriating to certain people, the refresh rate of each discharge should be at least 100 Hz. True, there are those who see 100 Hz, but I don’t ride them on this car. Of the two indicators, the most “difficult” from this point of view is the 9-bit ALS318. It turns out that the refresh rate should be at least 9 * 100 Hz. To simplify the calculation of intervals - a refresh rate of 1 kHz was chosen. Circuit ALS318 is connected to the mcp23017 port expander. Port A - segments, port B - bits. The 9th bit is controlled directly from the GPIO of the microcontroller. It turns out that once every millisecond it is necessary to update the state of ports A and B of the expander via i2c. The next nuance came out of here.
    3. Slow i2c exchange with ds1307. In our case, two slaves hang on the i2c bus. Port expander and clock. The latter do not keep up with the SCL frequency above 100 kHz, while the expander can work at frequencies up to 1.7 MHz. To update the expander ports, it is necessary to write 4 8-bit words in i2c every 1 ms (expander address, port A address, data for port A, data for port B). During initialization, the expander is programmed to auto-increment the addresses of internal registers when reading / writing. And the address of port B immediately follows the address of port A, which saves on the transfer of an additional address of port B. To ensure a short processing time of the update procedure, the SCL clock frequency of 500 kHz was chosen. Moreover, a survey of the state of the watch is carried out once in 100 cycles of updating the display, i.e. every 100ms. The clock polling procedure sets the SCL frequency to 100kHz acceptable for ds1307. When debugging the exchange over i2c, the SaleaeLogic USB logic analyzer (8 channels, up to 24 MHz sampling) greatly helped. Soft to it is able to decode various protocols, including i2c.

    4. Nutrition . The speedometer for storing time is constantly powered by the battery and for operation - the voltage supplied when the ignition is turned on. The last one is powered by a DC-DC converter and decoder for IN14, a port expander. In the absence of ignition voltage - the device is put into storage mode. If the ignition key is turned on, the indication starts, interruptions from the speed sensor are allowed. When the ignition is turned off, odometer readings are recorded in the non-volatile memory of the microcontroller.
    5. Management To set the clock, reset the odometers (there are two of them, except the main mileage counter), an encoder with a button was used (I honestly stole the picture on the network. My encoder is already filled with hot-melt adhesive for waterproofing):

    6. Logical levels of i2c slaves. Since the ds1307 clock is powered by 5V, and the microcontroller and port expander from 3.3V - the pull-up resistors of the i2c bus are connected to 3.3V. According to the datasheet for ds1307, the logical unit voltage is 2.2V, then 3.3V will be fully operational.
    7. WatchdogThe system uses a hardware i2c interface, while the processor "sleeps" while waiting for a byte to be sent / received. In the event of ignition failure / shutdown at this time, the microcontroller may not wait for the slave to respond and remain in "sleep" mode. To eliminate such hangs, the hardware watchdog of the microcontroller is used. In the main loop, watchdog is constantly reset. In the case of a hang-up, the main loop stops and the watchdog overflows, sending a reset to the microcontroller. To determine the nature of the reset (power on or watchdog), a variable is introduced into the program that is not initialized during the reset (#pragma NOINIT). If it is equal to the known value, there was a reset by watchdog.
    8. CalibrationIn principle, calibration can be done already in battle, for example, to travel at a certain speed in gps. Having typed, for example, 30 km / h - click on the cap, and the speedometer will remember the measured pulse frequency corresponding to 30 km / h. But on the back wall there was an interesting inscription:

    Thus, 10 pulses of the speed sensor will correspond to one meter traveled by the car. If there are significant differences in fact, I will make the necessary adjustments.
    9. Vibration resistance.The device is designed for operation in difficult from the point of view of vibration conditions. I did not find information on the IN14 vibration resistance on the Internet. Time, as they say, will tell. The electrical connections are made by the good old MGTF. After checking the modules - they were filled with epoxy glue. By the way, in fixprice I found quite a glue for myself in the form factor of double syringes.
    Here are the design elements:





    10. Miscellaneous. Existing mileage saved previously from the aforementioned pieces of paper in non-volatile memory. Speaking of her. Non-volatile memory is organized page by page in msp430. The first three are available for the user. The fourth stores the calibration data of the clock. The readings of the main mileage counter and two additional resettable odometers are saved sequentially, filling out the first three pages of flash in turn. Upon reaching the end of the third page - the first three pages are erased and recording starts again from the beginning of the first. Thus, the flash resource is increased, although the resource of the ignition switch (saving occurs when the ignition is turned off) is, of course, less than the resource of erasing the flash record.
    In the dashboard:

    In principle, everything. Waiting for comments and comments. Archive with the sources and the scheme in diptrace according to the tradition in the picture :
    Unfortunately, the updated habrastorage recognizes the archive in the picture and does not allow it to be saved, so here are the sources and the scheme:
    dl.dropboxusercontent.com/u/974924/nivaCon2.rar
    PS And yes, These IN14 lamps are indeed 44 years old.
    PPS Video on the go could not be removed. Not enough hands. Determination of speed checked by GPS. Deviations of ± 4 km / h at a speed of 40 km / h. Quite sufficient accuracy.

    Here's a video:

    I shot it like this:

    Also popular now: